Sample-CLI-commands.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * FreeRTOS V202104.00
  3. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */
  27. /******************************************************************************
  28. *
  29. * http://www.FreeRTOS.org/cli
  30. *
  31. ******************************************************************************/
  32. /* FreeRTOS includes. */
  33. #include "FreeRTOS.h"
  34. #include "task.h"
  35. /* Standard includes. */
  36. #include <stdint.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. /* FreeRTOS+CLI includes. */
  41. #include "FreeRTOS_CLI.h"
  42. #include "board.h"
  43. #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
  44. #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
  45. #endif
  46. #ifndef configINCLUDE_QUERY_HEAP_COMMAND
  47. #define configINCLUDE_QUERY_HEAP_COMMAND 0
  48. #endif
  49. /*
  50. * The function that registers the commands that are defined within this file.
  51. */
  52. void vRegisterSampleCLICommands( void );
  53. /*
  54. * Implements the task-stats command.
  55. */
  56. static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  57. /*
  58. * Implements the run-time-stats command.
  59. */
  60. #if( configGENERATE_RUN_TIME_STATS == 1 )
  61. static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  62. #endif /* configGENERATE_RUN_TIME_STATS */
  63. /*
  64. * Implements the echo-three-parameters command.
  65. */
  66. static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  67. /*
  68. * Implements the echo-parameters command.
  69. */
  70. static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  71. #ifdef WIFI_SUPPORT
  72. static BaseType_t prvParameterStartWifiCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  73. static BaseType_t prvParameterPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  74. static BaseType_t prvParameterStartBtcoLogCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  75. static BaseType_t prvParameterStartIwprivCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  76. #endif
  77. static BaseType_t prvParameterIperfCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  78. /*
  79. * Implements the "query heap" command.
  80. */
  81. #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
  82. static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  83. #endif
  84. /*
  85. * Implements the "trace start" and "trace stop" commands;
  86. */
  87. #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
  88. static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
  89. #endif
  90. /* Structure that defines the "task-stats" command line command. This generates
  91. a table that gives information on each task in the system. */
  92. static const CLI_Command_Definition_t xTaskStats =
  93. {
  94. "task-stats", /* The command string to type. */
  95. "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
  96. prvTaskStatsCommand, /* The function to run. */
  97. 0 /* No parameters are expected. */
  98. };
  99. /* Structure that defines the "echo_3_parameters" command line command. This
  100. takes exactly three parameters that the command simply echos back one at a
  101. time. */
  102. static const CLI_Command_Definition_t xThreeParameterEcho =
  103. {
  104. "echo-3-parameters",
  105. "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
  106. prvThreeParameterEchoCommand, /* The function to run. */
  107. 3 /* Three parameters are expected, which can take any value. */
  108. };
  109. /* Structure that defines the "echo_parameters" command line command. This
  110. takes a variable number of parameters that the command simply echos back one at
  111. a time. */
  112. static const CLI_Command_Definition_t xParameterEcho =
  113. {
  114. "echo-parameters",
  115. "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
  116. prvParameterEchoCommand, /* The function to run. */
  117. -1 /* The user can enter any number of commands. */
  118. };
  119. #if( configGENERATE_RUN_TIME_STATS == 1 )
  120. /* Structure that defines the "run-time-stats" command line command. This
  121. generates a table that shows how much run time each task has */
  122. static const CLI_Command_Definition_t xRunTimeStats =
  123. {
  124. "run-time-stats", /* The command string to type. */
  125. "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
  126. prvRunTimeStatsCommand, /* The function to run. */
  127. 0 /* No parameters are expected. */
  128. };
  129. #endif /* configGENERATE_RUN_TIME_STATS */
  130. #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
  131. /* Structure that defines the "query_heap" command line command. */
  132. static const CLI_Command_Definition_t xQueryHeap =
  133. {
  134. "query-heap",
  135. "\r\nquery-heap:\r\n Displays the free heap space, and minimum ever free heap space.\r\n",
  136. prvQueryHeapCommand, /* The function to run. */
  137. 0 /* The user can enter any number of commands. */
  138. };
  139. #endif /* configQUERY_HEAP_COMMAND */
  140. #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
  141. /* Structure that defines the "trace" command line command. This takes a single
  142. parameter, which can be either "start" or "stop". */
  143. static const CLI_Command_Definition_t xStartStopTrace =
  144. {
  145. "trace",
  146. "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
  147. prvStartStopTraceCommand, /* The function to run. */
  148. 1 /* One parameter is expected. Valid values are "start" and "stop". */
  149. };
  150. #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
  151. #ifdef WIFI_SUPPORT
  152. static const CLI_Command_Definition_t xStartWifi =
  153. {
  154. "startwifi",
  155. "\r\nstartwifi [ap | sta]:\r\n Starts AP or STA in FreeRTOS+Trace\r\n",
  156. prvParameterStartWifiCommand, /* The function to run. */
  157. 0 /* One parameter is expected. Valid values are "start" and "stop". */
  158. };
  159. static const CLI_Command_Definition_t xPingCmd =
  160. {
  161. "ping",
  162. "\r\nping [192.168.13.20]:\r\n ping remote device in FreeRTOS+Trace\r\n",
  163. prvParameterPingCommand, /* The function to run. */
  164. 1 /* One parameter is expected. Valid values are "start" and "stop". */
  165. };
  166. static const CLI_Command_Definition_t xStartBtCoLog =
  167. {
  168. "startbtcolog",
  169. "\r\nstartbtcolog:\r\n Starts btco log in FreeRTOS+Trace\r\n",
  170. prvParameterStartBtcoLogCommand, /* The function to run. */
  171. 0 /* One parameter is expected. Valid values are "start" and "stop". */
  172. };
  173. static const CLI_Command_Definition_t xStartIwprivCmd =
  174. {
  175. "iwpriv",
  176. "\r\niwpriv dbg [flow | rx] :\r\n Starts btco log in FreeRTOS+Trace\r\n",
  177. prvParameterStartIwprivCommand, /* The function to run. */
  178. 0
  179. };
  180. #endif
  181. static const CLI_Command_Definition_t xIperfCmd =
  182. {//¡ä?iperf??¨®?¨¤¡ä¡Á?¡¤¨¦¨°¡Á¨ª¡§wifi?¡§?¦Ì2a¨º?
  183. "iperf",
  184. "\r\n iperf [ip] [port]:\r\n Starts iperf client\r\n",
  185. prvParameterIperfCommand, /* The function to run. */
  186. 0 /* One parameter is expected. Valid values are "start" and "stop". */
  187. };
  188. /*-----------------------------------------------------------*/
  189. void vRegisterSampleCLICommands( void )
  190. {
  191. /* Register all the command line commands defined immediately above. */
  192. FreeRTOS_CLIRegisterCommand( &xTaskStats );
  193. FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
  194. FreeRTOS_CLIRegisterCommand( &xParameterEcho );
  195. #if( configGENERATE_RUN_TIME_STATS == 1 )
  196. {
  197. FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
  198. }
  199. #endif
  200. #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
  201. {
  202. FreeRTOS_CLIRegisterCommand( &xQueryHeap );
  203. }
  204. #endif
  205. #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
  206. {
  207. FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
  208. }
  209. #endif
  210. #ifdef WIFI_SUPPORT
  211. FreeRTOS_CLIRegisterCommand( &xStartWifi );
  212. FreeRTOS_CLIRegisterCommand( &xPingCmd );
  213. FreeRTOS_CLIRegisterCommand( &xStartBtCoLog);
  214. FreeRTOS_CLIRegisterCommand( &xStartIwprivCmd);
  215. #endif
  216. FreeRTOS_CLIRegisterCommand( &xIperfCmd);
  217. }
  218. /*-----------------------------------------------------------*/
  219. static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  220. {
  221. const char *const pcHeader = " State Priority Stack #\r\n************************************************\r\n";
  222. BaseType_t xSpacePadding;
  223. /* Remove compile time warnings about unused parameters, and check the
  224. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  225. write buffer length is adequate, so does not check for buffer overflows. */
  226. ( void ) pcCommandString;
  227. ( void ) xWriteBufferLen;
  228. configASSERT( pcWriteBuffer );
  229. /* Generate a table of task stats. */
  230. strcpy( pcWriteBuffer, "Task" );
  231. pcWriteBuffer += strlen( pcWriteBuffer );
  232. /* Minus three for the null terminator and half the number of characters in
  233. "Task" so the column lines up with the centre of the heading. */
  234. configASSERT( configMAX_TASK_NAME_LEN > 3 );
  235. for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
  236. {
  237. /* Add a space to align columns after the task's name. */
  238. *pcWriteBuffer = ' ';
  239. pcWriteBuffer++;
  240. /* Ensure always terminated. */
  241. *pcWriteBuffer = 0x00;
  242. }
  243. strcpy( pcWriteBuffer, pcHeader );
  244. vTaskList( pcWriteBuffer + strlen( pcHeader ) );
  245. /* There is no more data to return after this single string, so return
  246. pdFALSE. */
  247. return pdFALSE;
  248. }
  249. /*-----------------------------------------------------------*/
  250. #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
  251. static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  252. {
  253. /* Remove compile time warnings about unused parameters, and check the
  254. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  255. write buffer length is adequate, so does not check for buffer overflows. */
  256. ( void ) pcCommandString;
  257. ( void ) xWriteBufferLen;
  258. configASSERT( pcWriteBuffer );
  259. sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );
  260. /* There is no more data to return after this single string, so return
  261. pdFALSE. */
  262. return pdFALSE;
  263. }
  264. #endif /* configINCLUDE_QUERY_HEAP */
  265. /*-----------------------------------------------------------*/
  266. #if( configGENERATE_RUN_TIME_STATS == 1 )
  267. static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  268. {
  269. const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
  270. BaseType_t xSpacePadding;
  271. /* Remove compile time warnings about unused parameters, and check the
  272. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  273. write buffer length is adequate, so does not check for buffer overflows. */
  274. ( void ) pcCommandString;
  275. ( void ) xWriteBufferLen;
  276. configASSERT( pcWriteBuffer );
  277. /* Generate a table of task stats. */
  278. strcpy( pcWriteBuffer, "Task" );
  279. pcWriteBuffer += strlen( pcWriteBuffer );
  280. /* Pad the string "task" with however many bytes necessary to make it the
  281. length of a task name. Minus three for the null terminator and half the
  282. number of characters in "Task" so the column lines up with the centre of
  283. the heading. */
  284. for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
  285. {
  286. /* Add a space to align columns after the task's name. */
  287. *pcWriteBuffer = ' ';
  288. pcWriteBuffer++;
  289. /* Ensure always terminated. */
  290. *pcWriteBuffer = 0x00;
  291. }
  292. strcpy( pcWriteBuffer, pcHeader );
  293. vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
  294. /* There is no more data to return after this single string, so return
  295. pdFALSE. */
  296. return pdFALSE;
  297. }
  298. #endif /* configGENERATE_RUN_TIME_STATS */
  299. /*-----------------------------------------------------------*/
  300. static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  301. {
  302. const char *pcParameter;
  303. BaseType_t xParameterStringLength, xReturn;
  304. static UBaseType_t uxParameterNumber = 0;
  305. /* Remove compile time warnings about unused parameters, and check the
  306. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  307. write buffer length is adequate, so does not check for buffer overflows. */
  308. ( void ) pcCommandString;
  309. ( void ) xWriteBufferLen;
  310. configASSERT( pcWriteBuffer );
  311. if( uxParameterNumber == 0 )
  312. {
  313. /* The first time the function is called after the command has been
  314. entered just a header string is returned. */
  315. sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
  316. /* Next time the function is called the first parameter will be echoed
  317. back. */
  318. uxParameterNumber = 1U;
  319. /* There is more data to be returned as no parameters have been echoed
  320. back yet. */
  321. xReturn = pdPASS;
  322. }
  323. else
  324. {
  325. /* Obtain the parameter string. */
  326. pcParameter = FreeRTOS_CLIGetParameter
  327. (
  328. pcCommandString, /* The command string itself. */
  329. uxParameterNumber, /* Return the next parameter. */
  330. &xParameterStringLength /* Store the parameter string length. */
  331. );
  332. /* Sanity check something was returned. */
  333. configASSERT( pcParameter );
  334. /* Return the parameter string. */
  335. memset( pcWriteBuffer, 0x00, xWriteBufferLen );
  336. sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
  337. strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );
  338. strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
  339. /* If this is the last of the three parameters then there are no more
  340. strings to return after this one. */
  341. if( uxParameterNumber == 3U )
  342. {
  343. /* If this is the last of the three parameters then there are no more
  344. strings to return after this one. */
  345. xReturn = pdFALSE;
  346. uxParameterNumber = 0;
  347. }
  348. else
  349. {
  350. /* There are more parameters to return after this one. */
  351. xReturn = pdTRUE;
  352. uxParameterNumber++;
  353. }
  354. }
  355. return xReturn;
  356. }
  357. /*-----------------------------------------------------------*/
  358. static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  359. {
  360. const char *pcParameter;
  361. BaseType_t xParameterStringLength, xReturn;
  362. static UBaseType_t uxParameterNumber = 0;
  363. /* Remove compile time warnings about unused parameters, and check the
  364. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  365. write buffer length is adequate, so does not check for buffer overflows. */
  366. ( void ) pcCommandString;
  367. ( void ) xWriteBufferLen;
  368. configASSERT( pcWriteBuffer );
  369. if( uxParameterNumber == 0 )
  370. {
  371. /* The first time the function is called after the command has been
  372. entered just a header string is returned. */
  373. sprintf( pcWriteBuffer, "The parameters were:\r\n" );
  374. /* Next time the function is called the first parameter will be echoed
  375. back. */
  376. uxParameterNumber = 1U;
  377. /* There is more data to be returned as no parameters have been echoed
  378. back yet. */
  379. xReturn = pdPASS;
  380. }
  381. else
  382. {
  383. /* Obtain the parameter string. */
  384. pcParameter = FreeRTOS_CLIGetParameter
  385. (
  386. pcCommandString, /* The command string itself. */
  387. uxParameterNumber, /* Return the next parameter. */
  388. &xParameterStringLength /* Store the parameter string length. */
  389. );
  390. if( pcParameter != NULL )
  391. {
  392. /* Return the parameter string. */
  393. memset( pcWriteBuffer, 0x00, xWriteBufferLen );
  394. sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
  395. strncat( pcWriteBuffer, ( char * ) pcParameter, ( size_t ) xParameterStringLength );
  396. strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
  397. /* There might be more parameters to return after this one. */
  398. xReturn = pdTRUE;
  399. uxParameterNumber++;
  400. }
  401. else
  402. {
  403. /* No more parameters were found. Make sure the write buffer does
  404. not contain a valid string. */
  405. pcWriteBuffer[ 0 ] = 0x00;
  406. /* No more data to return. */
  407. xReturn = pdFALSE;
  408. /* Start over the next time this command is executed. */
  409. uxParameterNumber = 0;
  410. }
  411. }
  412. return xReturn;
  413. }
  414. /*-----------------------------------------------------------*/
  415. #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
  416. static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  417. {
  418. const char *pcParameter;
  419. BaseType_t lParameterStringLength;
  420. /* Remove compile time warnings about unused parameters, and check the
  421. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  422. write buffer length is adequate, so does not check for buffer overflows. */
  423. ( void ) pcCommandString;
  424. ( void ) xWriteBufferLen;
  425. configASSERT( pcWriteBuffer );
  426. /* Obtain the parameter string. */
  427. pcParameter = FreeRTOS_CLIGetParameter
  428. (
  429. pcCommandString, /* The command string itself. */
  430. 1, /* Return the first parameter. */
  431. &lParameterStringLength /* Store the parameter string length. */
  432. );
  433. /* Sanity check something was returned. */
  434. configASSERT( pcParameter );
  435. /* There are only two valid parameter values. */
  436. if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
  437. {
  438. /* Start or restart the trace. */
  439. vTraceStop();
  440. vTraceClear();
  441. vTraceStart();
  442. sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
  443. }
  444. else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
  445. {
  446. /* End the trace, if one is running. */
  447. vTraceStop();
  448. sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
  449. }
  450. else
  451. {
  452. sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
  453. }
  454. /* There is no more data to return after this single string, so return
  455. pdFALSE. */
  456. return pdFALSE;
  457. }
  458. #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
  459. #ifdef WIFI_SUPPORT
  460. #include "iot_wifi.h"
  461. static BaseType_t prvParameterStartWifiCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  462. {
  463. const char *pcParameter;
  464. BaseType_t lParameterStringLength;
  465. /* Remove compile time warnings about unused parameters, and check the
  466. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  467. write buffer length is adequate, so does not check for buffer overflows. */
  468. ( void ) pcCommandString;
  469. ( void ) xWriteBufferLen;
  470. configASSERT( pcWriteBuffer );
  471. /* Obtain the parameter string. */
  472. pcParameter = FreeRTOS_CLIGetParameter
  473. (
  474. pcCommandString, /* The command string itself. */
  475. 1, /* Return the first parameter. */
  476. &lParameterStringLength /* Store the parameter string length. */
  477. );
  478. /* Sanity check something was returned. */
  479. configASSERT( pcParameter );
  480. /* There are only two valid parameter values. */
  481. if( strncmp( pcParameter, "ap", strlen( "ap" ) ) == 0 )
  482. {
  483. //printf("\r\nstart ap\r\n");
  484. start_ap(36, "ap63011", "88888888", 1);
  485. }
  486. else if( strncmp( pcParameter, "sta", strlen( "sta" ) ) == 0 )
  487. {
  488. int pssid_len = 0, ppwd_len = 0;
  489. char ssid[64] = {0}, passwd[64] = {0};
  490. const char *pssid = FreeRTOS_CLIGetParameter
  491. (
  492. pcCommandString,
  493. 2,
  494. (BaseType_t *)&pssid_len
  495. );
  496. memcpy(ssid, pssid, pssid_len);
  497. const char *ppwd = FreeRTOS_CLIGetParameter
  498. (
  499. pcCommandString,
  500. 3,
  501. (BaseType_t *)&ppwd_len
  502. );
  503. memcpy(passwd, ppwd, ppwd_len);
  504. //printf("\r\nssid:[%s] len:%d passwd:[%s] ppwd_len:%d\r\n", pssid, pssid_len, ppwd, ppwd_len);
  505. start_sta(ssid, passwd, 1);
  506. }
  507. else
  508. {
  509. printf("\r\ninvalid parameters\r\n");
  510. }
  511. /* There is no more data to return after this single string, so return
  512. pdFALSE. */
  513. return pdFALSE;
  514. }
  515. static BaseType_t prvParameterPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  516. {
  517. const char *pcParameter;
  518. BaseType_t lParameterStringLength;
  519. /* Remove compile time warnings about unused parameters, and check the
  520. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  521. write buffer length is adequate, so does not check for buffer overflows. */
  522. ( void ) pcCommandString;
  523. ( void ) xWriteBufferLen;
  524. configASSERT( pcWriteBuffer );
  525. /* Obtain the parameter string. */
  526. pcParameter = FreeRTOS_CLIGetParameter
  527. (
  528. pcCommandString, /* The command string itself. */
  529. 1, /* Return the first parameter. */
  530. &lParameterStringLength /* Store the parameter string length. */
  531. );
  532. /* Sanity check something was returned. */
  533. configASSERT( pcParameter );
  534. start_ping(pcParameter);
  535. /* There is no more data to return after this single string, so return
  536. pdFALSE. */
  537. return pdFALSE;
  538. }
  539. static BaseType_t prvParameterStartBtcoLogCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  540. {
  541. //const char *pcParameter;
  542. //BaseType_t lParameterStringLength;
  543. /* Remove compile time warnings about unused parameters, and check the
  544. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  545. write buffer length is adequate, so does not check for buffer overflows. */
  546. ( void ) pcCommandString;
  547. ( void ) xWriteBufferLen;
  548. configASSERT( pcWriteBuffer );
  549. #if 0
  550. /* Obtain the parameter string. */
  551. pcParameter = FreeRTOS_CLIGetParameter
  552. (
  553. pcCommandString, /* The command string itself. */
  554. 1, /* Return the first parameter. */
  555. &lParameterStringLength /* Store the parameter string length. */
  556. );
  557. /* Sanity check something was returned. */
  558. configASSERT( pcParameter );
  559. #endif
  560. enable_btco_log();
  561. /* There is no more data to return after this single string, so return
  562. pdFALSE. */
  563. return pdFALSE;
  564. }
  565. void cmd_test(const char* temp_uart_buf);//for wifi iwpriv2a¡§o?
  566. static BaseType_t prvParameterStartIwprivCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  567. {
  568. //const char *pcParameter;
  569. //BaseType_t lParameterStringLength;
  570. /* Remove compile time warnings about unused parameters, and check the
  571. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  572. write buffer length is adequate, so does not check for buffer overflows. */
  573. ( void ) pcCommandString;
  574. ( void ) xWriteBufferLen;
  575. configASSERT( pcWriteBuffer );
  576. #if 0
  577. /* Obtain the parameter string. */
  578. pcParameter = FreeRTOS_CLIGetParameter
  579. (
  580. pcCommandString, /* The command string itself. */
  581. 2, /* Return the first parameter. */
  582. &lParameterStringLength /* Store the parameter string length. */
  583. );
  584. /* Sanity check something was returned. */
  585. configASSERT( pcParameter );
  586. #endif
  587. cmd_test(pcCommandString);
  588. sprintf( pcWriteBuffer, "\r\n %s started.\r\n" , pcCommandString);
  589. /* There is no more data to return after this single string, so return
  590. pdFALSE. */
  591. return pdFALSE;
  592. }
  593. #endif
  594. #if !USE_LWIP
  595. void start_iperf_client(const char* ip, int port);
  596. #else
  597. #include "ethernet.h"
  598. #include "tcpip.h"
  599. #include "lwip/apps/lwiperf.h"
  600. static void* iperf_client_handle = NULL;
  601. #define lwip_addr_converter( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \
  602. ( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) | \
  603. ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) | \
  604. ( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) | \
  605. ( ( uint32_t ) ( ucOctet0 ) ) )
  606. static void lwiperf_client_report_cb_impl(void *arg, enum lwiperf_report_type report_type,
  607. const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
  608. u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
  609. {
  610. printf("lwiperf_report_cb_impl bytes:%d %d ms \r\n", bytes_transferred, ms_duration);
  611. }
  612. static void start_iperf_client(const char* ip, short port)
  613. {
  614. ip_addr_t remote_addr;
  615. char addr_buf[4] = {0};
  616. sscanf(ip, "%d.%d.%d.%d", (int*)&addr_buf[0], (int*)&addr_buf[1], (int*)&addr_buf[2], (int*)&addr_buf[3]);
  617. remote_addr.addr = lwip_addr_converter(addr_buf[0], addr_buf[1], addr_buf[2], addr_buf[3]);
  618. iperf_client_handle = lwiperf_start_tcp_client(&remote_addr, (u16_t)port, LWIPERF_CLIENT, lwiperf_client_report_cb_impl, NULL);
  619. }
  620. #endif
  621. static BaseType_t prvParameterIperfCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
  622. {
  623. const char *pcParameter;
  624. BaseType_t lParameterStringLength;
  625. /* Remove compile time warnings about unused parameters, and check the
  626. write buffer is not NULL. NOTE - for simplicity, this example assumes the
  627. write buffer length is adequate, so does not check for buffer overflows. */
  628. ( void ) pcCommandString;
  629. ( void ) xWriteBufferLen;
  630. configASSERT( pcWriteBuffer );
  631. /* Obtain the parameter string. */
  632. pcParameter = FreeRTOS_CLIGetParameter
  633. (
  634. pcCommandString, /* The command string itself. */
  635. 1, /* Return the first parameter. */
  636. &lParameterStringLength /* Store the parameter string length. */
  637. );
  638. /* Sanity check something was returned. */
  639. //configASSERT( pcParameter );
  640. if( strncmp( pcParameter, "client", strlen( "client" ) ) == 0 )
  641. {
  642. printf("\r\n iperf client test start \r\n");
  643. int addr_str_len = 0, port_str_len = 0;
  644. char addr_str[64] = {0}, port_str[64] = {0};
  645. int port = 0;
  646. const char *paddr_str = FreeRTOS_CLIGetParameter
  647. (
  648. pcCommandString,
  649. 2,
  650. (BaseType_t *)&addr_str_len
  651. );
  652. memcpy(addr_str, paddr_str, addr_str_len);
  653. const char *pport_str = FreeRTOS_CLIGetParameter
  654. (
  655. pcCommandString,
  656. 3,
  657. (BaseType_t *)&port_str_len
  658. );
  659. memcpy(port_str, pport_str, port_str_len);
  660. port = atoi(port_str);
  661. printf("\r\n addr:[%s] len:%d port str:[%s] port len:%d port:%d\r\n", addr_str, addr_str_len, port_str, port_str_len, port);
  662. start_iperf_client(addr_str, port);
  663. printf("\r\n iperf client test end\r\n");
  664. }
  665. else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
  666. {
  667. #if USE_LWIP
  668. if (iperf_client_handle)
  669. lwiperf_abort(iperf_client_handle);
  670. #endif
  671. }
  672. else
  673. {
  674. printf("\r\ninvalid parameters\r\n");
  675. }
  676. /* There is no more data to return after this single string, so return
  677. pdFALSE. */
  678. return pdFALSE;
  679. }