Merge branch 'dev' into ui

This commit is contained in:
Mario Hüttel 2020-04-27 21:53:27 +02:00
commit fe51c80248

View File

@ -330,6 +330,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 */
@ -340,7 +383,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",
@ -433,8 +476,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,
}