/* Utils includes. */\r
#include "CommandInterpreter.h"\r
\r
+/* Dimensions the buffer into which input characters are placed. */\r
#define cmdMAX_INPUT_SIZE 20\r
\r
+/* Dimensions the buffer into which string outputs can be placed. */\r
+#define cmdMAX_OUTPUT_SIZE 1024\r
+\r
/*-----------------------------------------------------------*/\r
\r
void vBasicSocketsCommandInterpreterTask( void *pvParameters )\r
struct sockaddr_in sLocalAddr;\r
struct sockaddr_in client_addr;\r
const signed char *pcWelcomeMessage = "FreeRTOS command server - connection accepted.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
-const signed char *pcString;\r
signed char cInChar, cInputIndex;\r
-signed char cInputString[ cmdMAX_INPUT_SIZE ];\r
+static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ];\r
+portBASE_TYPE xReturned;\r
\r
( void ) pvParameters;\r
\r
{\r
/* The input string was not a quit command. \r
Pass the string to the command interpreter. */\r
- while( ( pcString = pcCmdIntProcessCommand( cInputString ) ) != NULL )\r
+ do\r
{\r
- /* A string has been generated by the \r
- command interpreter. Send it. */\r
- lwip_send( lClientFd, pcString, strlen( ( const char * ) pcString ), 0 );\r
- }\r
+ xReturned = xCmdIntProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE );\r
+ lwip_send( lClientFd, cOutputString, strlen( ( const char * ) cOutputString ), 0 );\r
+\r
+ } while( xReturned != pdFALSE );\r
\r
/* All the strings generated by the input \r
command have been sent. Clear the input\r
extern void lwIPAppsInit( void *pvArguments );\r
\r
/* Callbacks to handle the command line commands defined by the xTaskStats and\r
-xRunTimeStats command definitions respectively. These functions are not\r
-reentrant! They must be used from one task only - or at least by only one task\r
-at a time. */\r
-static const signed char *prvTaskStatsCommand( void );\r
-static const signed char *prvRunTimeStatsCommand( void );\r
+xRunTimeStats command definitions respectively. These functions are not \r
+necessarily reentrant! They must be used from one task only - or at least by \r
+only one task at a time. */\r
+static portBASE_TYPE prvTaskStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen );\r
+static portBASE_TYPE prvRunTimeStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen );\r
\r
/* The string that latches the current demo status. */\r
static char *pcStatusMessage = "All tasks running without error";\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static const signed char *prvTaskStatsCommand( void )\r
+static portBASE_TYPE prvTaskStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen )\r
{\r
-static signed char *pcReturn = NULL;\r
const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";\r
\r
- /* This is the callback function that is executed when the command line\r
- command defined by the xTaskStats structure is entered. This function\r
- is called repeatedly until it returns NULL. It is therefore not re-entrant\r
- and must not be called from more than one task - or at least - not from\r
- more than one task at the same time. */\r
- if( pcReturn == NULL )\r
- {\r
- /* Generate a table of task state. */\r
- pcReturn = pcLwipAppsBlockingGetTxBuffer();\r
- if( pcReturn != NULL )\r
- {\r
- strcpy( pcReturn, pcHeader );\r
- vTaskList( pcReturn + strlen( pcHeader ) );\r
- }\r
- }\r
- else\r
- {\r
- /* This command only returns one string, so the second time it is\r
- called it just resets itself and returns NULL to say no more strings\r
- are going to be generated. */\r
- pcReturn = NULL;\r
- vLwipAppsReleaseTxBuffer();\r
- }\r
+ configASSERT( pcWriteBuffer );\r
+\r
+ /* This function assumes the buffer length is adequate. */\r
+ ( void ) xWriteBufferLen;\r
+\r
+ /* Generate a table of task stats. */\r
+ strcpy( pcWriteBuffer, pcHeader );\r
+ vTaskList( pcWriteBuffer + strlen( pcHeader ) );\r
\r
- return pcReturn;\r
+ /* There is no more data to return after this single string, so return \r
+ pdFALSE. */\r
+ return pdFALSE;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static const signed char *prvRunTimeStatsCommand( void )\r
+static portBASE_TYPE prvRunTimeStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen )\r
{\r
-static signed char *pcReturn = NULL;\r
const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";\r
\r
- /* This is the callback function that is executed when the command line\r
- command defined by the xRunTimeStats structure is entered. This function\r
- is called repeatedly until it returns NULL. It is therefore not re-entrant\r
- and must not be called from more than one task - or at least - not from\r
- more than one task at the same time. */\r
+ configASSERT( pcWriteBuffer );\r
\r
- if( pcReturn == NULL )\r
- {\r
- /* Generate a table of run time stats. */\r
- pcReturn = pcLwipAppsBlockingGetTxBuffer();\r
- if( pcReturn != NULL )\r
- {\r
- strcpy( pcReturn, pcHeader );\r
- vTaskGetRunTimeStats( pcReturn + strlen( pcHeader ) );\r
- }\r
- }\r
- else\r
- {\r
- /* This command only returns one string, so the second time it is\r
- called it just resets itself and returns NULL to say no more strings\r
- are going to be generated. */\r
- pcReturn = NULL;\r
- vLwipAppsReleaseTxBuffer();\r
- }\r
+ /* This function assumes the buffer length is adequate. */\r
+ ( void ) xWriteBufferLen;\r
+\r
+ /* Generate a table of task stats. */\r
+ strcpy( pcWriteBuffer, pcHeader );\r
+ vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );\r
\r
- return pcReturn;\r
+ /* There is no more data to return after this single string, so return \r
+ pdFALSE. */\r
+ return pdFALSE;\r
}\r
\r
\r