]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/CLI-commands.c
Update FreeRTOS+ version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / CLI-commands.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70  /******************************************************************************\r
71  *\r
72  * See the following URL for information on the commands defined in this file:\r
73  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml\r
74  *\r
75  ******************************************************************************/\r
76 \r
77 \r
78 /* FreeRTOS includes. */\r
79 #include "FreeRTOS.h"\r
80 #include "task.h"\r
81 \r
82 /* Standard includes. */\r
83 #include <stdint.h>\r
84 #include <stdio.h>\r
85 #include <stdlib.h>\r
86 \r
87 /* FreeRTOS+CLI includes. */\r
88 #include "FreeRTOS_CLI.h"\r
89 \r
90 /* FreeRTOS+UDP includes, just to make the stats available to the CLI\r
91 commands. */\r
92 #include "FreeRTOS_UDP_IP.h"\r
93 #include "FreeRTOS_Sockets.h"\r
94 \r
95 #ifndef  configINCLUDE_TRACE_RELATED_CLI_COMMANDS\r
96         #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0\r
97 #endif\r
98 \r
99 \r
100 /*\r
101  * Implements the run-time-stats command.\r
102  */\r
103 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
104 \r
105 /*\r
106  * Implements the task-stats command.\r
107  */\r
108 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
109 \r
110 /*\r
111  * Implements the echo-three-parameters command.\r
112  */\r
113 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
114 \r
115 /*\r
116  * Implements the echo-parameters command.\r
117  */\r
118 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
119 \r
120 /*\r
121  * Defines a command that prints out IP address information.\r
122  */\r
123 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
124 \r
125 /*\r
126  * Defines a command that prints out the gathered demo debug stats.\r
127  */\r
128 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
129 \r
130 /*\r
131  * Defines a command that sends an ICMP ping request to an IP address.\r
132  */\r
133 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
134 \r
135 /*\r
136  * Implements the "trace start" and "trace stop" commands;\r
137  */\r
138 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
139         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
140 #endif\r
141 \r
142 /* Structure that defines the "ip-config" command line command. */\r
143 static const CLI_Command_Definition_t xIPConfig =\r
144 {\r
145         "ip-config",\r
146         "ip-config:\r\n Displays IP address configuration\r\n\r\n",\r
147         prvDisplayIPConfig,\r
148         0\r
149 };\r
150 \r
151 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
152         /* Structure that defines the "ip-debug-stats" command line command. */\r
153         static const CLI_Command_Definition_t xIPDebugStats =\r
154         {\r
155                 "ip-debug-stats", /* The command string to type. */\r
156                 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",\r
157                 prvDisplayIPDebugStats, /* The function to run. */\r
158                 0 /* No parameters are expected. */\r
159         };\r
160 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
161 \r
162 /* Structure that defines the "run-time-stats" command line command.   This\r
163 generates a table that shows how much run time each task has */\r
164 static const CLI_Command_Definition_t xRunTimeStats =\r
165 {\r
166         "run-time-stats", /* The command string to type. */\r
167         "run-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n\r\n",\r
168         prvRunTimeStatsCommand, /* The function to run. */\r
169         0 /* No parameters are expected. */\r
170 };\r
171 \r
172 /* Structure that defines the "task-stats" command line command.  This generates\r
173 a table that gives information on each task in the system. */\r
174 static const CLI_Command_Definition_t xTaskStats =\r
175 {\r
176         "task-stats", /* The command string to type. */\r
177         "task-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n\r\n",\r
178         prvTaskStatsCommand, /* The function to run. */\r
179         0 /* No parameters are expected. */\r
180 };\r
181 \r
182 /* Structure that defines the "echo_3_parameters" command line command.  This\r
183 takes exactly three parameters that the command simply echos back one at a\r
184 time. */\r
185 static const CLI_Command_Definition_t xThreeParameterEcho =\r
186 {\r
187         "echo-3-parameters",\r
188         "echo-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n\r\n",\r
189         prvThreeParameterEchoCommand, /* The function to run. */\r
190         3 /* Three parameters are expected, which can take any value. */\r
191 };\r
192 \r
193 /* Structure that defines the "echo_parameters" command line command.  This\r
194 takes a variable number of parameters that the command simply echos back one at\r
195 a time. */\r
196 static const CLI_Command_Definition_t xParameterEcho =\r
197 {\r
198         "echo-parameters",\r
199         "echo-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n\r\n",\r
200         prvParameterEchoCommand, /* The function to run. */\r
201         -1 /* The user can enter any number of commands. */\r
202 };\r
203 \r
204 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
205 \r
206         /* Structure that defines the "ping" command line command.  This takes an IP\r
207         address or host name and (optionally) the number of bytes to ping as\r
208         parameters. */\r
209         static const CLI_Command_Definition_t xPing =\r
210         {\r
211                 "ping",\r
212                 "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
213                 prvPingCommand, /* The function to run. */\r
214                 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */\r
215         };\r
216 \r
217 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
218 \r
219 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
220         /* Structure that defines the "trace" command line command.  This takes a single\r
221         parameter, which can be either "start" or "stop". */\r
222         static const CLI_Command_Definition_t xStartStopTrace =\r
223         {\r
224                 "trace",\r
225                 "trace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n\r\n",\r
226                 prvStartStopTraceCommand, /* The function to run. */\r
227                 1 /* One parameter is expected.  Valid values are "start" and "stop". */\r
228         };\r
229 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r
230 \r
231 /*-----------------------------------------------------------*/\r
232 \r
233 void vRegisterCLICommands( void )\r
234 {\r
235         /* Register all the command line commands defined immediately above. */\r
236         FreeRTOS_CLIRegisterCommand( &xTaskStats );\r
237         FreeRTOS_CLIRegisterCommand( &xRunTimeStats );\r
238         FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );\r
239         FreeRTOS_CLIRegisterCommand( &xParameterEcho );\r
240         FreeRTOS_CLIRegisterCommand( &xIPDebugStats );\r
241         FreeRTOS_CLIRegisterCommand( &xIPConfig );\r
242 \r
243         #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
244         {\r
245                 FreeRTOS_CLIRegisterCommand( &xPing );\r
246         }\r
247         #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
248 \r
249         #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
250                 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );\r
251         #endif\r
252 }\r
253 /*-----------------------------------------------------------*/\r
254 \r
255 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
256 {\r
257 const char *const pcHeader = "Task          State  Priority  Stack      #\r\n************************************************\r\n";\r
258 \r
259         /* Remove compile time warnings about unused parameters, and check the\r
260         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
261         write buffer length is adequate, so does not check for buffer overflows. */\r
262         ( void ) pcCommandString;\r
263         ( void ) xWriteBufferLen;\r
264         configASSERT( pcWriteBuffer );\r
265 \r
266         /* Generate a table of task stats. */\r
267         strcpy( pcWriteBuffer, pcHeader );\r
268         vTaskList( pcWriteBuffer + strlen( pcHeader ) );\r
269 \r
270         /* There is no more data to return after this single string, so return\r
271         pdFALSE. */\r
272         return pdFALSE;\r
273 }\r
274 /*-----------------------------------------------------------*/\r
275 \r
276 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
277 {\r
278 const char * const pcHeader = "Task            Abs Time      % Time\r\n****************************************\r\n";\r
279 \r
280         /* Remove compile time warnings about unused parameters, and check the\r
281         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
282         write buffer length is adequate, so does not check for buffer overflows. */\r
283         ( void ) pcCommandString;\r
284         ( void ) xWriteBufferLen;\r
285         configASSERT( pcWriteBuffer );\r
286 \r
287         /* Generate a table of task stats. */\r
288         strcpy( pcWriteBuffer, pcHeader );\r
289         vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );\r
290 \r
291         /* There is no more data to return after this single string, so return\r
292         pdFALSE. */\r
293         return pdFALSE;\r
294 }\r
295 /*-----------------------------------------------------------*/\r
296 \r
297 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
298 {\r
299 const char *pcParameter;\r
300 BaseType_t xParameterStringLength, xReturn;\r
301 static BaseType_t lParameterNumber = 0;\r
302 \r
303         /* Remove compile time warnings about unused parameters, and check the\r
304         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
305         write buffer length is adequate, so does not check for buffer overflows. */\r
306         ( void ) pcCommandString;\r
307         ( void ) xWriteBufferLen;\r
308         configASSERT( pcWriteBuffer );\r
309 \r
310         if( lParameterNumber == 0 )\r
311         {\r
312                 /* The first time the function is called after the command has been\r
313                 entered just a header string is returned. */\r
314                 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );\r
315 \r
316                 /* Next time the function is called the first parameter will be echoed\r
317                 back. */\r
318                 lParameterNumber = 1L;\r
319 \r
320                 /* There is more data to be returned as no parameters have been echoed\r
321                 back yet. */\r
322                 xReturn = pdPASS;\r
323         }\r
324         else\r
325         {\r
326                 /* Obtain the parameter string. */\r
327                 pcParameter = FreeRTOS_CLIGetParameter\r
328                                                 (\r
329                                                         pcCommandString,                /* The command string itself. */\r
330                                                         lParameterNumber,               /* Return the next parameter. */\r
331                                                         &xParameterStringLength /* Store the parameter string length. */\r
332                                                 );\r
333 \r
334                 /* Sanity check something was returned. */\r
335                 configASSERT( pcParameter );\r
336 \r
337                 /* Return the parameter string. */\r
338                 memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
339                 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
340                 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
341                 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
342 \r
343                 /* If this is the last of the three parameters then there are no more\r
344                 strings to return after this one. */\r
345                 if( lParameterNumber == 3L )\r
346                 {\r
347                         /* If this is the last of the three parameters then there are no more\r
348                         strings to return after this one. */\r
349                         xReturn = pdFALSE;\r
350                         lParameterNumber = 0L;\r
351                 }\r
352                 else\r
353                 {\r
354                         /* There are more parameters to return after this one. */\r
355                         xReturn = pdTRUE;\r
356                         lParameterNumber++;\r
357                 }\r
358         }\r
359 \r
360         return xReturn;\r
361 }\r
362 /*-----------------------------------------------------------*/\r
363 \r
364 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
365 {\r
366 const char *pcParameter;\r
367 BaseType_t xParameterStringLength, xReturn;\r
368 static BaseType_t lParameterNumber = 0;\r
369 \r
370         /* Remove compile time warnings about unused parameters, and check the\r
371         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
372         write buffer length is adequate, so does not check for buffer overflows. */\r
373         ( void ) pcCommandString;\r
374         ( void ) xWriteBufferLen;\r
375         configASSERT( pcWriteBuffer );\r
376 \r
377         if( lParameterNumber == 0 )\r
378         {\r
379                 /* The first time the function is called after the command has been\r
380                 entered just a header string is returned. */\r
381                 sprintf( pcWriteBuffer, "The parameters were:\r\n" );\r
382 \r
383                 /* Next time the function is called the first parameter will be echoed\r
384                 back. */\r
385                 lParameterNumber = 1L;\r
386 \r
387                 /* There is more data to be returned as no parameters have been echoed\r
388                 back yet. */\r
389                 xReturn = pdPASS;\r
390         }\r
391         else\r
392         {\r
393                 /* Obtain the parameter string. */\r
394                 pcParameter = FreeRTOS_CLIGetParameter\r
395                                                 (\r
396                                                         pcCommandString,                /* The command string itself. */\r
397                                                         lParameterNumber,               /* Return the next parameter. */\r
398                                                         &xParameterStringLength /* Store the parameter string length. */\r
399                                                 );\r
400 \r
401                 if( pcParameter != NULL )\r
402                 {\r
403                         /* Return the parameter string. */\r
404                         memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
405                         sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
406                         strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
407                         strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
408 \r
409                         /* There might be more parameters to return after this one. */\r
410                         xReturn = pdTRUE;\r
411                         lParameterNumber++;\r
412                 }\r
413                 else\r
414                 {\r
415                         /* No more parameters were found.  Make sure the write buffer does\r
416                         not contain a valid string. */\r
417                         pcWriteBuffer[ 0 ] = 0x00;\r
418 \r
419                         /* No more data to return. */\r
420                         xReturn = pdFALSE;\r
421 \r
422                         /* Start over the next time this command is executed. */\r
423                         lParameterNumber = 0;\r
424                 }\r
425         }\r
426 \r
427         return xReturn;\r
428 }\r
429 /*-----------------------------------------------------------*/\r
430 \r
431 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
432 \r
433         static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
434         {\r
435         char * pcParameter;\r
436         BaseType_t lParameterStringLength, xReturn;\r
437         uint32_t ulIPAddress, ulBytesToPing;\r
438         const uint32_t ulDefaultBytesToPing = 8UL;\r
439         char cBuffer[ 16 ];\r
440 \r
441                 /* Remove compile time warnings about unused parameters, and check the\r
442                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
443                 write buffer length is adequate, so does not check for buffer overflows. */\r
444                 ( void ) pcCommandString;\r
445                 ( void ) xWriteBufferLen;\r
446                 configASSERT( pcWriteBuffer );\r
447 \r
448                 /* Start with an empty string. */\r
449                 pcWriteBuffer[ 0 ] = 0x00;\r
450 \r
451                 /* Obtain the number of bytes to ping. */\r
452                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
453                                                                 (\r
454                                                                         pcCommandString,                /* The command string itself. */\r
455                                                                         2,                                              /* Return the second parameter. */\r
456                                                                         &lParameterStringLength /* Store the parameter string length. */\r
457                                                                 );\r
458 \r
459                 if( pcParameter == NULL )\r
460                 {\r
461                         /* The number of bytes was not specified, so default it. */\r
462                         ulBytesToPing = ulDefaultBytesToPing;\r
463                 }\r
464                 else\r
465                 {\r
466                         ulBytesToPing = atol( pcParameter );\r
467                 }\r
468 \r
469                 /* Obtain the IP address string. */\r
470                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
471                                                                 (\r
472                                                                         pcCommandString,                /* The command string itself. */\r
473                                                                         1,                                              /* Return the first parameter. */\r
474                                                                         &lParameterStringLength /* Store the parameter string length. */\r
475                                                                 );\r
476 \r
477                 /* Sanity check something was returned. */\r
478                 configASSERT( pcParameter );\r
479 \r
480                 /* Attempt to obtain the IP address.   If the first character is not a\r
481                 digit, assume the host name has been passed in. */\r
482                 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )\r
483                 {\r
484                         ulIPAddress = FreeRTOS_inet_addr( pcParameter );\r
485                 }\r
486                 else\r
487                 {\r
488                         /* Terminate the host name. */\r
489                         pcParameter[ lParameterStringLength ] = 0x00;\r
490 \r
491                         /* Attempt to resolve host. */\r
492                         ulIPAddress = FreeRTOS_gethostbyname( pcParameter );\r
493                 }\r
494 \r
495                 /* Convert IP address, which may have come from a DNS lookup, to string. */\r
496                 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );\r
497 \r
498                 if( ulIPAddress != 0 )\r
499                 {\r
500                         xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );\r
501                 }\r
502                 else\r
503                 {\r
504                         xReturn = pdFALSE;\r
505                 }\r
506 \r
507                 if( xReturn == pdFALSE )\r
508                 {\r
509                         sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );\r
510                 }\r
511                 else\r
512                 {\r
513                         sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, xReturn );\r
514                 }\r
515 \r
516                 return pdFALSE;\r
517         }\r
518         /*-----------------------------------------------------------*/\r
519 \r
520 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
521 \r
522 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
523 \r
524         static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
525         {\r
526         static BaseType_t xIndex = -1;\r
527         extern xExampleDebugStatEntry_t xIPTraceValues[];\r
528         BaseType_t xReturn;\r
529 \r
530                 /* Remove compile time warnings about unused parameters, and check the\r
531                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
532                 write buffer length is adequate, so does not check for buffer overflows. */\r
533                 ( void ) pcCommandString;\r
534                 ( void ) xWriteBufferLen;\r
535                 configASSERT( pcWriteBuffer );\r
536 \r
537                 xIndex++;\r
538 \r
539                 if( xIndex < xExampleDebugStatEntries() )\r
540                 {\r
541                         sprintf( pcWriteBuffer, "%s %d\r\n", xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );\r
542                         xReturn = pdPASS;\r
543                 }\r
544                 else\r
545                 {\r
546                         /* Reset the index for the next time it is called. */\r
547                         xIndex = -1;\r
548 \r
549                         /* Ensure nothing remains in the write buffer. */\r
550                         pcWriteBuffer[ 0 ] = 0x00;\r
551                         xReturn = pdFALSE;\r
552                 }\r
553 \r
554                 return xReturn;\r
555         }\r
556         /*-----------------------------------------------------------*/\r
557 \r
558 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
559 \r
560 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
561 {\r
562 static BaseType_t xIndex = 0;\r
563 BaseType_t xReturn;\r
564 uint32_t ulAddress;\r
565 \r
566         /* Remove compile time warnings about unused parameters, and check the\r
567         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
568         write buffer length is adequate, so does not check for buffer overflows. */\r
569         ( void ) pcCommandString;\r
570         ( void ) xWriteBufferLen;\r
571         configASSERT( pcWriteBuffer );\r
572 \r
573         switch( xIndex )\r
574         {\r
575                 case 0 :\r
576                         FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );\r
577                         sprintf( pcWriteBuffer, "\r\nIP address " );\r
578                         xReturn = pdTRUE;\r
579                         xIndex++;\r
580                         break;\r
581 \r
582                 case 1 :\r
583                         FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );\r
584                         sprintf( pcWriteBuffer, "\r\nNet mask " );\r
585                         xReturn = pdTRUE;\r
586                         xIndex++;\r
587                         break;\r
588 \r
589                 case 2 :\r
590                         FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );\r
591                         sprintf( pcWriteBuffer, "\r\nGateway address " );\r
592                         xReturn = pdTRUE;\r
593                         xIndex++;\r
594                         break;\r
595 \r
596                 case 3 :\r
597                         FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );\r
598                         sprintf( pcWriteBuffer, "\r\nDNS server address " );\r
599                         xReturn = pdTRUE;\r
600                         xIndex++;\r
601                         break;\r
602 \r
603                 default :\r
604                         ulAddress = 0;\r
605                         sprintf( pcWriteBuffer, "\r\n\r\n" );\r
606                         xReturn = pdFALSE;\r
607                         xIndex = 0;\r
608                         break;\r
609         }\r
610 \r
611         if( ulAddress != 0 )\r
612         {\r
613                 FreeRTOS_inet_ntoa( ulAddress,  &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) );\r
614         }\r
615 \r
616         return xReturn;\r
617 }\r
618 /*-----------------------------------------------------------*/\r
619 \r
620 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
621 \r
622         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
623         {\r
624         const char *pcParameter;\r
625         BaseType_t lParameterStringLength;\r
626 \r
627                 /* Remove compile time warnings about unused parameters, and check the\r
628                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
629                 write buffer length is adequate, so does not check for buffer overflows. */\r
630                 ( void ) pcCommandString;\r
631                 ( void ) xWriteBufferLen;\r
632                 configASSERT( pcWriteBuffer );\r
633 \r
634                 /* Obtain the parameter string. */\r
635                 pcParameter = FreeRTOS_CLIGetParameter\r
636                                                 (\r
637                                                         pcCommandString,                /* The command string itself. */\r
638                                                         1,                                              /* Return the first parameter. */\r
639                                                         &lParameterStringLength /* Store the parameter string length. */\r
640                                                 );\r
641 \r
642                 /* Sanity check something was returned. */\r
643                 configASSERT( pcParameter );\r
644 \r
645                 /* There are only two valid parameter values. */\r
646                 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )\r
647                 {\r
648                         /* Start or restart the trace. */\r
649                         vTraceStop();\r
650                         vTraceClear();\r
651                         vTraceStart();\r
652 \r
653                         sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );\r
654                 }\r
655                 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )\r
656                 {\r
657                         /* End the trace, if one is running. */\r
658                         vTraceStop();\r
659                         sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );\r
660                 }\r
661                 else\r
662                 {\r
663                         sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );\r
664                 }\r
665 \r
666                 /* There is no more data to return after this single string, so return\r
667                 pdFALSE. */\r
668                 return pdFALSE;\r
669         }\r
670 \r
671 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r