From: richardbarry Date: Wed, 3 Aug 2011 09:36:12 +0000 (+0000) Subject: Change command interpreter semantics. X-Git-Tag: V7.0.2~74 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f42a1c08f597bd176865b4f0514383aedcbabbf0;p=freertos Change command interpreter semantics. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1536 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/Demo/WIN32-MSVC-lwIP/WIN32.suo b/Demo/WIN32-MSVC-lwIP/WIN32.suo index 86113f538..a43142fa4 100644 Binary files a/Demo/WIN32-MSVC-lwIP/WIN32.suo and b/Demo/WIN32-MSVC-lwIP/WIN32.suo differ diff --git a/Demo/WIN32-MSVC-lwIP/lwIP_Apps/apps/BasicSocketCommandServer/BasicSocketCommandServer.c b/Demo/WIN32-MSVC-lwIP/lwIP_Apps/apps/BasicSocketCommandServer/BasicSocketCommandServer.c index 733a188b4..6fd3cc114 100644 --- a/Demo/WIN32-MSVC-lwIP/lwIP_Apps/apps/BasicSocketCommandServer/BasicSocketCommandServer.c +++ b/Demo/WIN32-MSVC-lwIP/lwIP_Apps/apps/BasicSocketCommandServer/BasicSocketCommandServer.c @@ -65,8 +65,12 @@ /* Utils includes. */ #include "CommandInterpreter.h" +/* Dimensions the buffer into which input characters are placed. */ #define cmdMAX_INPUT_SIZE 20 +/* Dimensions the buffer into which string outputs can be placed. */ +#define cmdMAX_OUTPUT_SIZE 1024 + /*-----------------------------------------------------------*/ void vBasicSocketsCommandInterpreterTask( void *pvParameters ) @@ -75,9 +79,9 @@ long lSocket, lClientFd, lBytes, lAddrLen = sizeof( struct sockaddr_in ); struct sockaddr_in sLocalAddr; struct sockaddr_in client_addr; const signed char *pcWelcomeMessage = "FreeRTOS command server - connection accepted.\r\nType Help to view a list of registered commands.\r\n\r\n>"; -const signed char *pcString; signed char cInChar, cInputIndex; -signed char cInputString[ cmdMAX_INPUT_SIZE ]; +static signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ]; +portBASE_TYPE xReturned; ( void ) pvParameters; @@ -134,12 +138,12 @@ signed char cInputString[ cmdMAX_INPUT_SIZE ]; { /* The input string was not a quit command. Pass the string to the command interpreter. */ - while( ( pcString = pcCmdIntProcessCommand( cInputString ) ) != NULL ) + do { - /* A string has been generated by the - command interpreter. Send it. */ - lwip_send( lClientFd, pcString, strlen( ( const char * ) pcString ), 0 ); - } + xReturned = xCmdIntProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE ); + lwip_send( lClientFd, cOutputString, strlen( ( const char * ) cOutputString ), 0 ); + + } while( xReturned != pdFALSE ); /* All the strings generated by the input command have been sent. Clear the input diff --git a/Demo/WIN32-MSVC-lwIP/main.c b/Demo/WIN32-MSVC-lwIP/main.c index 27aecaee1..ac29b6acb 100644 --- a/Demo/WIN32-MSVC-lwIP/main.c +++ b/Demo/WIN32-MSVC-lwIP/main.c @@ -122,11 +122,11 @@ static void prvCheckTimerCallback( xTimerHandle xTimer ); extern void lwIPAppsInit( void *pvArguments ); /* Callbacks to handle the command line commands defined by the xTaskStats and -xRunTimeStats command definitions respectively. These functions are not -reentrant! They must be used from one task only - or at least by only one task -at a time. */ -static const signed char *prvTaskStatsCommand( void ); -static const signed char *prvRunTimeStatsCommand( void ); +xRunTimeStats command definitions respectively. These functions are not +necessarily reentrant! They must be used from one task only - or at least by +only one task at a time. */ +static portBASE_TYPE prvTaskStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen ); +static portBASE_TYPE prvRunTimeStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen ); /* The string that latches the current demo status. */ static char *pcStatusMessage = "All tasks running without error"; @@ -316,70 +316,41 @@ unsigned long ulReturn; } /*-----------------------------------------------------------*/ -static const signed char *prvTaskStatsCommand( void ) +static portBASE_TYPE prvTaskStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen ) { -static signed char *pcReturn = NULL; const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n"; - /* This is the callback function that is executed when the command line - command defined by the xTaskStats structure is entered. This function - is called repeatedly until it returns NULL. It is therefore not re-entrant - and must not be called from more than one task - or at least - not from - more than one task at the same time. */ - if( pcReturn == NULL ) - { - /* Generate a table of task state. */ - pcReturn = pcLwipAppsBlockingGetTxBuffer(); - if( pcReturn != NULL ) - { - strcpy( pcReturn, pcHeader ); - vTaskList( pcReturn + strlen( pcHeader ) ); - } - } - else - { - /* This command only returns one string, so the second time it is - called it just resets itself and returns NULL to say no more strings - are going to be generated. */ - pcReturn = NULL; - vLwipAppsReleaseTxBuffer(); - } + configASSERT( pcWriteBuffer ); + + /* This function assumes the buffer length is adequate. */ + ( void ) xWriteBufferLen; + + /* Generate a table of task stats. */ + strcpy( pcWriteBuffer, pcHeader ); + vTaskList( pcWriteBuffer + strlen( pcHeader ) ); - return pcReturn; + /* There is no more data to return after this single string, so return + pdFALSE. */ + return pdFALSE; } /*-----------------------------------------------------------*/ -static const signed char *prvRunTimeStatsCommand( void ) +static portBASE_TYPE prvRunTimeStatsCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen ) { -static signed char *pcReturn = NULL; const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n"; - /* This is the callback function that is executed when the command line - command defined by the xRunTimeStats structure is entered. This function - is called repeatedly until it returns NULL. It is therefore not re-entrant - and must not be called from more than one task - or at least - not from - more than one task at the same time. */ + configASSERT( pcWriteBuffer ); - if( pcReturn == NULL ) - { - /* Generate a table of run time stats. */ - pcReturn = pcLwipAppsBlockingGetTxBuffer(); - if( pcReturn != NULL ) - { - strcpy( pcReturn, pcHeader ); - vTaskGetRunTimeStats( pcReturn + strlen( pcHeader ) ); - } - } - else - { - /* This command only returns one string, so the second time it is - called it just resets itself and returns NULL to say no more strings - are going to be generated. */ - pcReturn = NULL; - vLwipAppsReleaseTxBuffer(); - } + /* This function assumes the buffer length is adequate. */ + ( void ) xWriteBufferLen; + + /* Generate a table of task stats. */ + strcpy( pcWriteBuffer, pcHeader ); + vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) ); - return pcReturn; + /* There is no more data to return after this single string, so return + pdFALSE. */ + return pdFALSE; }