add cat command to cli
This commit is contained in:
parent
09724c5d11
commit
f827750120
|
@ -49,6 +49,7 @@
|
||||||
ENTRY(help , cli_cmd_help , NULL) \
|
ENTRY(help , cli_cmd_help , NULL) \
|
||||||
ENTRY(ls , cli_cmd_list , "list items in current directory") \
|
ENTRY(ls , cli_cmd_list , "list items in current directory") \
|
||||||
ENTRY(cd , cli_cmd_changedir, "change 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
|
// Expands the function to have the standard function signature
|
||||||
|
@ -103,13 +104,17 @@ static cli_cmdfunc_t cli_command_tbl[] =
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
#define CLI_MAX_BUFFER 256
|
||||||
|
#define CLI_FILE_READ_BUFFER (4*1024)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ASCII_BACKSPACE = 8,
|
ASCII_BACKSPACE = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CLI_MAX_BUFFER 256
|
|
||||||
static char cli_buffer[CLI_MAX_BUFFER];
|
static char cli_buffer[CLI_MAX_BUFFER];
|
||||||
|
|
||||||
|
uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM;
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
|
@ -243,4 +248,50 @@ tusb_error_t cli_cmd_changedir(const char * p_para)
|
||||||
return TUSB_ERROR_NONE;
|
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
|
#endif
|
||||||
|
|
|
@ -312,7 +312,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum { SCSI_XFER_TIMEOUT = 1000 };
|
enum { SCSI_XFER_TIMEOUT = 2000 };
|
||||||
//------------- SCSI Inquiry -------------//
|
//------------- SCSI Inquiry -------------//
|
||||||
tusbh_msc_inquiry(dev_addr, 0, msch_buffer);
|
tusbh_msc_inquiry(dev_addr, 0, msch_buffer);
|
||||||
osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error);
|
osal_semaphore_wait(msch_sem_hdl, SCSI_XFER_TIMEOUT, &error);
|
||||||
|
|
Loading…
Reference in New Issue