...
µC/Shell with the µC/FS shell commands is initialized in in "Initializing µC/Shell". The file system initialization (FS_Init()
) function should have previously been called.
Code Block | ||||
---|---|---|---|---|
| ||||
CPU_BOOLEAN App_ShellInit (void)
{
CPU_BOOLEAN ok;
ok = Shell_Init();
if (ok == DEF_FAIL) {
return (DEF_FAIL);
}
ok = FSShell_Init();
if (ok == DEF_FAIL) {
return (DEF_FAIL;
}
return (DEF_OK);
} |
It’s assumed that the application will create a task to receive input from a terminal; this task should be written as shown in "Executing shell commands & handling shell output".
Code Block | ||||
---|---|---|---|---|
| ||||
void App_ShellTask (void *p_arg)
{
CPU_CHAR cmd_line[MAX_CMD_LEN];
SHELL_ERR err;
SHELL_CMD_PARAM cmd_param;
CPU_CHAR cwd_path[FS_CFG_FULL_ NAME_LEN + 1u];
(1)
Str_Copy(&cwd_path[0], (CPU_CHAR *)"\\");
cmd_param.pcur_working_dir = (void *)cwd_path[0];
cmd_param.pout_opt = (void *)0;
while (DEF_TRUE) {
App_ShellIn(cmd_line, MAX_CMD_LEN); (2)
(3)
Shell_Exec(cmd_line, App_ShellOut, &cmd_param, &err);
switch (err) {
case SHELL_ERR_CMD_NOT_FOUND:
case SHELL_ERR_CMD_SEARCH:
case SHELL_ERR_ARG_TBL_FULL:
App_ShellOut("Command not found\r\n", 19, cmd_param.pout_opt);
break;
default:
break;
}
}
}
/*
**************************************************************************************
* App_ShellIn()
**************************************************************************************
*/
CPU_INT16S App_ShellIn (CPU_CHAR *pbuf,
CPU_INT16U buf_len)
{
/* $$$$ Store line from terminal/command line into 'pbuf'; return length of line. */
}
/*
**************************************************************************************
* App_ShellOut()
**************************************************************************************
*/
CPU_INT16S App_ShellOut (CPU_CHAR *pbuf,
CPU_INT16U buf_len,
void *popt)
{
/* $$$$ Output 'pbuf' data on terminal/command line; return nbr bytes tx'd. */
} |
Panel | ||
---|---|---|
| ||
(1) The (2) The next command, ending with a newline, should be read from the command line. (3) The received command should be executed with |