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