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