diff options
| author | hathach <[email protected]> | 2013-09-26 01:14:27 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-09-26 01:14:27 +0700 |
| commit | f827750120d8d1f6558bd296a075718b970fb3db (patch) | |
| tree | 6536337fbd39a1b383dbaf82445fc8e2f3a2dd9f | |
| parent | 09724c5d11e14b162ccc1ab2dde4b64987b05817 (diff) | |
add cat command to cli
| -rw-r--r-- | demos/host/src/cli.c | 53 | ||||
| -rw-r--r-- | tinyusb/class/msc_host.c | 2 |
2 files changed, 53 insertions, 2 deletions
diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c index 186e018d9..8b128f001 100644 --- a/demos/host/src/cli.c +++ b/demos/host/src/cli.c @@ -49,6 +49,7 @@ ENTRY(help , cli_cmd_help , NULL) \ ENTRY(ls , cli_cmd_list , "list items in current directory") \ ENTRY(cd , cli_cmd_changedir, "change current directory") \ + ENTRY(cat , cli_cmd_cat , "display contents of a text file") \ //--------------------------------------------------------------------+ // Expands the function to have the standard function signature @@ -103,13 +104,17 @@ static cli_cmdfunc_t cli_command_tbl[] = //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ +#define CLI_MAX_BUFFER 256 +#define CLI_FILE_READ_BUFFER (4*1024) + enum { ASCII_BACKSPACE = 8, }; -#define CLI_MAX_BUFFER 256 static char cli_buffer[CLI_MAX_BUFFER]; +uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM; + //--------------------------------------------------------------------+ // IMPLEMENTATION @@ -243,4 +248,50 @@ tusb_error_t cli_cmd_changedir(const char * p_para) return TUSB_ERROR_NONE; } +//--------------------------------------------------------------------+ +// CAT Command +//--------------------------------------------------------------------+ +tusb_error_t cli_cmd_cat(const char *p_para) +{ + if ( (p_para == NULL) || (strlen(p_para) == 0) ) return TUSB_ERROR_INVALID_PARA; + + FIL file; + + switch( f_open(&file, p_para, FA_READ) ) + { + case FR_OK: + { + uint32_t bytes_read = 0; + if ( (FR_OK == f_read(&file, fileread_buffer, CLI_FILE_READ_BUFFER, &bytes_read)) && (bytes_read > 0) ) + { + if ( isprint( fileread_buffer[0] ) ) + { + putchar('\n'); + for(uint32_t i=0; i<bytes_read; i++) + { + putchar( fileread_buffer[i] ); + } + }else + { + printf("%s 's contents is not printable\n", p_para); + } + } + f_close(&file); + } + break; + + case FR_INVALID_NAME: + printf("%s : No such file or directory\n", p_para); + return TUSB_ERROR_INVALID_PARA; + break; + + default : + printf("failed to open %s\n", p_para); + return TUSB_ERROR_FAILED; + break; + } + + return TUSB_ERROR_NONE; +} + #endif diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c index b4fd5b127..673cfc9e0 100644 --- a/tinyusb/class/msc_host.c +++ b/tinyusb/class/msc_host.c @@ -312,7 +312,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con ); #endif - enum { SCSI_XFER_TIMEOUT = 1000 }; + enum { SCSI_XFER_TIMEOUT = 2000 }; //------------- SCSI Inquiry -------------// tusbh_msc_inquiry(dev_addr, 0, msch_buffer); osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error); |
