2 FreeRTOS V9.0.0rc1 - 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 /******************************************************************************
\r
72 * See the following URL for information on the commands defined in this file:
\r
73 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
75 ******************************************************************************/
\r
78 /* FreeRTOS includes. */
\r
79 #include "FreeRTOS.h"
\r
82 /* Standard includes. */
\r
87 /* FreeRTOS+CLI includes. */
\r
88 #include "FreeRTOS_CLI.h"
\r
90 /* FreeRTOS+UDP includes, just to make the stats available to the CLI
\r
92 #include "FreeRTOS_UDP_IP.h"
\r
93 #include "FreeRTOS_Sockets.h"
\r
96 * Defines a command that prints out IP address information.
\r
98 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
101 * Defines a command that prints out the gathered demo debug stats.
\r
103 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
106 * Defines a command that sends an ICMP ping request to an IP address.
\r
108 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
110 /* Structure that defines the "ip-config" command line command. */
\r
111 static const CLI_Command_Definition_t xIPConfig =
\r
114 "ip-config:\r\n Displays IP address configuration\r\n\r\n",
\r
115 prvDisplayIPConfig,
\r
119 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
120 /* Structure that defines the "ip-debug-stats" command line command. */
\r
121 static const CLI_Command_Definition_t xIPDebugStats =
\r
123 "ip-debug-stats", /* The command string to type. */
\r
124 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
\r
125 prvDisplayIPDebugStats, /* The function to run. */
\r
126 0 /* No parameters are expected. */
\r
128 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
130 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
132 /* Structure that defines the "ping" command line command. This takes an IP
\r
133 address or host name and (optionally) the number of bytes to ping as
\r
135 static const CLI_Command_Definition_t xPing =
\r
138 "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
139 prvPingCommand, /* The function to run. */
\r
140 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
\r
143 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
146 /*-----------------------------------------------------------*/
\r
148 void vRegisterUDPCLICommands( void )
\r
150 /* Register all the command line commands defined immediately above. */
\r
151 FreeRTOS_CLIRegisterCommand( &xIPConfig );
\r
153 #if configINCLUDE_DEMO_DEBUG_STATS == 1
\r
155 FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
\r
157 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
159 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
161 FreeRTOS_CLIRegisterCommand( &xPing );
\r
163 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
165 /*-----------------------------------------------------------*/
\r
167 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
169 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
171 char * pcParameter;
\r
172 BaseType_t lParameterStringLength, xReturn;
\r
173 uint32_t ulIPAddress, ulBytesToPing;
\r
174 const uint32_t ulDefaultBytesToPing = 8UL;
\r
175 char cBuffer[ 16 ];
\r
177 /* Remove compile time warnings about unused parameters, and check the
\r
178 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
179 write buffer length is adequate, so does not check for buffer overflows. */
\r
180 ( void ) pcCommandString;
\r
181 ( void ) xWriteBufferLen;
\r
182 configASSERT( pcWriteBuffer );
\r
184 /* Start with an empty string. */
\r
185 pcWriteBuffer[ 0 ] = 0x00;
\r
187 /* Obtain the number of bytes to ping. */
\r
188 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
190 pcCommandString, /* The command string itself. */
\r
191 2, /* Return the second parameter. */
\r
192 &lParameterStringLength /* Store the parameter string length. */
\r
195 if( pcParameter == NULL )
\r
197 /* The number of bytes was not specified, so default it. */
\r
198 ulBytesToPing = ulDefaultBytesToPing;
\r
202 ulBytesToPing = atol( pcParameter );
\r
205 /* Obtain the IP address string. */
\r
206 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
208 pcCommandString, /* The command string itself. */
\r
209 1, /* Return the first parameter. */
\r
210 &lParameterStringLength /* Store the parameter string length. */
\r
213 /* Sanity check something was returned. */
\r
214 configASSERT( pcParameter );
\r
216 /* Attempt to obtain the IP address. If the first character is not a
\r
217 digit, assume the host name has been passed in. */
\r
218 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
\r
220 ulIPAddress = FreeRTOS_inet_addr( pcParameter );
\r
224 /* Terminate the host name. */
\r
225 pcParameter[ lParameterStringLength ] = 0x00;
\r
227 /* Attempt to resolve host. */
\r
228 ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
\r
231 /* Convert IP address, which may have come from a DNS lookup, to string. */
\r
232 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
\r
234 if( ulIPAddress != 0 )
\r
236 xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
\r
243 if( xReturn == pdFALSE )
\r
245 sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
\r
249 sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
\r
254 /*-----------------------------------------------------------*/
\r
256 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
258 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
260 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
262 static BaseType_t xIndex = -1;
\r
263 extern xExampleDebugStatEntry_t xIPTraceValues[];
\r
264 BaseType_t xReturn;
\r
266 /* Remove compile time warnings about unused parameters, and check the
\r
267 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
268 write buffer length is adequate, so does not check for buffer overflows. */
\r
269 ( void ) pcCommandString;
\r
270 ( void ) xWriteBufferLen;
\r
271 configASSERT( pcWriteBuffer );
\r
275 if( xIndex < xExampleDebugStatEntries() )
\r
277 sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
\r
282 /* Reset the index for the next time it is called. */
\r
285 /* Ensure nothing remains in the write buffer. */
\r
286 pcWriteBuffer[ 0 ] = 0x00;
\r
292 /*-----------------------------------------------------------*/
\r
294 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
296 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
298 static BaseType_t xIndex = 0;
\r
299 BaseType_t xReturn;
\r
300 uint32_t ulAddress;
\r
302 /* Remove compile time warnings about unused parameters, and check the
\r
303 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
304 write buffer length is adequate, so does not check for buffer overflows. */
\r
305 ( void ) pcCommandString;
\r
306 ( void ) xWriteBufferLen;
\r
307 configASSERT( pcWriteBuffer );
\r
312 FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
\r
313 sprintf( pcWriteBuffer, "\r\nIP address " );
\r
319 FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
\r
320 sprintf( pcWriteBuffer, "\r\nNet mask " );
\r
326 FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
\r
327 sprintf( pcWriteBuffer, "\r\nGateway address " );
\r
333 FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
\r
334 sprintf( pcWriteBuffer, "\r\nDNS server address " );
\r
341 sprintf( pcWriteBuffer, "\r\n\r\n" );
\r
347 if( ulAddress != 0 )
\r
349 FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
\r
354 /*-----------------------------------------------------------*/
\r