2 FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /******************************************************************************
\r
68 * See the following URL for information on the commands defined in this file:
\r
69 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
71 ******************************************************************************/
\r
74 /* FreeRTOS includes. */
\r
75 #include "FreeRTOS.h"
\r
78 /* Standard includes. */
\r
83 /* FreeRTOS+CLI includes. */
\r
84 #include "FreeRTOS_CLI.h"
\r
86 /* FreeRTOS+UDP includes, just to make the stats available to the CLI
\r
88 #include "FreeRTOS_UDP_IP.h"
\r
89 #include "FreeRTOS_Sockets.h"
\r
92 * Defines a command that prints out IP address information.
\r
94 static portBASE_TYPE prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
97 * Defines a command that prints out the gathered demo debug stats.
\r
99 static portBASE_TYPE prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
102 * Defines a command that sends an ICMP ping request to an IP address.
\r
104 static portBASE_TYPE prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
106 /* Structure that defines the "ip-config" command line command. */
\r
107 static const CLI_Command_Definition_t xIPConfig =
\r
110 "ip-config:\r\n Displays IP address configuration\r\n\r\n",
\r
111 prvDisplayIPConfig,
\r
115 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
116 /* Structure that defines the "ip-debug-stats" command line command. */
\r
117 static const CLI_Command_Definition_t xIPDebugStats =
\r
119 "ip-debug-stats", /* The command string to type. */
\r
120 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
\r
121 prvDisplayIPDebugStats, /* The function to run. */
\r
122 0 /* No parameters are expected. */
\r
124 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
126 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
128 /* Structure that defines the "ping" command line command. This takes an IP
\r
129 address or host name and (optionally) the number of bytes to ping as
\r
131 static const CLI_Command_Definition_t xPing =
\r
134 "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
135 prvPingCommand, /* The function to run. */
\r
136 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
\r
139 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
142 /*-----------------------------------------------------------*/
\r
144 void vRegisterUDPCLICommands( void )
\r
146 /* Register all the command line commands defined immediately above. */
\r
147 FreeRTOS_CLIRegisterCommand( &xIPConfig );
\r
149 #if configINCLUDE_DEMO_DEBUG_STATS == 1
\r
151 FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
\r
153 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
155 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
157 FreeRTOS_CLIRegisterCommand( &xPing );
\r
159 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
161 /*-----------------------------------------------------------*/
\r
163 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
165 static portBASE_TYPE prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
167 char * pcParameter;
\r
168 portBASE_TYPE lParameterStringLength, xReturn;
\r
169 uint32_t ulIPAddress, ulBytesToPing;
\r
170 const uint32_t ulDefaultBytesToPing = 8UL;
\r
171 char cBuffer[ 16 ];
\r
173 /* Remove compile time warnings about unused parameters, and check the
\r
174 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
175 write buffer length is adequate, so does not check for buffer overflows. */
\r
176 ( void ) pcCommandString;
\r
177 ( void ) xWriteBufferLen;
\r
178 configASSERT( pcWriteBuffer );
\r
180 /* Start with an empty string. */
\r
181 pcWriteBuffer[ 0 ] = 0x00;
\r
183 /* Obtain the number of bytes to ping. */
\r
184 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
186 pcCommandString, /* The command string itself. */
\r
187 2, /* Return the second parameter. */
\r
188 &lParameterStringLength /* Store the parameter string length. */
\r
191 if( pcParameter == NULL )
\r
193 /* The number of bytes was not specified, so default it. */
\r
194 ulBytesToPing = ulDefaultBytesToPing;
\r
198 ulBytesToPing = atol( pcParameter );
\r
201 /* Obtain the IP address string. */
\r
202 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
204 pcCommandString, /* The command string itself. */
\r
205 1, /* Return the first parameter. */
\r
206 &lParameterStringLength /* Store the parameter string length. */
\r
209 /* Sanity check something was returned. */
\r
210 configASSERT( pcParameter );
\r
212 /* Attempt to obtain the IP address. If the first character is not a
\r
213 digit, assume the host name has been passed in. */
\r
214 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
\r
216 ulIPAddress = FreeRTOS_inet_addr( pcParameter );
\r
220 /* Terminate the host name. */
\r
221 pcParameter[ lParameterStringLength ] = 0x00;
\r
223 /* Attempt to resolve host. */
\r
224 ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
\r
227 /* Convert IP address, which may have come from a DNS lookup, to string. */
\r
228 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
\r
230 if( ulIPAddress != 0 )
\r
232 xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
\r
239 if( xReturn == pdFALSE )
\r
241 sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
\r
245 sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
\r
250 /*-----------------------------------------------------------*/
\r
252 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
254 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
256 static portBASE_TYPE prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
258 static portBASE_TYPE xIndex = -1;
\r
259 extern xExampleDebugStatEntry_t xIPTraceValues[];
\r
260 portBASE_TYPE xReturn;
\r
262 /* Remove compile time warnings about unused parameters, and check the
\r
263 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
264 write buffer length is adequate, so does not check for buffer overflows. */
\r
265 ( void ) pcCommandString;
\r
266 ( void ) xWriteBufferLen;
\r
267 configASSERT( pcWriteBuffer );
\r
271 if( xIndex < xExampleDebugStatEntries() )
\r
273 sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
\r
278 /* Reset the index for the next time it is called. */
\r
281 /* Ensure nothing remains in the write buffer. */
\r
282 pcWriteBuffer[ 0 ] = 0x00;
\r
288 /*-----------------------------------------------------------*/
\r
290 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
292 static portBASE_TYPE prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
294 static portBASE_TYPE xIndex = 0;
\r
295 portBASE_TYPE xReturn;
\r
296 uint32_t ulAddress;
\r
298 /* Remove compile time warnings about unused parameters, and check the
\r
299 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
300 write buffer length is adequate, so does not check for buffer overflows. */
\r
301 ( void ) pcCommandString;
\r
302 ( void ) xWriteBufferLen;
\r
303 configASSERT( pcWriteBuffer );
\r
308 FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
\r
309 sprintf( pcWriteBuffer, "\r\nIP address " );
\r
315 FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
\r
316 sprintf( pcWriteBuffer, "\r\nNet mask " );
\r
322 FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
\r
323 sprintf( pcWriteBuffer, "\r\nGateway address " );
\r
329 FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
\r
330 sprintf( pcWriteBuffer, "\r\nDNS server address " );
\r
337 sprintf( pcWriteBuffer, "\r\n\r\n" );
\r
343 if( ulAddress != 0 )
\r
345 FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
\r
350 /*-----------------------------------------------------------*/
\r