mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 13:31:58 -04:00
Change command interpreter semantics.
This commit is contained in:
parent
59fbe1da22
commit
49f726cf25
|
@ -71,7 +71,7 @@ typedef struct xCOMMAND_INPUT_LIST
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
static const signed char *prvHelpCommand( void );
|
static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen );
|
||||||
|
|
||||||
/* 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. */
|
||||||
|
@ -132,10 +132,10 @@ portBASE_TYPE xReturn = pdFAIL;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
const signed char *pcCmdIntProcessCommand( const signed char * const pcCommandInput )
|
portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen )
|
||||||
{
|
{
|
||||||
static const xCommandLineInputListItem *pxCommand = NULL;
|
static const xCommandLineInputListItem *pxCommand = NULL;
|
||||||
signed const char *pcReturn = NULL;
|
portBASE_TYPE xReturn;
|
||||||
|
|
||||||
/* Note: This function is not re-entrant. It must not be called from more
|
/* Note: This function is not re-entrant. It must not be called from more
|
||||||
thank one task. */
|
thank one task. */
|
||||||
|
@ -156,52 +156,53 @@ signed const char *pcReturn = NULL;
|
||||||
|
|
||||||
if( pxCommand != NULL )
|
if( pxCommand != NULL )
|
||||||
{
|
{
|
||||||
pcReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter();
|
/* Call the callback function that is registered to this command. */
|
||||||
|
xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen );
|
||||||
|
|
||||||
/* If no strings were returned, then all the strings that are going to
|
/* If xReturn is pdFALSE, then no further strings will be returned
|
||||||
be returned by the current command have already been returned, and
|
after this one, and pxCommand can be reset to NULL ready to search
|
||||||
pxCommand can be reset to NULL ready to search for the next entered
|
for the next entered command. */
|
||||||
command. */
|
if( xReturn == pdFALSE )
|
||||||
if( pcReturn == NULL )
|
|
||||||
{
|
{
|
||||||
pxCommand = NULL;
|
pxCommand = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pcReturn = ( const signed char * const ) "Command not recognised. Available commands are listed below.\r\n\r\n";
|
strncpy( ( char * ) pcWriteBuffer, ( const char * const ) "Command not recognised. Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
|
||||||
|
xReturn = pdFALSE;
|
||||||
/* Print out the help string. */
|
|
||||||
pxCommand = &xRegisteredCommands;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pcReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static const signed char *prvHelpCommand( void )
|
static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen )
|
||||||
{
|
{
|
||||||
static const xCommandLineInputListItem * pxCommand = &xRegisteredCommands;
|
static const xCommandLineInputListItem * pxCommand = NULL;
|
||||||
signed const char *pcReturn;
|
signed portBASE_TYPE xReturn;
|
||||||
|
|
||||||
/* pxCommand will be NULL if all the commands in the list have already been
|
if( pxCommand == NULL )
|
||||||
returned. */
|
|
||||||
if( pxCommand != NULL )
|
|
||||||
{
|
{
|
||||||
/* Return the next command help string, before moving the pointer on to
|
/* Reset the pxCommand pointer back to the start of the list. */
|
||||||
the next command in the list. */
|
pxCommand = &xRegisteredCommands;
|
||||||
pcReturn = pxCommand->pxCommandLineDefinition->pcHelpString;
|
}
|
||||||
pxCommand = pxCommand->pxNext;
|
|
||||||
|
/* Return the next command help string, before moving the pointer on to
|
||||||
|
the next command in the list. */
|
||||||
|
strncpy( ( char * ) pcWriteBuffer, ( const char * ) pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );
|
||||||
|
pxCommand = pxCommand->pxNext;
|
||||||
|
|
||||||
|
if( pxCommand == NULL )
|
||||||
|
{
|
||||||
|
/* There are no more commands in the list, so there will be no more
|
||||||
|
strings to return after this one and pdFALSE should be returned. */
|
||||||
|
xReturn = pdFALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Reset the pointer back to the start of the list. */
|
xReturn = pdTRUE;
|
||||||
pxCommand = &xRegisteredCommands;
|
|
||||||
|
|
||||||
/* Return NULL to show that there are no more strings to return. */
|
|
||||||
pcReturn = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pcReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,15 +56,17 @@
|
||||||
|
|
||||||
/* The prototype to which callback functions used to process command line
|
/* The prototype to which callback functions used to process command line
|
||||||
commands must comply. This type will change when commands with parameters
|
commands must comply. This type will change when commands with parameters
|
||||||
are included. */
|
are included. pcWriteBuffer is a buffer into which the output from executing
|
||||||
typedef const signed char * (*pdCOMMAND_LINE_CALLBACK)( void );
|
the command can be written, xWriteBufferLen is the length, in bytes, of the
|
||||||
|
pcWriteBuffer buffer. */
|
||||||
|
typedef portBASE_TYPE (*pdCOMMAND_LINE_CALLBACK)( signed char *pcWriteBuffer, size_t xWriteBufferLen );
|
||||||
|
|
||||||
/* The structure that defines command line commands. A command line command
|
/* The structure that defines command line commands. A command line command
|
||||||
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 example "help: Returns a list of all the commands\r\n". */
|
||||||
const 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. */
|
||||||
} xCommandLineInput;
|
} xCommandLineInput;
|
||||||
|
|
||||||
|
@ -77,18 +79,17 @@ typedef struct xCOMMAND_LINE_INPUT
|
||||||
portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister );
|
portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runns the command interpreter for the command string "pcCommandInput". If
|
* Runs the command interpreter for the command string "pcCommandInput". Any
|
||||||
* pcCommandInput is valid (the command has been registered) a string will be
|
* output generated by running the command will be placed into pcWriteBuffer.
|
||||||
* returned, and pcCmdIntProcessCommand must then be called repeatedly until
|
* xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to
|
||||||
* NULL is returned. If pcCommand pcCommandInput is not valid (the command is
|
* by pcWriteBuffer.
|
||||||
* not recognised as a registered command) then an error message will be
|
*
|
||||||
* returned - and again pcCmdIntProcessCommand() must be called repeatedly
|
* xCmdIntProcessCommand should be called repeatedly until it returns pdFALSE.
|
||||||
* until NULL is returned.
|
|
||||||
*
|
*
|
||||||
* 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 * const pcCommandInput );
|
portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen );
|
||||||
|
|
||||||
#endif /* COMMAND_INTERPRETER_H */
|
#endif /* COMMAND_INTERPRETER_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue