* The callback function that is executed when "help" is entered. This is the\r
* only default command that is always present.\r
*/\r
-static const signed char *prvHelpCommand( void );\r
+static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen );\r
\r
/* The definition of the "help" command. This command is always at the front\r
of the list of registered commands. */\r
}\r
/*-----------------------------------------------------------*/\r
\r
-const signed char *pcCmdIntProcessCommand( const signed char * const pcCommandInput )\r
+portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen )\r
{\r
static const xCommandLineInputListItem *pxCommand = NULL;\r
-signed const char *pcReturn = NULL;\r
+portBASE_TYPE xReturn;\r
\r
/* Note: This function is not re-entrant. It must not be called from more\r
thank one task. */\r
\r
if( pxCommand != NULL )\r
{\r
- pcReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter();\r
+ /* Call the callback function that is registered to this command. */\r
+ xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen );\r
\r
- /* If no strings were returned, then all the strings that are going to\r
- be returned by the current command have already been returned, and\r
- pxCommand can be reset to NULL ready to search for the next entered\r
- command. */\r
- if( pcReturn == NULL )\r
+ /* If xReturn is pdFALSE, then no further strings will be returned\r
+ after this one, and pxCommand can be reset to NULL ready to search \r
+ for the next entered command. */\r
+ if( xReturn == pdFALSE )\r
{\r
pxCommand = NULL;\r
}\r
}\r
else\r
{\r
- pcReturn = ( const signed char * const ) "Command not recognised. Available commands are listed below.\r\n\r\n";\r
-\r
- /* Print out the help string. */\r
- pxCommand = &xRegisteredCommands;\r
+ strncpy( ( char * ) pcWriteBuffer, ( const char * const ) "Command not recognised. Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );\r
+ xReturn = pdFALSE;\r
}\r
\r
- return pcReturn;\r
+ return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static const signed char *prvHelpCommand( void )\r
+static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen )\r
{\r
-static const xCommandLineInputListItem * pxCommand = &xRegisteredCommands;\r
-signed const char *pcReturn;\r
+static const xCommandLineInputListItem * pxCommand = NULL;\r
+signed portBASE_TYPE xReturn;\r
\r
- /* pxCommand will be NULL if all the commands in the list have already been\r
- returned. */\r
- if( pxCommand != NULL )\r
+ if( pxCommand == NULL )\r
{\r
- /* Return the next command help string, before moving the pointer on to\r
- the next command in the list. */\r
- pcReturn = pxCommand->pxCommandLineDefinition->pcHelpString;\r
- pxCommand = pxCommand->pxNext;\r
+ /* Reset the pxCommand pointer back to the start of the list. */\r
+ pxCommand = &xRegisteredCommands;\r
+ }\r
+\r
+ /* Return the next command help string, before moving the pointer on to\r
+ the next command in the list. */\r
+ strncpy( ( char * ) pcWriteBuffer, ( const char * ) pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );\r
+ pxCommand = pxCommand->pxNext;\r
+\r
+ if( pxCommand == NULL )\r
+ {\r
+ /* There are no more commands in the list, so there will be no more\r
+ strings to return after this one and pdFALSE should be returned. */\r
+ xReturn = pdFALSE;\r
}\r
else\r
{\r
- /* Reset the pointer back to the start of the list. */\r
- pxCommand = &xRegisteredCommands;\r
-\r
- /* Return NULL to show that there are no more strings to return. */\r
- pcReturn = NULL;\r
+ xReturn = pdTRUE;\r
}\r
- \r
- return pcReturn;\r
-}\r
\r
+ return xReturn;\r
+}\r
\r
/* The prototype to which callback functions used to process command line\r
commands must comply. This type will change when commands with parameters \r
-are included. */\r
-typedef const signed char * (*pdCOMMAND_LINE_CALLBACK)( void );\r
+are included. pcWriteBuffer is a buffer into which the output from executing\r
+the command can be written, xWriteBufferLen is the length, in bytes, of the\r
+pcWriteBuffer buffer. */\r
+typedef portBASE_TYPE (*pdCOMMAND_LINE_CALLBACK)( signed char *pcWriteBuffer, size_t xWriteBufferLen );\r
\r
/* The structure that defines command line commands. A command line command\r
should be defined by declaring a const structure of this type. */\r
typedef struct xCOMMAND_LINE_INPUT\r
{\r
const signed char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */\r
- 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". */\r
+ 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". */\r
const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */\r
} xCommandLineInput;\r
\r
portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister );\r
\r
/*\r
- * Runns the command interpreter for the command string "pcCommandInput". If\r
- * pcCommandInput is valid (the command has been registered) a string will be \r
- * returned, and pcCmdIntProcessCommand must then be called repeatedly until \r
- * NULL is returned. If pcCommand pcCommandInput is not valid (the command is\r
- * not recognised as a registered command) then an error message will be\r
- * returned - and again pcCmdIntProcessCommand() must be called repeatedly\r
- * until NULL is returned.\r
+ * Runs the command interpreter for the command string "pcCommandInput". Any\r
+ * output generated by running the command will be placed into pcWriteBuffer.\r
+ * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to\r
+ * by pcWriteBuffer.\r
+ *\r
+ * xCmdIntProcessCommand should be called repeatedly until it returns pdFALSE.\r
*\r
* pcCmdIntProcessCommand is not reentrant. It must not be called from more\r
* than one task - or at least - by more than one task at a time.\r
*/\r
-const signed char *pcCmdIntProcessCommand( const signed char * const pcCommandInput );\r
+portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen );\r
\r
#endif /* COMMAND_INTERPRETER_H */\r
\r