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