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