Add cat command
This commit is contained in:
parent
d91463c458
commit
e7106b54c4
@ -329,6 +329,49 @@ static shellmatta_retCode_t shell_cmd_reset(const shellmatta_handle_t handle, co
|
||||
|
||||
return SHELLMATTA_BUSY;
|
||||
}
|
||||
|
||||
static shellmatta_retCode_t shell_cmd_cat(const shellmatta_handle_t handle, const char *arguments,
|
||||
uint32_t length)
|
||||
{
|
||||
FIL file;
|
||||
char path_buff[256];
|
||||
const char *path;
|
||||
UINT bytes_read;
|
||||
FRESULT res;
|
||||
|
||||
strncpy(path_buff, arguments, MIN(sizeof(path_buff), length));
|
||||
path_buff[MIN(length, sizeof(path_buff)-1)] = 0;
|
||||
path = strtok(path_buff, " ");
|
||||
path = strtok(NULL, " ");
|
||||
|
||||
if (strlen(path) == 0) {
|
||||
shellmatta_printf(handle, "Specify path!\r\n");
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
res = f_open(&file, path, FA_READ);
|
||||
if (res == FR_OK) {
|
||||
shellmatta_write(handle, "\r\n", 2U);
|
||||
do {
|
||||
res = f_read(&file, path_buff, sizeof(path_buff), &bytes_read);
|
||||
if (bytes_read > 0)
|
||||
shellmatta_write(handle, path_buff, bytes_read);
|
||||
else
|
||||
break;
|
||||
} while (res == FR_OK);
|
||||
|
||||
shellmatta_write(handle, "\r\n", 2U);
|
||||
}
|
||||
|
||||
if (res != FR_OK) {
|
||||
shellmatta_printf(handle, "Error reading file\r\n");
|
||||
}
|
||||
|
||||
f_close(&file);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
//typedef struct shellmatta_cmd
|
||||
//{
|
||||
// char *cmd; /**< command name */
|
||||
@ -339,7 +382,7 @@ static shellmatta_retCode_t shell_cmd_reset(const shellmatta_handle_t handle, co
|
||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||
//} shellmatta_cmd_t;
|
||||
|
||||
static shellmatta_cmd_t cmd[12] = {
|
||||
static shellmatta_cmd_t cmd[13] = {
|
||||
{
|
||||
.cmd = "version",
|
||||
.cmdAlias = "ver",
|
||||
@ -432,8 +475,16 @@ static shellmatta_cmd_t cmd[12] = {
|
||||
.cmd = "reset",
|
||||
.cmdAlias = NULL,
|
||||
.helpText = "Reset controller",
|
||||
.usageText = "Resets the controller",
|
||||
.usageText = "reset",
|
||||
.cmdFct = shell_cmd_reset,
|
||||
.next = &cmd[12],
|
||||
},
|
||||
{
|
||||
.cmd = "cat",
|
||||
.cmdAlias = NULL,
|
||||
.helpText = "Print file contents",
|
||||
.usageText = "cat <path>",
|
||||
.cmdFct = shell_cmd_cat,
|
||||
.next = NULL,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user