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