]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/CLI-commands.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / CLI-commands.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29  /******************************************************************************\r
30  *\r
31  * See the following URL for information on the commands defined in this file:\r
32  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml\r
33  *\r
34  ******************************************************************************/\r
35 \r
36 \r
37 /* FreeRTOS includes. */\r
38 #include "FreeRTOS.h"\r
39 #include "task.h"\r
40 \r
41 /* Standard includes. */\r
42 #include <stdint.h>\r
43 #include <stdio.h>\r
44 #include <stdlib.h>\r
45 \r
46 /* FreeRTOS+CLI includes. */\r
47 #include "FreeRTOS_CLI.h"\r
48 \r
49 /* FreeRTOS+UDP includes, just to make the stats available to the CLI\r
50 commands. */\r
51 #include "FreeRTOS_UDP_IP.h"\r
52 #include "FreeRTOS_Sockets.h"\r
53 \r
54 #ifndef  configINCLUDE_TRACE_RELATED_CLI_COMMANDS\r
55         #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0\r
56 #endif\r
57 \r
58 \r
59 /*\r
60  * Implements the run-time-stats command.\r
61  */\r
62 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
63 \r
64 /*\r
65  * Implements the task-stats command.\r
66  */\r
67 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
68 \r
69 /*\r
70  * Implements the echo-three-parameters command.\r
71  */\r
72 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
73 \r
74 /*\r
75  * Implements the echo-parameters command.\r
76  */\r
77 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
78 \r
79 /*\r
80  * Defines a command that prints out IP address information.\r
81  */\r
82 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
83 \r
84 /*\r
85  * Defines a command that prints out the gathered demo debug stats.\r
86  */\r
87 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
88 \r
89 /*\r
90  * Defines a command that sends an ICMP ping request to an IP address.\r
91  */\r
92 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
93 \r
94 /*\r
95  * Implements the "trace start" and "trace stop" commands;\r
96  */\r
97 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
98         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
99 #endif\r
100 \r
101 /* Structure that defines the "ip-config" command line command. */\r
102 static const CLI_Command_Definition_t xIPConfig =\r
103 {\r
104         "ip-config",\r
105         "ip-config:\r\n Displays IP address configuration\r\n\r\n",\r
106         prvDisplayIPConfig,\r
107         0\r
108 };\r
109 \r
110 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
111         /* Structure that defines the "ip-debug-stats" command line command. */\r
112         static const CLI_Command_Definition_t xIPDebugStats =\r
113         {\r
114                 "ip-debug-stats", /* The command string to type. */\r
115                 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",\r
116                 prvDisplayIPDebugStats, /* The function to run. */\r
117                 0 /* No parameters are expected. */\r
118         };\r
119 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
120 \r
121 /* Structure that defines the "run-time-stats" command line command.   This\r
122 generates a table that shows how much run time each task has */\r
123 static const CLI_Command_Definition_t xRunTimeStats =\r
124 {\r
125         "run-time-stats", /* The command string to type. */\r
126         "run-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n\r\n",\r
127         prvRunTimeStatsCommand, /* The function to run. */\r
128         0 /* No parameters are expected. */\r
129 };\r
130 \r
131 /* Structure that defines the "task-stats" command line command.  This generates\r
132 a table that gives information on each task in the system. */\r
133 static const CLI_Command_Definition_t xTaskStats =\r
134 {\r
135         "task-stats", /* The command string to type. */\r
136         "task-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n\r\n",\r
137         prvTaskStatsCommand, /* The function to run. */\r
138         0 /* No parameters are expected. */\r
139 };\r
140 \r
141 /* Structure that defines the "echo_3_parameters" command line command.  This\r
142 takes exactly three parameters that the command simply echos back one at a\r
143 time. */\r
144 static const CLI_Command_Definition_t xThreeParameterEcho =\r
145 {\r
146         "echo-3-parameters",\r
147         "echo-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n\r\n",\r
148         prvThreeParameterEchoCommand, /* The function to run. */\r
149         3 /* Three parameters are expected, which can take any value. */\r
150 };\r
151 \r
152 /* Structure that defines the "echo_parameters" command line command.  This\r
153 takes a variable number of parameters that the command simply echos back one at\r
154 a time. */\r
155 static const CLI_Command_Definition_t xParameterEcho =\r
156 {\r
157         "echo-parameters",\r
158         "echo-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n\r\n",\r
159         prvParameterEchoCommand, /* The function to run. */\r
160         -1 /* The user can enter any number of commands. */\r
161 };\r
162 \r
163 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
164 \r
165         /* Structure that defines the "ping" command line command.  This takes an IP\r
166         address or host name and (optionally) the number of bytes to ping as\r
167         parameters. */\r
168         static const CLI_Command_Definition_t xPing =\r
169         {\r
170                 "ping",\r
171                 "ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",\r
172                 prvPingCommand, /* The function to run. */\r
173                 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */\r
174         };\r
175 \r
176 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
177 \r
178 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
179         /* Structure that defines the "trace" command line command.  This takes a single\r
180         parameter, which can be either "start" or "stop". */\r
181         static const CLI_Command_Definition_t xStartStopTrace =\r
182         {\r
183                 "trace",\r
184                 "trace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n\r\n",\r
185                 prvStartStopTraceCommand, /* The function to run. */\r
186                 1 /* One parameter is expected.  Valid values are "start" and "stop". */\r
187         };\r
188 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r
189 \r
190 /*-----------------------------------------------------------*/\r
191 \r
192 void vRegisterCLICommands( void )\r
193 {\r
194         /* Register all the command line commands defined immediately above. */\r
195         FreeRTOS_CLIRegisterCommand( &xTaskStats );\r
196         FreeRTOS_CLIRegisterCommand( &xRunTimeStats );\r
197         FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );\r
198         FreeRTOS_CLIRegisterCommand( &xParameterEcho );\r
199         FreeRTOS_CLIRegisterCommand( &xIPDebugStats );\r
200         FreeRTOS_CLIRegisterCommand( &xIPConfig );\r
201 \r
202         #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
203         {\r
204                 FreeRTOS_CLIRegisterCommand( &xPing );\r
205         }\r
206         #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
207 \r
208         #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
209                 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );\r
210         #endif\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
215 {\r
216 const char *const pcHeader = "  State\tPriority\tStack\t#\r\n************************************************\r\n";\r
217 BaseType_t xSpacePadding;\r
218 \r
219         /* Remove compile time warnings about unused parameters, and check the\r
220         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
221         write buffer length is adequate, so does not check for buffer overflows. */\r
222         ( void ) pcCommandString;\r
223         ( void ) xWriteBufferLen;\r
224         configASSERT( pcWriteBuffer );\r
225 \r
226         /* Generate a table of task stats. */\r
227         strcpy( pcWriteBuffer, "Task" );\r
228         pcWriteBuffer += strlen( pcWriteBuffer );\r
229 \r
230         /* Pad the string "task" with however many bytes necessary to make it the\r
231         length of a task name.  Minus three for the null terminator and half the \r
232         number of characters in "Task" so the column lines up with the centre of \r
233         the heading. */\r
234         for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )\r
235         {\r
236                 /* Add a space to align columns after the task's name. */\r
237                 *pcWriteBuffer = ' ';\r
238                 pcWriteBuffer++;\r
239 \r
240                 /* Ensure always terminated. */\r
241                 *pcWriteBuffer = 0x00;\r
242         }\r
243         strcpy( pcWriteBuffer, pcHeader );\r
244         vTaskList( pcWriteBuffer + strlen( pcHeader ) );\r
245 \r
246         /* There is no more data to return after this single string, so return\r
247         pdFALSE. */\r
248         return pdFALSE;\r
249 }\r
250 /*-----------------------------------------------------------*/\r
251 \r
252 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
253 {\r
254 const char * const pcHeader = "  Abs Time      % Time\r\n****************************************\r\n";\r
255 BaseType_t xSpacePadding;\r
256 \r
257         /* Remove compile time warnings about unused parameters, and check the\r
258         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
259         write buffer length is adequate, so does not check for buffer overflows. */\r
260         ( void ) pcCommandString;\r
261         ( void ) xWriteBufferLen;\r
262         configASSERT( pcWriteBuffer );\r
263 \r
264         /* Generate a table of task stats. */\r
265         strcpy( pcWriteBuffer, "Task" );\r
266         pcWriteBuffer += strlen( pcWriteBuffer );\r
267 \r
268         /* Pad the string "task" with however many bytes necessary to make it the\r
269         length of a task name.  Minus three for the null terminator and half the \r
270         number of characters in "Task" so the column lines up with the centre of \r
271         the heading. */\r
272         for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )\r
273         {\r
274                 /* Add a space to align columns after the task's name. */\r
275                 *pcWriteBuffer = ' ';\r
276                 pcWriteBuffer++;\r
277 \r
278                 /* Ensure always terminated. */\r
279                 *pcWriteBuffer = 0x00;\r
280         }\r
281 \r
282         strcpy( pcWriteBuffer, pcHeader );\r
283         vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );\r
284 \r
285         /* There is no more data to return after this single string, so return\r
286         pdFALSE. */\r
287         return pdFALSE;\r
288 }\r
289 /*-----------------------------------------------------------*/\r
290 \r
291 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
292 {\r
293 const char *pcParameter;\r
294 BaseType_t xParameterStringLength, xReturn;\r
295 static BaseType_t lParameterNumber = 0;\r
296 \r
297         /* Remove compile time warnings about unused parameters, and check the\r
298         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
299         write buffer length is adequate, so does not check for buffer overflows. */\r
300         ( void ) pcCommandString;\r
301         ( void ) xWriteBufferLen;\r
302         configASSERT( pcWriteBuffer );\r
303 \r
304         if( lParameterNumber == 0 )\r
305         {\r
306                 /* The first time the function is called after the command has been\r
307                 entered just a header string is returned. */\r
308                 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );\r
309 \r
310                 /* Next time the function is called the first parameter will be echoed\r
311                 back. */\r
312                 lParameterNumber = 1L;\r
313 \r
314                 /* There is more data to be returned as no parameters have been echoed\r
315                 back yet. */\r
316                 xReturn = pdPASS;\r
317         }\r
318         else\r
319         {\r
320                 /* Obtain the parameter string. */\r
321                 pcParameter = FreeRTOS_CLIGetParameter\r
322                                                 (\r
323                                                         pcCommandString,                /* The command string itself. */\r
324                                                         lParameterNumber,               /* Return the next parameter. */\r
325                                                         &xParameterStringLength /* Store the parameter string length. */\r
326                                                 );\r
327 \r
328                 /* Sanity check something was returned. */\r
329                 configASSERT( pcParameter );\r
330 \r
331                 /* Return the parameter string. */\r
332                 memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
333                 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
334                 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
335                 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
336 \r
337                 /* If this is the last of the three parameters then there are no more\r
338                 strings to return after this one. */\r
339                 if( lParameterNumber == 3L )\r
340                 {\r
341                         /* If this is the last of the three parameters then there are no more\r
342                         strings to return after this one. */\r
343                         xReturn = pdFALSE;\r
344                         lParameterNumber = 0L;\r
345                 }\r
346                 else\r
347                 {\r
348                         /* There are more parameters to return after this one. */\r
349                         xReturn = pdTRUE;\r
350                         lParameterNumber++;\r
351                 }\r
352         }\r
353 \r
354         return xReturn;\r
355 }\r
356 /*-----------------------------------------------------------*/\r
357 \r
358 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
359 {\r
360 const char *pcParameter;\r
361 BaseType_t xParameterStringLength, xReturn;\r
362 static BaseType_t lParameterNumber = 0;\r
363 \r
364         /* Remove compile time warnings about unused parameters, and check the\r
365         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
366         write buffer length is adequate, so does not check for buffer overflows. */\r
367         ( void ) pcCommandString;\r
368         ( void ) xWriteBufferLen;\r
369         configASSERT( pcWriteBuffer );\r
370 \r
371         if( lParameterNumber == 0 )\r
372         {\r
373                 /* The first time the function is called after the command has been\r
374                 entered just a header string is returned. */\r
375                 sprintf( pcWriteBuffer, "The parameters were:\r\n" );\r
376 \r
377                 /* Next time the function is called the first parameter will be echoed\r
378                 back. */\r
379                 lParameterNumber = 1L;\r
380 \r
381                 /* There is more data to be returned as no parameters have been echoed\r
382                 back yet. */\r
383                 xReturn = pdPASS;\r
384         }\r
385         else\r
386         {\r
387                 /* Obtain the parameter string. */\r
388                 pcParameter = FreeRTOS_CLIGetParameter\r
389                                                 (\r
390                                                         pcCommandString,                /* The command string itself. */\r
391                                                         lParameterNumber,               /* Return the next parameter. */\r
392                                                         &xParameterStringLength /* Store the parameter string length. */\r
393                                                 );\r
394 \r
395                 if( pcParameter != NULL )\r
396                 {\r
397                         /* Return the parameter string. */\r
398                         memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
399                         sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
400                         strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
401                         strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
402 \r
403                         /* There might be more parameters to return after this one. */\r
404                         xReturn = pdTRUE;\r
405                         lParameterNumber++;\r
406                 }\r
407                 else\r
408                 {\r
409                         /* No more parameters were found.  Make sure the write buffer does\r
410                         not contain a valid string. */\r
411                         pcWriteBuffer[ 0 ] = 0x00;\r
412 \r
413                         /* No more data to return. */\r
414                         xReturn = pdFALSE;\r
415 \r
416                         /* Start over the next time this command is executed. */\r
417                         lParameterNumber = 0;\r
418                 }\r
419         }\r
420 \r
421         return xReturn;\r
422 }\r
423 /*-----------------------------------------------------------*/\r
424 \r
425 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
426 \r
427         static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
428         {\r
429         char * pcParameter;\r
430         BaseType_t lParameterStringLength, xReturn;\r
431         uint32_t ulIPAddress, ulBytesToPing;\r
432         const uint32_t ulDefaultBytesToPing = 8UL;\r
433         char cBuffer[ 16 ];\r
434 \r
435                 /* Remove compile time warnings about unused parameters, and check the\r
436                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
437                 write buffer length is adequate, so does not check for buffer overflows. */\r
438                 ( void ) pcCommandString;\r
439                 ( void ) xWriteBufferLen;\r
440                 configASSERT( pcWriteBuffer );\r
441 \r
442                 /* Start with an empty string. */\r
443                 pcWriteBuffer[ 0 ] = 0x00;\r
444 \r
445                 /* Obtain the number of bytes to ping. */\r
446                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
447                                                                 (\r
448                                                                         pcCommandString,                /* The command string itself. */\r
449                                                                         2,                                              /* Return the second parameter. */\r
450                                                                         &lParameterStringLength /* Store the parameter string length. */\r
451                                                                 );\r
452 \r
453                 if( pcParameter == NULL )\r
454                 {\r
455                         /* The number of bytes was not specified, so default it. */\r
456                         ulBytesToPing = ulDefaultBytesToPing;\r
457                 }\r
458                 else\r
459                 {\r
460                         ulBytesToPing = atol( pcParameter );\r
461                 }\r
462 \r
463                 /* Obtain the IP address string. */\r
464                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
465                                                                 (\r
466                                                                         pcCommandString,                /* The command string itself. */\r
467                                                                         1,                                              /* Return the first parameter. */\r
468                                                                         &lParameterStringLength /* Store the parameter string length. */\r
469                                                                 );\r
470 \r
471                 /* Sanity check something was returned. */\r
472                 configASSERT( pcParameter );\r
473 \r
474                 /* Attempt to obtain the IP address.   If the first character is not a\r
475                 digit, assume the host name has been passed in. */\r
476                 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )\r
477                 {\r
478                         ulIPAddress = FreeRTOS_inet_addr( pcParameter );\r
479                 }\r
480                 else\r
481                 {\r
482                         /* Terminate the host name. */\r
483                         pcParameter[ lParameterStringLength ] = 0x00;\r
484 \r
485                         /* Attempt to resolve host. */\r
486                         ulIPAddress = FreeRTOS_gethostbyname( pcParameter );\r
487                 }\r
488 \r
489                 /* Convert IP address, which may have come from a DNS lookup, to string. */\r
490                 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );\r
491 \r
492                 if( ulIPAddress != 0 )\r
493                 {\r
494                         xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );\r
495                 }\r
496                 else\r
497                 {\r
498                         xReturn = pdFALSE;\r
499                 }\r
500 \r
501                 if( xReturn == pdFALSE )\r
502                 {\r
503                         sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );\r
504                 }\r
505                 else\r
506                 {\r
507                         sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, xReturn );\r
508                 }\r
509 \r
510                 return pdFALSE;\r
511         }\r
512         /*-----------------------------------------------------------*/\r
513 \r
514 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
515 \r
516 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
517 \r
518         static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
519         {\r
520         static BaseType_t xIndex = -1;\r
521         extern xExampleDebugStatEntry_t xIPTraceValues[];\r
522         BaseType_t xReturn;\r
523 \r
524                 /* Remove compile time warnings about unused parameters, and check the\r
525                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
526                 write buffer length is adequate, so does not check for buffer overflows. */\r
527                 ( void ) pcCommandString;\r
528                 ( void ) xWriteBufferLen;\r
529                 configASSERT( pcWriteBuffer );\r
530 \r
531                 xIndex++;\r
532 \r
533                 if( xIndex < xExampleDebugStatEntries() )\r
534                 {\r
535                         sprintf( pcWriteBuffer, "%s %d\r\n", xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );\r
536                         xReturn = pdPASS;\r
537                 }\r
538                 else\r
539                 {\r
540                         /* Reset the index for the next time it is called. */\r
541                         xIndex = -1;\r
542 \r
543                         /* Ensure nothing remains in the write buffer. */\r
544                         pcWriteBuffer[ 0 ] = 0x00;\r
545                         xReturn = pdFALSE;\r
546                 }\r
547 \r
548                 return xReturn;\r
549         }\r
550         /*-----------------------------------------------------------*/\r
551 \r
552 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
553 \r
554 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
555 {\r
556 static BaseType_t xIndex = 0;\r
557 BaseType_t xReturn;\r
558 uint32_t ulAddress;\r
559 \r
560         /* Remove compile time warnings about unused parameters, and check the\r
561         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
562         write buffer length is adequate, so does not check for buffer overflows. */\r
563         ( void ) pcCommandString;\r
564         ( void ) xWriteBufferLen;\r
565         configASSERT( pcWriteBuffer );\r
566 \r
567         switch( xIndex )\r
568         {\r
569                 case 0 :\r
570                         FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );\r
571                         sprintf( pcWriteBuffer, "\r\nIP address " );\r
572                         xReturn = pdTRUE;\r
573                         xIndex++;\r
574                         break;\r
575 \r
576                 case 1 :\r
577                         FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );\r
578                         sprintf( pcWriteBuffer, "\r\nNet mask " );\r
579                         xReturn = pdTRUE;\r
580                         xIndex++;\r
581                         break;\r
582 \r
583                 case 2 :\r
584                         FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );\r
585                         sprintf( pcWriteBuffer, "\r\nGateway address " );\r
586                         xReturn = pdTRUE;\r
587                         xIndex++;\r
588                         break;\r
589 \r
590                 case 3 :\r
591                         FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );\r
592                         sprintf( pcWriteBuffer, "\r\nDNS server address " );\r
593                         xReturn = pdTRUE;\r
594                         xIndex++;\r
595                         break;\r
596 \r
597                 default :\r
598                         ulAddress = 0;\r
599                         sprintf( pcWriteBuffer, "\r\n\r\n" );\r
600                         xReturn = pdFALSE;\r
601                         xIndex = 0;\r
602                         break;\r
603         }\r
604 \r
605         if( ulAddress != 0 )\r
606         {\r
607                 FreeRTOS_inet_ntoa( ulAddress,  &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) );\r
608         }\r
609 \r
610         return xReturn;\r
611 }\r
612 /*-----------------------------------------------------------*/\r
613 \r
614 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
615 \r
616         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
617         {\r
618         const char *pcParameter;\r
619         BaseType_t lParameterStringLength;\r
620 \r
621                 /* Remove compile time warnings about unused parameters, and check the\r
622                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
623                 write buffer length is adequate, so does not check for buffer overflows. */\r
624                 ( void ) pcCommandString;\r
625                 ( void ) xWriteBufferLen;\r
626                 configASSERT( pcWriteBuffer );\r
627 \r
628                 /* Obtain the parameter string. */\r
629                 pcParameter = FreeRTOS_CLIGetParameter\r
630                                                 (\r
631                                                         pcCommandString,                /* The command string itself. */\r
632                                                         1,                                              /* Return the first parameter. */\r
633                                                         &lParameterStringLength /* Store the parameter string length. */\r
634                                                 );\r
635 \r
636                 /* Sanity check something was returned. */\r
637                 configASSERT( pcParameter );\r
638 \r
639                 /* There are only two valid parameter values. */\r
640                 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )\r
641                 {\r
642                         /* Start or restart the trace. */\r
643                         vTraceStop();\r
644                         vTraceClear();\r
645                         vTraceStart();\r
646 \r
647                         sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );\r
648                 }\r
649                 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )\r
650                 {\r
651                         /* End the trace, if one is running. */\r
652                         vTraceStop();\r
653                         sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );\r
654                 }\r
655                 else\r
656                 {\r
657                         sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );\r
658                 }\r
659 \r
660                 /* There is no more data to return after this single string, so return\r
661                 pdFALSE. */\r
662                 return pdFALSE;\r
663         }\r
664 \r
665 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r