Comment the command line interpreter and lwIP sockets based server code.

pull/1/head
Richard Barry 14 years ago
parent 5ca1d4194d
commit 815bde09b9

@ -55,6 +55,12 @@
#include "task.h" #include "task.h"
#include "CommandInterpreter.h" #include "CommandInterpreter.h"
typedef struct xCOMMAND_INPUT_LIST
{
const xCommandLineInput *pxCommandLineDefinition;
struct xCOMMAND_INPUT_LIST *pxNext;
} xCommandLineInputListItem;
/* /*
* The callback function that is executed when "help" is entered. This is the * The callback function that is executed when "help" is entered. This is the
* only default command that is always present. * only default command that is always present.
@ -63,39 +69,77 @@ static const signed char *prvHelpCommand( void );
/* The definition of the "help" command. This command is always at the front /* The definition of the "help" command. This command is always at the front
of the list of registered commands. */ of the list of registered commands. */
const xCommandLineInput xHelpCommand = static const xCommandLineInput xHelpCommand =
{ {
"help", "help",
"help: Lists all the registered commands\r\n", "help: Lists all the registered commands\r\n",
prvHelpCommand, prvHelpCommand
NULL };
/* The definition of the list of commands. Commands that are registered are
added to this list. */
static xCommandLineInputListItem xRegisteredCommands =
{
&xHelpCommand, /* The first command in the list is always the help command, defined in this file. */
NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */
}; };
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vCmdIntRegisterCommand( const xCommandLineInput *pxCommandToRegister ) portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister )
{ {
/* Used to point to the last command in the list of registered command, just to static xCommandLineInputListItem *pxLastCommandInList = &xRegisteredCommands;
make registering commands faster. */ xCommandLineInputListItem *pxNewListItem;
static xCommandLineInput *pxLastCommandInList = &xHelpCommand; portBASE_TYPE xReturn = pdFAIL;
/* Check the parameter is not NULL. */
configASSERT( pxCommandToRegister );
/* Create a new list item that will reference the command being registered. */
pxNewListItem = ( xCommandLineInputListItem * ) pvPortMalloc( sizeof( xCommandLineInputListItem ) );
configASSERT( pxNewListItem );
if( pxNewListItem != NULL )
{
taskENTER_CRITICAL();
{
/* Reference the command being registered from the newly created
list item. */
pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
configASSERT( pxLastCommandInList ); /* The new list item will get added to the end of the list, so
pxLastCommandInList->pxNext = pxCommandToRegister; pxNext has nowhere to point. */
pxLastCommandInLIst = pxCommandToRegister; pxNewListItem->pxNext = NULL;
/* Add the newly created list item to the end of the already existing
list. */
pxLastCommandInList->pxNext = pxNewListItem;
/* Set the end of list marker to the new list item. */
pxLastCommandInList = pxNewListItem;
}
xReturn = pdPASS;
}
return xReturn;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
const signed char *pcCmdIntProcessCommand( const signed char *pcCommandInput ) const signed char *pcCmdIntProcessCommand( const signed char * const pcCommandInput )
{ {
static const xCommandLineInput *pxCommand = NULL; static const xCommandLineInputListItem *pxCommand = NULL;
signed const char *pcReturn = NULL; signed const char *pcReturn = NULL;
/* Note: This function is not re-entrant. It must not be called from more
thank one task. */
if( pxCommand == NULL ) if( pxCommand == NULL )
{ {
/* Search for the command string in the list of registered commands. */ /* Search for the command string in the list of registered commands. */
for( pxCommand = &xHelpCommand; pxCommand != NULL; pxCommand = pxCommand->pxNext ) for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )
{ {
if( strcmp( ( const char * ) pcCommandInput, ( const char * ) pxCommand->pcCommand ) == 0 ) if( strcmp( ( const char * ) pcCommandInput, ( const char * ) pxCommand->pxCommandLineDefinition->pcCommand ) == 0 )
{ {
/* The command has been found, the loop can exit so the command /* The command has been found, the loop can exit so the command
can be executed. */ can be executed. */
@ -106,7 +150,7 @@ signed const char *pcReturn = NULL;
if( pxCommand != NULL ) if( pxCommand != NULL )
{ {
pcReturn = pxCommand->pxCommandInterpreter(); pcReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter();
/* If no strings were returned, then all the strings that are going to /* If no strings were returned, then all the strings that are going to
be returned by the current command have already been returned, and be returned by the current command have already been returned, and
@ -119,8 +163,10 @@ signed const char *pcReturn = NULL;
} }
else else
{ {
pcReturn = "Command not recognised\r\n\r\n"; pcReturn = "Command not recognised. Available commands are listed below.\r\n\r\n";
pxCommand = &xHelpCommand;
/* Print out the help string. */
pxCommand = &xRegisteredCommands;
} }
return pcReturn; return pcReturn;
@ -129,7 +175,7 @@ signed const char *pcReturn = NULL;
static const signed char *prvHelpCommand( void ) static const signed char *prvHelpCommand( void )
{ {
static const xCommandLineInput * pxCommand = &xHelpCommand; static const xCommandLineInputListItem * pxCommand = &xRegisteredCommands;
signed const char *pcReturn; signed const char *pcReturn;
/* pxCommand will be NULL if all the commands in the list have already been /* pxCommand will be NULL if all the commands in the list have already been
@ -138,13 +184,13 @@ signed const char *pcReturn;
{ {
/* Return the next command help string, before moving the pointer on to /* Return the next command help string, before moving the pointer on to
the next command in the list. */ the next command in the list. */
pcReturn = pxCommand->pcHelpString; pcReturn = pxCommand->pxCommandLineDefinition->pcHelpString;
pxCommand = pxCommand->pxNext; pxCommand = pxCommand->pxNext;
} }
else else
{ {
/* Reset the pointer back to the start of the list. */ /* Reset the pointer back to the start of the list. */
pxCommand = &xHelpCommand; pxCommand = &xRegisteredCommands;
/* Return NULL to show that there are no more strings to return. */ /* Return NULL to show that there are no more strings to return. */
pcReturn = NULL; pcReturn = NULL;

@ -63,10 +63,9 @@ typedef const signed char * (*pdCOMMAND_LINE_CALLBACK)( void );
should be defined by declaring a const structure of this type. */ should be defined by declaring a const structure of this type. */
typedef struct xCOMMAND_LINE_INPUT typedef struct xCOMMAND_LINE_INPUT
{ {
const signed char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */ const signed char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */
const signed char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For exxample "help: Returns a list of all the commands\r\n". */ const signed char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For exxample "help: Returns a list of all the commands\r\n". */
pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */ const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */
const struct xCOMMAND_LINE_INPUT *pxNext; /* A pointer to the next xCommandLinInput structure. This should be NULL when the command is defined. It will get filled in automatically when the command is registered. */
} xCommandLineInput; } xCommandLineInput;
/* /*
@ -75,7 +74,7 @@ typedef struct xCOMMAND_LINE_INPUT
* handled by the command interpreter. Once a command has been registered it * handled by the command interpreter. Once a command has been registered it
* can be executed from the command line. * can be executed from the command line.
*/ */
void vCmdIntRegisterCommand( const xCommandLineInput *pxCommandToRegister ); portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister );
/* /*
* Runns the command interpreter for the command string "pcCommandInput". If * Runns the command interpreter for the command string "pcCommandInput". If
@ -89,7 +88,7 @@ void vCmdIntRegisterCommand( const xCommandLineInput *pxCommandToRegister );
* pcCmdIntProcessCommand is not reentrant. It must not be called from more * pcCmdIntProcessCommand is not reentrant. It must not be called from more
* than one task - or at least - by more than one task at a time. * than one task - or at least - by more than one task at a time.
*/ */
const signed char *pcCmdIntProcessCommand( const signed char *pcCommandInput ); const signed char *pcCmdIntProcessCommand( const signed char * const pcCommandInput );
#endif /* COMMAND_INTERPRETER_H */ #endif /* COMMAND_INTERPRETER_H */

Loading…
Cancel
Save