From f42a1c08f597bd176865b4f0514383aedcbabbf0 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Wed, 3 Aug 2011 09:36:12 +0000 Subject: [PATCH] Change command interpreter semantics. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1536 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Demo/WIN32-MSVC-lwIP/WIN32.suo | Bin 98816 -> 98816 bytes .../BasicSocketCommandServer.c | 18 ++-- Demo/WIN32-MSVC-lwIP/main.c | 85 ++++++------------ 3 files changed, 39 insertions(+), 64 deletions(-) diff --git a/Demo/WIN32-MSVC-lwIP/WIN32.suo b/Demo/WIN32-MSVC-lwIP/WIN32.suo index 86113f5382e2d6ebc2f811b2a3404fb49f659f4c..a43142fa408746ab1b21359f89610439a5c43995 100644 GIT binary patch delta 4123 zcmb_f3s6&M7QQDW*MJa13=u&gMpOnR2E+#zC4qXnE8Q;b#@2Cnt5$5g_Tgh`*Sb~PijH=wYjw}PiKw%)?o4OzopbO1 zKIi|>cOJi^iFY*d9p@!52QNtG!&vutzlp#ruLUjfWMQrJtaLQTan4K8&LF9~UUpJ0 zmr&i`+vc__<^X=MDc*g1z#NHOL9IdF9<-~PB!2wE&y*`5pfzhC z3sivIou6DTl|P_I~F?%J1;>Dp+ID3blWv9S8d@)jB zn28Up<5Br)9va?J3TLFiqTNz#-)7lUNy22SQDqzBHrhPE;s?VrY=2b+-?BIvoWPE| za@^Ubfh>Hm<0W*|>R8lT;hYq_+g#fPz-Z}%SX#VG%5ioM8|T(yVKI-=q6vqVB}h>I zg3@iS?~+Rw2wIdjcKfY0Q)wd6WTHf(XNc~TN(7oh<*7s|L`EVLkxGl^yq%_f>dWFg8TnoBf~D4Qrp!VTu0rNVq7Vc}fge-Zt$@`V|4p|M)1 zbiJS*E>u=fWuU0!*WeG$N=&$Y9HX}=2@+k{b5D-5H>wFe55Y$$!lJD_ zCfpR}M__)Gf}pp6r0we49rm>Fl7ckn&Z%zWP6AS1H0VgQIuh**OlncW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$G7;jgh+p40*EQo+J*!0|9DTBOcv|yG|dloF1 zmcdf*K34uy;M>$u@^(m2z5u!D$^0SLRM--h=KS`ZZCQWQFZtB4x1=Kyim}}}SN?8n zQyhMgsiQ-YV59*vME|s1m}p=cnCZZDm<^`_h^@n!Gh*3@Tt<+0$-M&zr9 zkh%*)O*C8yY7=rWrFRxxo(^`XlgePl=@>9gCe3!3Ds^0Z#u`IS55QxjFJ!W!bRo#l z^M?7}*4U4>3e|siK^?i25a*4{fQvxQ4GSSgl9OC2DFrp$*Yq%!{U9w1graHNxJ(;i|E_`S{Fb=e4VsVfJ;WE^^g~_T3Gwz<+?9kZfZ*S;j0S4gNW*3pc)XN{f(ZXOL%7*QXI5}xyO%=@bG0(p&4A!kI&1@V$0~S@hRY!t4qnzT^d7 zJadxM&i3!5+jb~YzQ{CbK=ILQVILX}6#B;|9x>)*uzLUB_;NNdx8$AP3I^adT`2)Q zi+h?c>+!WBveZNFPbWn89N&akPj8e$6~=p|re^kbH^9*#X;3HUPO!=+`xW+%?Svx0 zoNcMJwGqxKk1_cr|50!yk737gyJ-#`*~OjvWhS5SA3-hM-UUnX*>#EkW2RyaBbe_p Q!LK2QG{1&<6JJUH0g|$k)c^nh 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; } -- 2.39.5