Atmel Software Framework

shell.c File Reference
#include <string.h>
#include "compiler.h"
#include "board.h"
#include "shell.h"
#include "sensor.h"
#include "actuator.h"
#include "fscmds.h"
#include "syscmds.h"
#include "supervisor.h"
#include "tracedump.h"
#include "ethernet.h"
#include "usbsys.h"
#include "com1shell.h"

Data Structures

struct  st_cmd_registration
 

Macros

#define SHELL_FS_FIRSTCMDIDX   9
 
#define SHELL_FS_LASTCMDIDX   29
 
#define SHELL_MAX_NBTOKEN   8
 
#define SHELL_NB_COMMANDS   35
 

Typedefs

typedef struct st_cmd_registration Cmd_registration
 

Enumerations

enum  eCmdStatus {
  SHELL_CMDSTATUS_FOUND,
  SHELL_CMDSTATUS_NOTFOUND,
  SHELL_CMDSTATUS_PERMISSIONDENIED
}
 

Functions

static eExecStatus e_Shell_help (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The help command: displays all available commands. Format: help. More...
 
eExecStatus e_supervisor_switch_to_maintenance_mode (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode. Format: maintain. More...
 
static eCmdStatus prvCmdIdentify_Tokenize (signed portCHAR *pcStringCmd, eModId xModId, portBASE_TYPE *ac, signed portCHAR **av, portBASE_TYPE *pCmdIdx)
 Identify the cmd and tokenize the rest of the command line string. More...
 
eExecStatus Shell_exec (signed portCHAR *pcStringCmd, eModId xModId, signed short FsNavId, signed portCHAR **ppcStringReply)
 a command line executor. More...
 
void v_shell_Print_String_To_Requester_Stream (eModId xModId, const signed portCHAR *pcStringToDisplay)
 Print a string directly to the output stream of a module. More...
 

Variables

Cmd_registration a_cmd_registration [SHELL_NB_COMMANDS]
 
static portBASE_TYPE PrevCmdAc
 
signed portCHAR * PrevCmdAv [SHELL_MAX_NBTOKEN]
 
static portBASE_TYPE PrevCmdIdx = -1
 
const signed portCHAR *const SHELL_ERRMSG_HELP_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: help [sensor,actuator,sys,fs]"CRLF
 
const signed portCHAR *const SHELL_MSG_CMDNOTFOUND = (signed portCHAR *)"Error"CRLF"Command not found"CRLF
 
const signed portCHAR *const SHELL_MSG_HELP = (signed portCHAR *)"Commands summary"CRLF"help"CRLF"!!: execute the previous command"CRLF
 
const signed portCHAR *const SHELL_MSG_NOHISTORY = (signed portCHAR *)"Error"CRLF"No previous command"CRLF
 
const signed portCHAR *const SHELL_MSG_PERMISSIONDENIED = (signed portCHAR *)"Error"CRLF"Permission denied"CRLF
 
const signed portCHAR *const SHELL_MSG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Syntax error"CRLF
 
xSemaphoreHandle xSHELLFSMutex
 

#define SHELL_FS_FIRSTCMDIDX   9

First file system cmd idx in the a_cmd_registration[] array.

Referenced by Shell_exec().

#define SHELL_FS_LASTCMDIDX   29

Last file system cmd idx in the a_cmd_registration[] array.

Referenced by Shell_exec().

#define SHELL_MAX_NBTOKEN   8

Brief description of the module. This module is a central point for commands execution.

Detailed description of the module. It proposes only one interface function, Shell_exec(). This function parses a command line string to: 1) identify the command 2) verify that the caller has the right to execute the command 3) tokenize all arguments of the command If the command has been found, and the caller has the right to execute it, the command is executed. The command execution is managed by the target module. Target modules are: sensor, actuator, filesys, supervisor.

The input command line string must have the following format: cmd [arg[=val]], 5 (arg,val) maximum.

Max number of tokens

Referenced by prvCmdIdentify_Tokenize(), and Shell_exec().

#define SHELL_NB_COMMANDS   35

Number of registered commands.

Referenced by prvCmdIdentify_Tokenize().

The type of a command registration entry.

enum eCmdStatus

The cmd status enum.

Enumerator
SHELL_CMDSTATUS_FOUND 
SHELL_CMDSTATUS_NOTFOUND 
SHELL_CMDSTATUS_PERMISSIONDENIED 

static eExecStatus e_Shell_help ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)
static

The help command: displays all available commands. Format: help.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this exe function.
FsNavIdInput. The file system navigator id to use if the cmd is a file system command. NOT USED.
acInput. The argument counter. Not considered for this command.
avInput. The argument vector. Not considered for this command.
ppcStringReplyInput/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns
the status of the command execution.

References e_actuator_help(), e_fscmds_shell_help(), e_sensor_help(), e_syscmds_help(), NULL, pvPortMalloc(), SHELL_EXECSTATUS_KO, and SHELL_EXECSTATUS_OK.

