...
Note that future implementation could add members to this structure to support more parameters.
µC/
...
Shell Startup Code
We provide you with an example (i.e the application code) use of µC/Shell which is found in app.c
and it was written to provide a startup example on how to use the capabilities of the µC/Shell module. app.c
simply initializes µC/OS?II, µC/TCP-IP and µC/Shell, and creates a few tasks and other kernel objects that will give the user information about the state of the system. Note that you DO NOT need an RTOS like µC/OS?II or a TCP/IP stack like µC/TCP-IP to use µC/Shell.
Before you can use µC/Shell, the following has to be performed:1.
- Develop/create your command(s)
...
- Implement output functions (if needed)
...
- Initialize µC/Shell
This section of the manual will give you some examples of the above steps. Note that some sections of the source code have been removed or modified to help focus on the µC/Shell module use.
Listing 3-2 - Command
CPU_INT16S App_TestCmd (CPU_INT16U argc, (1)
CPU_CHAR *argv[],
SHELL_OUT_FNCT out_fnct,
SHELL_CMD_PARAM *pcmd_param)
{
CPU_INT16U cmd_namd_len;
CPU_INT16S output;
CPU_INT16S ret_val;
cmd_namd_len = Str_Len(argv[0]);
output = out_fnct(argv[0], (2)
cmd_namd_len,
pcmd_param->pout_opt
);
switch (output) {
case SHELL_OUT_RTN_CODE_CONN_CLOSED:
case SHELL_OUT_ERR:
ret_val = SHELL_EXEC_ERR;
break;
default:
ret_val = output;
}
return (ret_val); (3)
}
L3-2(1) Function implementing a test command.
L3-2(2) Use the output function to display the command name.
L3-2(3) The return value is command specific, with the exception of SHELL_EXEC_ERR
in case of an error.
Listing 3-3 - Initialization of module
static SHELL_CMD AppShellCmdTbl[] = (1)
{
{"App_test", App_TestCmd},
{0, 0 }
};
void App_InitShell (void)
{
CPU_BOOLEAN success;
SHELL_ERR err;
APP_TRACE_DEBUG(("Initialize Shell ... "));
success = Shell_Init(); (2)
if (success == DEF_OK) {
APP_TRACE_DEBUG(("done.\n\r"));
} else {
APP_TRACE_DEBUG(("failed.\n\r"));
return;
}
APP_TRACE_DEBUG(("Adding Shell command table ... "));
Shell_CmdTblAdd("App", App_ShellAppCmdTbl, &err); (3)
if (err == SHELL_ERR_NONE) {
APP_TRACE_DEBUG(("done.\n\r"));
} else {
APP_TRACE_DEBUG(("failed.\n\r"));
}
}
L3-3(1) Declare and populate a SHELL_CMD
structure table that will hold the ‘App
’ shell commands. The first member of this structure is the command name, and the other member a pointer to a function implementing the command itself.
This command table MUST have its last entry set to ‘0’.
L3-3(2) Initializes µC/Shell internal variables.
L3-3(3) Add the AppShellCmdTbl
module command table to the Shell.
...
µC/Shell Example Use
Listing 3-4 - Example use
...