+++ /dev/null
-/*\r
- FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
- All rights reserved\r
-\r
- VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
-\r
- ***************************************************************************\r
- >>! NOTE: The modification to the GPL is included to allow you to !<<\r
- >>! distribute a combined work that includes FreeRTOS without being !<<\r
- >>! obliged to provide the source code for proprietary components !<<\r
- >>! outside of the FreeRTOS kernel. !<<\r
- ***************************************************************************\r
-\r
- FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
- FOR A PARTICULAR PURPOSE. Full license text is available on the following\r
- link: http://www.freertos.org/a00114.html\r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS provides completely free yet professionally developed, *\r
- * robust, strictly quality controlled, supported, and cross *\r
- * platform software that is more than just the market leader, it *\r
- * is the industry's de facto standard. *\r
- * *\r
- * Help yourself get started quickly while simultaneously helping *\r
- * to support the FreeRTOS project by purchasing a FreeRTOS *\r
- * tutorial book, reference manual, or both: *\r
- * http://www.FreeRTOS.org/Documentation *\r
- * *\r
- ***************************************************************************\r
-\r
- http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading\r
- the FAQ page "My application does not run, what could be wrong?". Have you\r
- defined configASSERT()?\r
-\r
- http://www.FreeRTOS.org/support - In return for receiving this top quality\r
- embedded software for free we request you assist our global community by\r
- participating in the support forum.\r
-\r
- http://www.FreeRTOS.org/training - Investing in training allows your team to\r
- be as productive as possible as early as possible. Now you can receive\r
- FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
- Ltd, and the world's leading authority on the world's leading RTOS.\r
-\r
- http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
- including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
- compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
-\r
- http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
- Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
-\r
- http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
- Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS\r
- licenses offer ticketed support, indemnification and commercial middleware.\r
-\r
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
- engineered and independently SIL3 certified version for use in safety and\r
- mission critical applications that require provable dependability.\r
-\r
- 1 tab == 4 spaces!\r
-*/\r
-\r
-/* Standard includes. */\r
-#include "stdlib.h"\r
-#include "string.h"\r
-\r
-/* lwIP core includes */\r
-#include "lwip/opt.h"\r
-#include "lwip/sockets.h"\r
-\r
-/* FreeRTOS includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-\r
-/* Utils includes. */\r
-#include "FreeRTOS_CLI.h"\r
-\r
-/* Dimensions the buffer into which input characters are placed. */\r
-#define cmdMAX_INPUT_SIZE 100\r
-\r
-/* Dimensions the buffer into which string outputs can be placed. */\r
-#define cmdMAX_OUTPUT_SIZE 1024\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void vBasicSocketsCommandInterpreterTask( void *pvParameters )\r
-{\r
-long lSocket, lClientFd, lBytes, lAddrLen = sizeof( struct sockaddr_in ), lInputIndex;\r
-struct sockaddr_in sLocalAddr;\r
-struct sockaddr_in client_addr;\r
-const char *pcWelcomeMessage = "FreeRTOS command server - connection accepted.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
-char cInChar;\r
-static char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ];\r
-portBASE_TYPE xReturned;\r
-extern void vRegisterSampleCLICommands( void );\r
-\r
- ( void ) pvParameters;\r
-\r
- /* Register the standard CLI commands. */\r
- vRegisterSampleCLICommands();\r
-\r
- lSocket = lwip_socket(AF_INET, SOCK_STREAM, 0);\r
-\r
- if( lSocket >= 0 )\r
- {\r
- memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));\r
- sLocalAddr.sin_family = AF_INET;\r
- sLocalAddr.sin_len = sizeof(sLocalAddr);\r
- sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);\r
- sLocalAddr.sin_port = ntohs( ( ( unsigned short ) 23 ) );\r
-\r
- if( lwip_bind( lSocket, ( struct sockaddr *) &sLocalAddr, sizeof( sLocalAddr ) ) < 0 )\r
- {\r
- lwip_close( lSocket );\r
- vTaskDelete( NULL );\r
- }\r
-\r
- if( lwip_listen( lSocket, 20 ) != 0 )\r
- {\r
- lwip_close( lSocket );\r
- vTaskDelete( NULL );\r
- }\r
-\r
- for( ;; )\r
- {\r
-\r
- lClientFd = lwip_accept(lSocket, ( struct sockaddr * ) &client_addr, ( u32_t * ) &lAddrLen );\r
-\r
- if( lClientFd > 0L )\r
- {\r
- lwip_send( lClientFd, pcWelcomeMessage, strlen( ( const char * ) pcWelcomeMessage ), 0 );\r
-\r
- lInputIndex = 0;\r
- memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );\r
-\r
- do\r
- {\r
- lBytes = lwip_recv( lClientFd, &cInChar, sizeof( cInChar ), 0 );\r
-\r
- if( lBytes > 0L )\r
- {\r
- if( cInChar == '\n' )\r
- {\r
- /* The input string has been terminated. Was the\r
- input a quit command? */\r
- if( strcmp( "quit", ( const char * ) cInputString ) == 0 )\r
- {\r
- /* Set lBytes to 0 to close the connection. */\r
- lBytes = 0L;\r
- }\r
- else\r
- {\r
- /* The input string was not a quit command.\r
- Pass the string to the command interpreter. */\r
- do\r
- {\r
- /* Get the next output string from the command interpreter. */\r
- xReturned = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_INPUT_SIZE );\r
- lwip_send( lClientFd, cOutputString, strlen( ( const char * ) cOutputString ), 0 );\r
-\r
- } while( xReturned != pdFALSE );\r
-\r
-\r
- /* All the strings generated by the input\r
- command have been sent. Clear the input\r
- string ready to receive the next command. */\r
- lInputIndex = 0;\r
- memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );\r
- lwip_send( lClientFd, "\r\n>", strlen( "\r\n>" ), 0 );\r
- }\r
- }\r
- else\r
- {\r
- if( cInChar == '\r' )\r
- {\r
- /* Ignore the character. */\r
- }\r
- else if( cInChar == '\b' )\r
- {\r
- /* Backspace was pressed. Erase the last\r
- character in the string - if any. */\r
- if( lInputIndex > 0 )\r
- {\r
- lInputIndex--;\r
- cInputString[ lInputIndex ] = '\0';\r
- }\r
- }\r
- else\r
- {\r
- /* A character was entered. Add it to the string\r
- entered so far. When a \n is entered the complete\r
- string will be passed to the command interpreter. */\r
- if( lInputIndex < cmdMAX_INPUT_SIZE )\r
- {\r
- cInputString[ lInputIndex ] = cInChar;\r
- lInputIndex++;\r
- }\r
- }\r
- }\r
- }\r
-\r
- } while( lBytes > 0L );\r
-\r
- lwip_close( lClientFd );\r
- }\r
- }\r
- }\r
-\r
- /* Will only get here if a listening socket could not be created. */\r
- vTaskDelete( NULL );\r
-}\r
-\r