eExecStatus e_supervisor_switch_to_maintenance_mode ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

The switch-to-maintenance-mode command: initiate the process to
switch to maintenance mode. Format: maintain.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acIgnored.
avIgnored.
ppcStringReplyInput/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns
the status of the command execution.
static eCmdStatus prvCmdIdentify_Tokenize ( signed portCHAR *  pcStringCmd,
eModId  xModId,
portBASE_TYPE *  ac,
signed portCHAR **  av,
portBASE_TYPE *  pCmdIdx 
)
static

Identify the cmd and tokenize the rest of the command line string.

Parameters
pcStringCmdInput. The cmd line to parse. NULL-terminated string. Format: cmd [arg] [arg=val], with 6 (arg,val) maximum. WARNING: this string will be modified.
xModIdInput. The module that is requesting the exe of this cmd line.
acOutput. Argument count, in [0,SHELL_MAX_NBTOKEN].
avOutput. Argument vector, made of SHELL_MAX_NBTOKEN string ptrs maximum.
pCmdIdxOutput. The index of the command, in one of the cmd array.
Returns
the command status(eCmdStatus), indicating the Identify & Tokenize status.

Parse one arg.

References SHELL_CMDSTATUS_FOUND, SHELL_CMDSTATUS_NOTFOUND, SHELL_CMDSTATUS_PERMISSIONDENIED, SHELL_MAX_NBTOKEN, and SHELL_NB_COMMANDS.

Referenced by Shell_exec().

eExecStatus Shell_exec ( signed portCHAR *  pcStringCmd,
eModId  xModId,
signed short  FsNavId,
signed portCHAR **  ppcStringReply 
)

a command line executor.

Parameters
pcStringCmdInput. The cmd line to execute. NULL-terminated string. Format: cmd [arg] [arg=val], with 6 (arg,val) maximum. WARNING: this string will be modified.
xModIdInput. The module that is calling this exe function.
FsNavIdInput. The file system navigator id to use if the cmd is a file system command.
ppcStringReplyOutput. The caller must free this string (by calling vportFree()) only if it is non-NULL and the returned status is OK.
Returns
the status of the command execution.

References i, NULL, pdFALSE, st_cmd_registration::pf_exec_cmd, PrevCmdAc, PrevCmdIdx, prvCmdIdentify_Tokenize(), SHELL_CMDSTATUS_NOTFOUND, SHELL_CMDSTATUS_PERMISSIONDENIED, SHELL_ERRMSG_MAINTENANCEMODE, SHELL_EXECSTATUS_KO, SHELL_FS_FIRSTCMDIDX, SHELL_FS_LASTCMDIDX, SHELL_MAX_NBTOKEN, x_supervisor_SemaphoreGive(), and x_supervisor_SemaphoreTake().

Referenced by portTASK_FUNCTION().

void v_shell_Print_String_To_Requester_Stream ( eModId  xModId,
const signed portCHAR *  pcStringToDisplay 
)

Print a string directly to the output stream of a module.

Parameters
xModIdInput. The module associated with the target output stream.
pcStringToDisplayInput. The string to print.

References SYS_MODID_COM1SHELL, SYS_MODID_USB, TRACE_COM2, and vcom1shell_PrintMsg().

Referenced by e_fscmds_shell_fat(), e_fscmds_shell_pwd(), e_usbsys_lsusb(), prv_append(), prv_cat(), prv_df(), prv_e_usbsys_sync_cp_ukey(), and prv_ls().

Cmd_registration a_cmd_registration[SHELL_NB_COMMANDS]

The array of commands registration.

portBASE_TYPE PrevCmdAc
static

Referenced by Shell_exec().

signed portCHAR* PrevCmdAv[SHELL_MAX_NBTOKEN]
portBASE_TYPE PrevCmdIdx = -1
static

Previous cmd index.

Referenced by Shell_exec().

const signed portCHAR* const SHELL_ERRMSG_HELP_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: help [sensor,actuator,sys,fs]"CRLF

Error msg upon help syntax error.

const signed portCHAR* const SHELL_MSG_CMDNOTFOUND = (signed portCHAR *)"Error"CRLF"Command not found"CRLF

String messages.

Error msg upon command not found.

const signed portCHAR* const SHELL_MSG_HELP = (signed portCHAR *)"Commands summary"CRLF"help"CRLF"!!: execute the previous command"CRLF
const signed portCHAR* const SHELL_MSG_NOHISTORY = (signed portCHAR *)"Error"CRLF"No previous command"CRLF

Error msg if !! is executed and there is no previous command.

const signed portCHAR* const SHELL_MSG_PERMISSIONDENIED = (signed portCHAR *)"Error"CRLF"Permission denied"CRLF

Error msg upon command execution permission denied.

const signed portCHAR* const SHELL_MSG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Syntax error"CRLF

Error msg upon syntax error.

xSemaphoreHandle xSHELLFSMutex

The SHELLFS system mutex.

The SHELL system mutex.