shell.h File Reference


Detailed Description

AVR32 UC3 Control Panel Command Exec module.

This module provides a Command execution service.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file shell.h.

#include "compiler.h"
#include "FreeRTOS.h"
#include "supervisor.h"

Go to the source code of this file.

Defines

#define ABORT_CHAR   CTRL_C
#define BKSPACE_CHAR   '\b'
#define CR   '\r'
#define CRLF   "\r\n"
#define CTRL_C   0x03
#define CTRL_Q   0x11
#define ERROR_CRLF   "Error"CRLF
#define LF   '\n'
#define OK_CRLF   "OK"CRLF
#define QUIT_APPEND   CTRL_Q
#define SHELL_ERRMSG_CONFIGERROR   ERROR_CRLF"COULD NOT SET CONFIG"CRLF
#define SHELL_ERRMSG_MAINTENANCEMODE   ERROR_CRLF"Command unavailable in maintenance mode"CRLF
#define SHELL_ERRMSG_MEMALLOC   ERROR_CRLF"Memory allocation failed"CRLF
#define SHELL_ERRMSG_NOTIMPLEMENTED   "NOT IMPLEMENTED"CRLF
#define SHELL_MAX_MSGOUT_LEN   128
#define SHELL_MSG_CONFIG_SET   "config updated"CRLF
#define SHELL_MSG_REBOOT   "Reboot to take effect"CRLF

Typedefs

