]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/CLICommands/CLI-commands.c
Update FreeRTOS+ version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS-Plus / Demo / Common / FreeRTOS_Plus_UDP_Demos / CLICommands / 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 = "  State\tPriority\tStack\t#\r\n************************************************\r\n";\r
258 BaseType_t xSpacePadding;\r
259 \r
260         /* Remove compile time warnings about unused parameters, and check the\r
261         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
262         write buffer length is adequate, so does not check for buffer overflows. */\r
263         ( void ) pcCommandString;\r
264         ( void ) xWriteBufferLen;\r
265         configASSERT( pcWriteBuffer );\r
266 \r
267         /* Generate a table of task stats. */\r
268         strcpy( pcWriteBuffer, "Task" );\r
269         pcWriteBuffer += strlen( pcWriteBuffer );\r
270 \r
271         /* Pad the string "task" with however many bytes necessary to make it the\r
272         length of a task name.  Minus three for the null terminator and half the \r
273         number of characters in "Task" so the column lines up with the centre of \r
274         the heading. */\r
275         for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )\r
276         {\r
277                 /* Add a space to align columns after the task's name. */\r
278                 *pcWriteBuffer = ' ';\r
279                 pcWriteBuffer++;\r
280 \r
281                 /* Ensure always terminated. */\r
282                 *pcWriteBuffer = 0x00;\r
283         }\r
284         strcpy( pcWriteBuffer, pcHeader );\r
285         vTaskList( pcWriteBuffer + strlen( pcHeader ) );\r
286 \r
287         /* There is no more data to return after this single string, so return\r
288         pdFALSE. */\r
289         return pdFALSE;\r
290 }\r
291 /*-----------------------------------------------------------*/\r
292 \r
293 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
294 {\r
295 const char * const pcHeader = "  Abs Time      % Time\r\n****************************************\r\n";\r
296 BaseType_t xSpacePadding;\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         /* Generate a table of task stats. */\r
306         strcpy( pcWriteBuffer, "Task" );\r
307         pcWriteBuffer += strlen( pcWriteBuffer );\r
308 \r
309         /* Pad the string "task" with however many bytes necessary to make it the\r
310         length of a task name.  Minus three for the null terminator and half the \r
311         number of characters in "Task" so the column lines up with the centre of \r
312         the heading. */\r
313         for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )\r
314         {\r
315                 /* Add a space to align columns after the task's name. */\r
316                 *pcWriteBuffer = ' ';\r
317                 pcWriteBuffer++;\r
318 \r
319                 /* Ensure always terminated. */\r
320                 *pcWriteBuffer = 0x00;\r
321         }\r
322 \r
323         strcpy( pcWriteBuffer, pcHeader );\r
324         vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );\r
325 \r
326         /* There is no more data to return after this single string, so return\r
327         pdFALSE. */\r
328         return pdFALSE;\r
329 }\r
330 /*-----------------------------------------------------------*/\r
331 \r
332 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
333 {\r
334 const char *pcParameter;\r
335 BaseType_t xParameterStringLength, xReturn;\r
336 static BaseType_t lParameterNumber = 0;\r
337 \r
338         /* Remove compile time warnings about unused parameters, and check the\r
339         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
340         write buffer length is adequate, so does not check for buffer overflows. */\r
341         ( void ) pcCommandString;\r
342         ( void ) xWriteBufferLen;\r
343         configASSERT( pcWriteBuffer );\r
344 \r
345         if( lParameterNumber == 0 )\r
346         {\r
347                 /* The first time the function is called after the command has been\r
348                 entered just a header string is returned. */\r
349                 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );\r
350 \r
351                 /* Next time the function is called the first parameter will be echoed\r
352                 back. */\r
353                 lParameterNumber = 1L;\r
354 \r
355                 /* There is more data to be returned as no parameters have been echoed\r
356                 back yet. */\r
357                 xReturn = pdPASS;\r
358         }\r
359         else\r
360         {\r
361                 /* Obtain the parameter string. */\r
362                 pcParameter = FreeRTOS_CLIGetParameter\r
363                                                 (\r
364                                                         pcCommandString,                /* The command string itself. */\r
365                                                         lParameterNumber,               /* Return the next parameter. */\r
366                                                         &xParameterStringLength /* Store the parameter string length. */\r
367                                                 );\r
368 \r
369                 /* Sanity check something was returned. */\r
370                 configASSERT( pcParameter );\r
371 \r
372                 /* Return the parameter string. */\r
373                 memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
374                 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
375                 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
376                 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
377 \r
378                 /* If this is the last of the three parameters then there are no more\r
379                 strings to return after this one. */\r
380                 if( lParameterNumber == 3L )\r
381                 {\r
382                         /* If this is the last of the three parameters then there are no more\r
383                         strings to return after this one. */\r
384                         xReturn = pdFALSE;\r
385                         lParameterNumber = 0L;\r
386                 }\r
387                 else\r
388                 {\r
389                         /* There are more parameters to return after this one. */\r
390                         xReturn = pdTRUE;\r
391                         lParameterNumber++;\r
392                 }\r
393         }\r
394 \r
395         return xReturn;\r
396 }\r
397 /*-----------------------------------------------------------*/\r
398 \r
399 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
400 {\r
401 const char *pcParameter;\r
402 BaseType_t xParameterStringLength, xReturn;\r
403 static BaseType_t lParameterNumber = 0;\r
404 \r
405         /* Remove compile time warnings about unused parameters, and check the\r
406         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
407         write buffer length is adequate, so does not check for buffer overflows. */\r
408         ( void ) pcCommandString;\r
409         ( void ) xWriteBufferLen;\r
410         configASSERT( pcWriteBuffer );\r
411 \r
412         if( lParameterNumber == 0 )\r
413         {\r
414                 /* The first time the function is called after the command has been\r
415                 entered just a header string is returned. */\r
416                 sprintf( pcWriteBuffer, "The parameters were:\r\n" );\r
417 \r
418                 /* Next time the function is called the first parameter will be echoed\r
419                 back. */\r
420                 lParameterNumber = 1L;\r
421 \r
422                 /* There is more data to be returned as no parameters have been echoed\r
423                 back yet. */\r
424                 xReturn = pdPASS;\r
425         }\r
426         else\r
427         {\r
428                 /* Obtain the parameter string. */\r
429                 pcParameter = FreeRTOS_CLIGetParameter\r
430                                                 (\r
431                                                         pcCommandString,                /* The command string itself. */\r
432                                                         lParameterNumber,               /* Return the next parameter. */\r
433                                                         &xParameterStringLength /* Store the parameter string length. */\r
434                                                 );\r
435 \r
436                 if( pcParameter != NULL )\r
437                 {\r
438                         /* Return the parameter string. */\r
439                         memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
440                         sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
441                         strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
442                         strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
443 \r
444                         /* There might be more parameters to return after this one. */\r
445                         xReturn = pdTRUE;\r
446                         lParameterNumber++;\r
447                 }\r
448                 else\r
449                 {\r
450                         /* No more parameters were found.  Make sure the write buffer does\r
451                         not contain a valid string. */\r
452                         pcWriteBuffer[ 0 ] = 0x00;\r
453 \r
454                         /* No more data to return. */\r
455                         xReturn = pdFALSE;\r
456 \r
457                         /* Start over the next time this command is executed. */\r
458                         lParameterNumber = 0;\r
459                 }\r
460         }\r
461 \r
462         return xReturn;\r
463 }\r
464 /*-----------------------------------------------------------*/\r
465 \r
466 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
467 \r
468         static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
469         {\r
470         char * pcParameter;\r
471         BaseType_t lParameterStringLength, xReturn;\r
472         uint32_t ulIPAddress, ulBytesToPing;\r
473         const uint32_t ulDefaultBytesToPing = 8UL;\r
474         char cBuffer[ 16 ];\r
475 \r
476                 /* Remove compile time warnings about unused parameters, and check the\r
477                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
478                 write buffer length is adequate, so does not check for buffer overflows. */\r
479                 ( void ) pcCommandString;\r
480                 ( void ) xWriteBufferLen;\r
481                 configASSERT( pcWriteBuffer );\r
482 \r
483                 /* Start with an empty string. */\r
484                 pcWriteBuffer[ 0 ] = 0x00;\r
485 \r
486                 /* Obtain the number of bytes to ping. */\r
487                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
488                                                                 (\r
489                                                                         pcCommandString,                /* The command string itself. */\r
490                                                                         2,                                              /* Return the second parameter. */\r
491                                                                         &lParameterStringLength /* Store the parameter string length. */\r
492                                                                 );\r
493 \r
494                 if( pcParameter == NULL )\r
495                 {\r
496                         /* The number of bytes was not specified, so default it. */\r
497                         ulBytesToPing = ulDefaultBytesToPing;\r
498                 }\r
499                 else\r
500                 {\r
501                         ulBytesToPing = atol( pcParameter );\r
502                 }\r
503 \r
504                 /* Obtain the IP address string. */\r
505                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
506                                                                 (\r
507                                                                         pcCommandString,                /* The command string itself. */\r
508                                                                         1,                                              /* Return the first parameter. */\r
509                                                                         &lParameterStringLength /* Store the parameter string length. */\r
510                                                                 );\r
511 \r
512                 /* Sanity check something was returned. */\r
513                 configASSERT( pcParameter );\r
514 \r
515                 /* Attempt to obtain the IP address.   If the first character is not a\r
516                 digit, assume the host name has been passed in. */\r
517                 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )\r
518                 {\r
519                         ulIPAddress = FreeRTOS_inet_addr( pcParameter );\r
520                 }\r
521                 else\r
522                 {\r
523                         /* Terminate the host name. */\r
524                         pcParameter[ lParameterStringLength ] = 0x00;\r
525 \r
526                         /* Attempt to resolve host. */\r
527                         ulIPAddress = FreeRTOS_gethostbyname( pcParameter );\r
528                 }\r
529 \r
530                 /* Convert IP address, which may have come from a DNS lookup, to string. */\r
531                 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );\r
532 \r
533                 if( ulIPAddress != 0 )\r
534                 {\r
535                         xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );\r
536                 }\r
537                 else\r
538                 {\r
539                         xReturn = pdFALSE;\r
540                 }\r
541 \r
542                 if( xReturn == pdFALSE )\r
543                 {\r
544                         sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );\r
545                 }\r
546                 else\r
547                 {\r
548                         sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, xReturn );\r
549                 }\r
550 \r
551                 return pdFALSE;\r
552         }\r
553         /*-----------------------------------------------------------*/\r
554 \r
555 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
556 \r
557 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
558 \r
559         static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
560         {\r
561         static BaseType_t xIndex = -1;\r
562         extern xExampleDebugStatEntry_t xIPTraceValues[];\r
563         BaseType_t xReturn;\r
564 \r
565                 /* Remove compile time warnings about unused parameters, and check the\r
566                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
567                 write buffer length is adequate, so does not check for buffer overflows. */\r
568                 ( void ) pcCommandString;\r
569                 ( void ) xWriteBufferLen;\r
570                 configASSERT( pcWriteBuffer );\r
571 \r
572                 xIndex++;\r
573 \r
574                 if( xIndex < xExampleDebugStatEntries() )\r
575                 {\r
576                         sprintf( pcWriteBuffer, "%s %d\r\n", xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );\r
577                         xReturn = pdPASS;\r
578                 }\r
579                 else\r
580                 {\r
581                         /* Reset the index for the next time it is called. */\r
582                         xIndex = -1;\r
583 \r
584                         /* Ensure nothing remains in the write buffer. */\r
585                         pcWriteBuffer[ 0 ] = 0x00;\r
586                         xReturn = pdFALSE;\r
587                 }\r
588 \r
589                 return xReturn;\r
590         }\r
591         /*-----------------------------------------------------------*/\r
592 \r
593 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
594 \r
595 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
596 {\r
597 static BaseType_t xIndex = 0;\r
598 BaseType_t xReturn;\r
599 uint32_t ulAddress;\r
600 \r
601         /* Remove compile time warnings about unused parameters, and check the\r
602         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
603         write buffer length is adequate, so does not check for buffer overflows. */\r
604         ( void ) pcCommandString;\r
605         ( void ) xWriteBufferLen;\r
606         configASSERT( pcWriteBuffer );\r
607 \r
608         switch( xIndex )\r
609         {\r
610                 case 0 :\r
611                         FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );\r
612                         sprintf( pcWriteBuffer, "\r\nIP address " );\r
613                         xReturn = pdTRUE;\r
614                         xIndex++;\r
615                         break;\r
616 \r
617                 case 1 :\r
618                         FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );\r
619                         sprintf( pcWriteBuffer, "\r\nNet mask " );\r
620                         xReturn = pdTRUE;\r
621                         xIndex++;\r
622                         break;\r
623 \r
624                 case 2 :\r
625                         FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );\r
626                         sprintf( pcWriteBuffer, "\r\nGateway address " );\r
627                         xReturn = pdTRUE;\r
628                         xIndex++;\r
629                         break;\r
630 \r
631                 case 3 :\r
632                         FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );\r
633                         sprintf( pcWriteBuffer, "\r\nDNS server address " );\r
634                         xReturn = pdTRUE;\r
635                         xIndex++;\r
636                         break;\r
637 \r
638                 default :\r
639                         ulAddress = 0;\r
640                         sprintf( pcWriteBuffer, "\r\n\r\n" );\r
641                         xReturn = pdFALSE;\r
642                         xIndex = 0;\r
643                         break;\r
644         }\r
645 \r
646         if( ulAddress != 0 )\r
647         {\r
648                 FreeRTOS_inet_ntoa( ulAddress,  &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) );\r
649         }\r
650 \r
651         return xReturn;\r
652 }\r
653 /*-----------------------------------------------------------*/\r
654 \r
655 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
656 \r
657         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
658         {\r
659         const char *pcParameter;\r
660         BaseType_t lParameterStringLength;\r
661 \r
662                 /* Remove compile time warnings about unused parameters, and check the\r
663                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
664                 write buffer length is adequate, so does not check for buffer overflows. */\r
665                 ( void ) pcCommandString;\r
666                 ( void ) xWriteBufferLen;\r
667                 configASSERT( pcWriteBuffer );\r
668 \r
669                 /* Obtain the parameter string. */\r
670                 pcParameter = FreeRTOS_CLIGetParameter\r
671                                                 (\r
672                                                         pcCommandString,                /* The command string itself. */\r
673                                                         1,                                              /* Return the first parameter. */\r
674                                                         &lParameterStringLength /* Store the parameter string length. */\r
675                                                 );\r
676 \r
677                 /* Sanity check something was returned. */\r
678                 configASSERT( pcParameter );\r
679 \r
680                 /* There are only two valid parameter values. */\r
681                 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )\r
682                 {\r
683                         /* Start or restart the trace. */\r
684                         vTraceStop();\r
685                         vTraceClear();\r
686                         vTraceStart();\r
687 \r
688                         sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );\r
689                 }\r
690                 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )\r
691                 {\r
692                         /* End the trace, if one is running. */\r
693                         vTraceStop();\r
694                         sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );\r
695                 }\r
696                 else\r
697                 {\r
698                         sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );\r
699                 }\r
700 \r
701                 /* There is no more data to return after this single string, so return\r
702                 pdFALSE. */\r
703                 return pdFALSE;\r
704         }\r
705 \r
706 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r