2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
70 /* FreeRTOS includes. */
\r
71 #include "FreeRTOS.h"
\r
74 /* Standard includes. */
\r
79 /* FreeRTOS+CLI includes. */
\r
80 #include "FreeRTOS_CLI.h"
\r
82 /* FreeRTOS+TCP includes, just to make the stats available to the CLI
\r
84 #include "FreeRTOS_IP.h"
\r
85 #include "FreeRTOS_Sockets.h"
\r
88 * Defines a command that prints out IP address information.
\r
90 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
93 * Defines a command that prints out the gathered demo debug stats.
\r
95 #if( configINCLUDE_DEMO_DEBUG_STATS != 0 )
\r
96 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
100 * Defines a command that sends an ICMP ping request to an IP address.
\r
102 #if( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
\r
103 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
107 * Defines a command that calls FreeRTOS_netstat().
\r
109 static BaseType_t prvNetStatCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
111 /* Structure that defines the "ip-config" command line command. */
\r
112 static const CLI_Command_Definition_t xIPConfig =
\r
115 "\r\nip-config:\r\n Displays IP address configuration\r\n",
\r
116 prvDisplayIPConfig,
\r
120 #if( configINCLUDE_DEMO_DEBUG_STATS != 0 )
\r
121 /* Structure that defines the "ip-debug-stats" command line command. */
\r
122 static const CLI_Command_Definition_t xIPDebugStats =
\r
124 "ip-debug-stats", /* The command string to type. */
\r
125 "\r\nip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n",
\r
126 prvDisplayIPDebugStats, /* The function to run. */
\r
127 0 /* No parameters are expected. */
\r
129 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
131 #if( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
\r
133 /* Structure that defines the "ping" command line command. This takes an IP
\r
134 address or host name and (optionally) the number of bytes to ping as
\r
136 static const CLI_Command_Definition_t xPing =
\r
139 "\r\nping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n",
\r
140 prvPingCommand, /* The function to run. */
\r
141 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
\r
144 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
146 /* Structure that defines the "task-stats" command line command. This generates
\r
147 a table that gives information on each task in the system. */
\r
148 static const CLI_Command_Definition_t xNetStats =
\r
150 "net-stats", /* The command string to type. */
\r
151 "\r\nnet-stats:\r\n Calls FreeRTOS_netstat()\r\n",
\r
152 prvNetStatCommand, /* The function to run. */
\r
153 0 /* No parameters are expected. */
\r
156 /*-----------------------------------------------------------*/
\r
158 void vRegisterTCPCLICommands( void )
\r
160 /* Register all the command line commands defined immediately above. */
\r
161 FreeRTOS_CLIRegisterCommand( &xIPConfig );
\r
163 #if( configINCLUDE_DEMO_DEBUG_STATS == 1 )
\r
165 FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
\r
167 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
169 #if( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
\r
171 FreeRTOS_CLIRegisterCommand( &xPing );
\r
173 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
175 FreeRTOS_CLIRegisterCommand( &xNetStats );
\r
177 /*-----------------------------------------------------------*/
\r
179 #if( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
\r
181 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
183 char * pcParameter;
\r
184 BaseType_t lParameterStringLength, xReturn = pdFALSE;
\r
185 uint32_t ulIPAddress, ulBytesToPing;
\r
186 const uint32_t ulDefaultBytesToPing = 8UL;
\r
187 char cBuffer[ 16 ];
\r
189 /* Remove compile time warnings about unused parameters, and check the
\r
190 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
191 write buffer length is adequate, so does not check for buffer overflows. */
\r
192 ( void ) pcCommandString;
\r
193 ( void ) xWriteBufferLen;
\r
194 configASSERT( pcWriteBuffer );
\r
196 /* Start with an empty string. */
\r
197 pcWriteBuffer[ 0 ] = 0x00;
\r
199 /* Obtain the number of bytes to ping. */
\r
200 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
202 pcCommandString, /* The command string itself. */
\r
203 2, /* Return the second parameter. */
\r
204 &lParameterStringLength /* Store the parameter string length. */
\r
207 if( pcParameter == NULL )
\r
209 /* The number of bytes was not specified, so default it. */
\r
210 ulBytesToPing = ulDefaultBytesToPing;
\r
214 ulBytesToPing = atol( pcParameter );
\r
217 /* Obtain the IP address string. */
\r
218 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
220 pcCommandString, /* The command string itself. */
\r
221 1, /* Return the first parameter. */
\r
222 &lParameterStringLength /* Store the parameter string length. */
\r
225 if( pcParameter != NULL )
\r
227 /* Terminate the host name or IP address string. */
\r
228 pcParameter[ lParameterStringLength ] = 0x00;
\r
230 /* Attempt to obtain the IP address. If the first character is not a
\r
231 digit, assume the host name has been passed in. */
\r
232 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
\r
234 ulIPAddress = FreeRTOS_inet_addr( pcParameter );
\r
238 /* Attempt to resolve host. */
\r
239 ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
\r
242 /* Convert IP address, which may have come from a DNS lookup, to string. */
\r
243 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
\r
245 if( ulIPAddress != 0 )
\r
247 xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
\r
251 if( xReturn == pdFALSE )
\r
253 sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
\r
257 sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
\r
262 /*-----------------------------------------------------------*/
\r
264 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
266 #if( configINCLUDE_DEMO_DEBUG_STATS != 0 )
\r
268 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
270 static BaseType_t xIndex = -1;
\r
271 extern ExampleDebugStatEntry_t xIPTraceValues[];
\r
272 BaseType_t xReturn;
\r
274 /* Remove compile time warnings about unused parameters, and check the
\r
275 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
276 write buffer length is adequate, so does not check for buffer overflows. */
\r
277 ( void ) pcCommandString;
\r
278 ( void ) xWriteBufferLen;
\r
279 configASSERT( pcWriteBuffer );
\r
283 if( xIndex < xExampleDebugStatEntries() )
\r
285 sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
\r
290 /* Reset the index for the next time it is called. */
\r
293 /* Ensure nothing remains in the write buffer. */
\r
294 pcWriteBuffer[ 0 ] = 0x00;
\r
300 /*-----------------------------------------------------------*/
\r
302 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
304 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
306 static BaseType_t xIndex = 0;
\r
307 BaseType_t xReturn;
\r
308 uint32_t ulAddress;
\r
310 /* Remove compile time warnings about unused parameters, and check the
\r
311 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
312 write buffer length is adequate, so does not check for buffer overflows. */
\r
313 ( void ) pcCommandString;
\r
314 ( void ) xWriteBufferLen;
\r
315 configASSERT( pcWriteBuffer );
\r
320 FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
\r
321 sprintf( pcWriteBuffer, "\r\nIP address " );
\r
327 FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
\r
328 sprintf( pcWriteBuffer, "\r\nNet mask " );
\r
334 FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
\r
335 sprintf( pcWriteBuffer, "\r\nGateway address " );
\r
341 FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
\r
342 sprintf( pcWriteBuffer, "\r\nDNS server address " );
\r
349 sprintf( pcWriteBuffer, "\r\n\r\n" );
\r
355 if( ulAddress != 0 )
\r
357 FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
\r
362 /*-----------------------------------------------------------*/
\r
364 static BaseType_t prvNetStatCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
366 ( void ) pcWriteBuffer;
\r
367 ( void ) xWriteBufferLen;
\r
368 ( void ) pcCommandString;
\r
370 FreeRTOS_netstat();
\r
371 snprintf( pcWriteBuffer, xWriteBufferLen, "FreeRTOS_netstat() called - output uses FreeRTOS_printf\r\n" );
\r