typedef eExecStatus(* pfShellCmd )(eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 Function pointer typedef that each command should abide to.

Enumerations

enum  eExecStatus { SHELL_EXECSTATUS_OK, SHELL_EXECSTATUS_OK_NO_FREE, SHELL_EXECSTATUS_KO }

Functions

eExecStatus Shell_exec (signed portCHAR *pcStringCmd, eModId xModId, signed short FsNavId, signed portCHAR **ppcStringReply)
 a command line executor.
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.


Define Documentation

#define ABORT_CHAR   CTRL_C

Definition at line 65 of file shell.h.

Referenced by prvGetCmdLine().

#define BKSPACE_CHAR   '\b'

Definition at line 64 of file shell.h.

Referenced by prvGetCmdLine().

#define CR   '\r'

Definition at line 61 of file shell.h.

Referenced by prv_append(), and prvGetCmdLine().

#define CRLF   "\r\n"

#define CTRL_C   0x03

Definition at line 63 of file shell.h.

#define CTRL_Q   0x11

Definition at line 67 of file shell.h.

#define ERROR_CRLF   "Error"CRLF

Definition at line 71 of file shell.h.

#define LF   '\n'

Definition at line 62 of file shell.h.

Referenced by prv_append(), and prvGetCmdLine().

#define OK_CRLF   "OK"CRLF

Definition at line 70 of file shell.h.

#define QUIT_APPEND   CTRL_Q

Definition at line 68 of file shell.h.

Referenced by prv_append().

#define SHELL_ERRMSG_CONFIGERROR   ERROR_CRLF"COULD NOT SET CONFIG"CRLF

#define SHELL_ERRMSG_MAINTENANCEMODE   ERROR_CRLF"Command unavailable in maintenance mode"CRLF

Definition at line 76 of file shell.h.

Referenced by e_sensor_cmd_set_config(), e_syscmds_cmd_set_config(), and Shell_exec().

#define SHELL_ERRMSG_MEMALLOC   ERROR_CRLF"Memory allocation failed"CRLF

#define SHELL_ERRMSG_NOTIMPLEMENTED   "NOT IMPLEMENTED"CRLF

Definition at line 73 of file shell.h.

#define SHELL_MAX_MSGOUT_LEN   128

The max length of a response line.

Definition at line 81 of file shell.h.

Referenced by e_fscmds_shell_disk(), e_fscmds_shell_pwd(), e_usbsys_lsusb(), prv_df(), and prv_ls().

#define SHELL_MSG_CONFIG_SET   "config updated"CRLF

Definition at line 78 of file shell.h.

Referenced by e_smtpclient_cmd_set_config().

#define SHELL_MSG_REBOOT   "Reboot to take effect"CRLF

Definition at line 77 of file shell.h.

Referenced by e_ethernet_cmd_set_config(), and e_webserver_cmd_set_config().


Typedef Documentation

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

Function pointer typedef that each command should abide to.

Parameters:
xModId Input. The module that is calling this function.
FsNavId Input. The file system navigator id to use if the cmd is a file system command.
ac Input. The argument counter.
av Input. The argument vector.
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed if the returned status is OK; the caller must then free this string.
Returns:
the status of the command execution.

Definition at line 109 of file shell.h.


Enumeration Type Documentation

The exec command return status.

Enumerator:
SHELL_EXECSTATUS_OK 
SHELL_EXECSTATUS_OK_NO_FREE 
SHELL_EXECSTATUS_KO 

Definition at line 86 of file shell.h.

00086              {
00087    SHELL_EXECSTATUS_OK,               // The command was successfully executed.
00088    SHELL_EXECSTATUS_OK_NO_FREE,       // The command was successfully executed, but the caller has not to free buffer.
00089    SHELL_EXECSTATUS_KO,               // The command execution failed.
00090 } eExecStatus;


Function Documentation

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

a command line executor.

Parameters:
pcStringCmd Input. The cmd line to execute. NULL-terminated string. Format: cmd [arg[=val]], 2 (arg,val) maximum. WARNING: this string will be modified.
xModId Input. The module that is calling this exe function.
FsNavId Input. The file system navigator id to use if the cmd is a file system command.
ppcStringReply Output. 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.
Parameters:
pcStringCmd Input. The cmd line to execute. NULL-terminated string. Format: cmd [arg] [arg=val], with 6 (arg,val) maximum. WARNING: this string will be modified.
xModId Input. The module that is calling this exe function.
FsNavId Input. The file system navigator id to use if the cmd is a file system command.
ppcStringReply Output. 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.

Definition at line 235 of file shell.c.

References st_cmd_registration::pf_exec_cmd, 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(), and prvweb_ParseCGIRequest().

00239 {
00240    eCmdStatus        xCmdStatus;
00241    portBASE_TYPE     ac;
00242    signed portCHAR   *av[SHELL_MAX_NBTOKEN];
00243    portBASE_TYPE     CmdIdx;
00244    int               i;
00245    eExecStatus       xRet;
00246 
00247 
00248    // 1) Identify the command and tokenize the rest of the command line.
00249    xCmdStatus = prvCmdIdentify_Tokenize( pcStringCmd, xModId, &ac, av, &CmdIdx );
00250    if(SHELL_CMDSTATUS_NOTFOUND == xCmdStatus)
00251    {   // Command not found.
00252       if(ppcStringReply != NULL)
00253       {
00254          *ppcStringReply = (signed portCHAR *)SHELL_MSG_CMDNOTFOUND;
00255       }
00256       return(SHELL_EXECSTATUS_KO);
00257    }
00258    else if(SHELL_CMDSTATUS_PERMISSIONDENIED == xCmdStatus)
00259    {   // Permission denied.
00260       if(ppcStringReply != NULL)
00261       {
00262          *ppcStringReply = (signed portCHAR *)SHELL_MSG_PERMISSIONDENIED;
00263       }
00264       return(SHELL_EXECSTATUS_KO);
00265    }
00266 
00267    /* Get the SHELLFS mutex for File system access. */
00268    // We put this check here to reduce the code footprint (normally it should be
00269    // in each fs cmd function).
00270    if( ( CmdIdx >= SHELL_FS_FIRSTCMDIDX ) && ( CmdIdx <= SHELL_FS_LASTCMDIDX ) )
00271    {
00272       if( pdFALSE == x_supervisor_SemaphoreTake( xSHELLFSMutex, 0 ) )
00273       {   // Failed to get the SHELLFS mutex.
00274          if(ppcStringReply != NULL)
00275          {
00276             *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MAINTENANCEMODE;
00277          }
00278          return(SHELL_EXECSTATUS_KO);
00279       }
00280    }
00281 
00282    /* Special case for the !! command. Only for the SYS_MODID_COM1SHELL module,
00283       cf. a_cmd_registration[]. */
00284    if( 0 == CmdIdx ) // !! command
00285    {
00286       CmdIdx = PrevCmdIdx; // Execute the previous cmd.
00287       if( -1 == CmdIdx )
00288       {   // No previous command.
00289          if(ppcStringReply != NULL)
00290          {
00291             *ppcStringReply = (signed portCHAR *)SHELL_MSG_NOHISTORY;
00292          }
00293          return(SHELL_EXECSTATUS_KO);
00294       }
00295       ac = PrevCmdAc;      // NOTE: we take a shortcut here: we suppose the caller
00296                            // keeps the same pcStringCmd from one call to another.
00297       for(i=0; i<ac; i++)   av[i] = PrevCmdAv[i];
00298    }
00299    else
00300    {
00301       PrevCmdIdx = CmdIdx; // Save the cmd (used by the !! cmd).
00302       PrevCmdAc = ac;
00303       for(i=0; i<ac; i++)   PrevCmdAv[i] = av[i];
00304    }
00305 
00306    // 2) Execute the command.
00307    if(ppcStringReply != NULL)
00308       *ppcStringReply = NULL;
00309    xRet = a_cmd_registration[CmdIdx].pf_exec_cmd( xModId, FsNavId, ac, av, ppcStringReply );
00310 
00311    /* Release the SHELLFS mutex. */
00312    if( ( CmdIdx >= SHELL_FS_FIRSTCMDIDX ) && ( CmdIdx <= SHELL_FS_LASTCMDIDX ) )
00313    {
00314       x_supervisor_SemaphoreGive( xSHELLFSMutex );
00315    }
00316 
00317    return( xRet );
00318 }

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:
xModId Input. The module associated with the target output stream.
pcStringToDisplay Input. The string to print.

Definition at line 506 of file shell.c.

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().

00508 {
00509    switch( xModId )
00510    {
00511       case SYS_MODID_COM1SHELL:
00512          vcom1shell_PrintMsg(pcStringToDisplay);
00513          break;
00514       case SYS_MODID_USB:
00515          TRACE_COM2((char *)"Unimplemented stream redirection (from fscmds to USB)");
00516          break;
00517       default: // SHOULD NEVER HAPPEN
00518          TRACE_COM2((char *) "Unexpected stream redirection");
00519          break;
00520    }
00521 }


Generated on Fri Feb 19 02:22:47 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5