cli.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. #include "cli.h"
  2. extern void *cli_cmd$$Base;
  3. extern void *cli_cmd$$Limit;
  4. void cli_write(cli_t *p_cli)
  5. {
  6. for (int i = 0; i < p_cli->chartemplen; i++)
  7. p_cli->char_put(p_cli->tempbuf[i]);
  8. }
  9. int ringbufcmp(unsigned char *ringbuf, unsigned char ringbufis, const char *cr, int len)
  10. {
  11. unsigned char i = ringbufis;
  12. for (int j = 0; j < len; j++)
  13. {
  14. if (ringbuf[i] != cr[j])
  15. return 1;
  16. i++;
  17. }
  18. return 0;
  19. }
  20. /**
  21. * @brief CLI colors for @ref nrf_cli_fprintf function.
  22. */
  23. #define NRF_CLI_DEFAULT NRF_CLI_VT100_COLOR_DEFAULT /**< Turn off character attributes. */
  24. #define NRF_CLI_NORMAL NRF_CLI_VT100_COLOR_WHITE /**< Normal color printf. */
  25. #define NRF_CLI_INFO NRF_CLI_VT100_COLOR_GREEN /**< Info color printf. */
  26. #define NRF_CLI_OPTION NRF_CLI_VT100_COLOR_CYAN /**< Option color printf. */
  27. #define NRF_CLI_WARNING NRF_CLI_VT100_COLOR_YELLOW /**< Warning color printf. */
  28. #define NRF_CLI_ERROR NRF_CLI_VT100_COLOR_RED /**< Error color printf. */
  29. static void vt100_color_set(cli_t *p_cli, nrf_cli_vt100_color_t color)
  30. {
  31. if (p_cli->col.col == color)
  32. {
  33. return;
  34. }
  35. p_cli->col.col = color;
  36. cli_printf(p_cli, "\033[3%dm", color); //设置颜色
  37. }
  38. static void vt100_bgcolor_set(cli_t *p_cli, nrf_cli_vt100_color_t bgcolor)
  39. {
  40. if (p_cli->col.bgcol == bgcolor)
  41. {
  42. return;
  43. }
  44. p_cli->col.bgcol = bgcolor;
  45. cli_printf(p_cli, "\033[4%dm", bgcolor); //设置颜色
  46. }
  47. static inline void vt100_colors_store(cli_t *p_cli,
  48. nrf_cli_vt100_colors_t *p_color)
  49. {
  50. memcpy(p_color, &p_cli->col, sizeof(nrf_cli_vt100_colors_t));
  51. }
  52. static void vt100_colors_restore(cli_t *p_cli,
  53. nrf_cli_vt100_colors_t const *p_color)
  54. {
  55. vt100_color_set(p_cli, p_color->col);
  56. vt100_bgcolor_set(p_cli, p_color->bgcol);
  57. }
  58. #define print_name cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_GREEN, "\033[1m \r%s", p_cli->p_name)
  59. void Tab_pcs(cli_t *p_cli)
  60. {
  61. int temp = 0;
  62. cli_section_cmd_t *stmy;
  63. if (p_cli->cmdwp == p_cli->cmdrp)
  64. {
  65. cli_printf(p_cli, "\n\r\t");
  66. for (int p = (unsigned int)&cli_cmd$$Base; p < (unsigned int)&cli_cmd$$Limit; p += sizeof(cli_section_cmd_t))
  67. {
  68. stmy = ((cli_section_cmd_t *)p);
  69. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "%s\t", stmy->_p_cmd_str);
  70. temp++;
  71. if (temp % 5 == 0)
  72. cli_printf(p_cli, "\n\r\t");
  73. }
  74. cli_printf(p_cli, "\n");
  75. print_name;
  76. }
  77. else
  78. {
  79. for (int p = (unsigned int)&cli_cmd$$Base; p < (unsigned int)&cli_cmd$$Limit; p += sizeof(cli_section_cmd_t))
  80. {
  81. stmy = ((cli_section_cmd_t *)p);
  82. if (ringbufcmp(p_cli->cmdbuf, p_cli->cmdrp, stmy->_p_cmd_str, p_cli->cmdwp - p_cli->cmdrp) == 0)
  83. {
  84. for (int i = p_cli->cmdwp - p_cli->cmdrp; i < strlen(stmy->_p_cmd_str); i++)
  85. p_cli->cmdbuf[p_cli->cmdwp++] = stmy->_p_cmd_str[i];
  86. cli_printf(p_cli, "\n\r");
  87. print_name;
  88. cli_printf(p_cli, "%s", stmy->_p_cmd_str);
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. void Backspace_pcs(cli_t *p_cli)
  95. {
  96. if (p_cli->cmdwp != p_cli->cmdrp)
  97. {
  98. NRF_CLI_VT100_CMD(p_cli, NRF_CLI_VT100_CLEAREOL); //清除光标后面的内容
  99. p_cli->cmdwp--;
  100. }
  101. else
  102. {
  103. cli_printf(p_cli, "\033[1C"); //光标右移动
  104. }
  105. }
  106. void Delete_pcs(cli_t *p_cli)
  107. {
  108. }
  109. #define Historyshowlen 50
  110. void Up_pcs(cli_t *p_cli)
  111. {
  112. unsigned char showH_p = 0;
  113. unsigned char fir = 1;
  114. nrf_cli_vt100_colors_t col;
  115. if (p_cli->cmdbuf[(unsigned char)(p_cli->historyrp - 1)] != '*')
  116. return;
  117. if (p_cli->historyrp != p_cli->cmdwp)
  118. {
  119. p_cli->cmdwp = p_cli->cmdrp;
  120. cli_printf(p_cli, "\r");
  121. print_name;
  122. cli_printf(p_cli, "\033[K");
  123. }
  124. for (unsigned char i = (unsigned char)p_cli->historyrp - 2; i != (unsigned char)(p_cli->historyrp - Historyshowlen); i--)
  125. {
  126. if (p_cli->cmdbuf[i] == '*')
  127. {
  128. if (fir)
  129. {
  130. for (int j = 0; j < showH_p; j++)
  131. {
  132. p_cli->char_put(p_cli->cmdbuf[(unsigned char)(i + j + 1)]);
  133. p_cli->cmdbuf[p_cli->cmdwp++] = p_cli->cmdbuf[(unsigned char)(i + j + 1)];
  134. }
  135. cli_printf(p_cli, "\033[s");
  136. p_cli->char_put(' ');
  137. p_cli->historyrp = i + 1;
  138. fir = 0;
  139. vt100_colors_store(p_cli, &col);
  140. vt100_color_set(p_cli, NRF_CLI_VT100_COLOR_CYAN);
  141. p_cli->char_put('[');
  142. }
  143. else
  144. {
  145. for (int j = 0; j < showH_p; j++)
  146. p_cli->char_put(p_cli->cmdbuf[(unsigned char)(i + j + 1)]);
  147. p_cli->char_put(' ');
  148. }
  149. showH_p = 0;
  150. }
  151. else
  152. showH_p++;
  153. if ((p_cli->cmdbuf[i] == 0) || (i == p_cli->cmdwp))
  154. break;
  155. }
  156. if (fir == 0)
  157. {
  158. p_cli->char_put(']');
  159. vt100_colors_restore(p_cli, &col);
  160. cli_printf(p_cli, "\033[u");
  161. }
  162. }
  163. void Down_pcs(cli_t *p_cli)
  164. {
  165. for (unsigned char j = 0; j < p_cli->cmdwp; j++)
  166. p_cli->char_put(p_cli->cmdbuf[j]);
  167. }
  168. void Left_pcs(cli_t *p_cli)
  169. {
  170. cli_printf(p_cli, "\033[1D");
  171. }
  172. void Right_pcs(cli_t *p_cli)
  173. {
  174. cli_printf(p_cli, "\033[1C");
  175. }
  176. #define ARGVCUNMAX 25
  177. char *cmd_argv[ARGVCUNMAX]; //最多存放25个参数的指针
  178. void cmd_pcs(cli_t *p_cli)
  179. {
  180. cli_section_cmd_t *stmy;
  181. int stmy_len = 0;
  182. char sgv_tag = 0;
  183. unsigned short agvc = 0;
  184. char argvtrg = 0;
  185. for (int p = (unsigned int)&cli_cmd$$Base; p < (unsigned int)&cli_cmd$$Limit; p += sizeof(cli_section_cmd_t))
  186. {
  187. stmy = ((cli_section_cmd_t *)p);
  188. stmy_len = strlen(stmy->_p_cmd_str);
  189. if (
  190. ((unsigned char)stmy_len == (unsigned char)(p_cli->cmdwp - p_cli->cmdrp))||
  191. (((unsigned char)stmy_len < (unsigned char)(p_cli->cmdwp - p_cli->cmdrp))&&(p_cli->cmdbuf[(unsigned char)(p_cli->cmdrp + stmy_len)] == ' '))
  192. )
  193. {
  194. if (ringbufcmp(p_cli->cmdbuf, p_cli->cmdrp, stmy->_p_cmd_str, stmy_len) == 0)
  195. {
  196. cli_printf(p_cli, "\r\n");
  197. if ((unsigned char)stmy_len == (unsigned char)(p_cli->cmdwp - p_cli->cmdrp))
  198. {
  199. (*(cli_cmd_t *)(&(stmy->_p_cmd_hander)))(p_cli, 0, NULL); //调用没参数的命令
  200. }
  201. else
  202. {
  203. agvc = 0;
  204. p_cli->cmdbuf[p_cli->cmdwp++] = ' ';
  205. //找出所有参数的指针
  206. for (unsigned char i = (unsigned char)(p_cli->cmdrp + stmy_len); (unsigned char)i != p_cli->cmdwp; i++)
  207. {
  208. switch (sgv_tag)
  209. {
  210. case 0:
  211. if (p_cli->cmdbuf[i] != ' ')
  212. {
  213. cmd_argv[agvc++] = (char *)(&(p_cli->cmdbuf[i]));
  214. sgv_tag++;
  215. }
  216. break;
  217. default:
  218. if (p_cli->cmdbuf[i] == ' ')
  219. {
  220. p_cli->cmdbuf[i] = 0;
  221. sgv_tag = 0;
  222. }
  223. else if ((i == 255) && (p_cli->cmdbuf[0] != ' ')) //参数不连续
  224. {
  225. argvtrg = 1;
  226. }
  227. break;
  228. }
  229. }
  230. if (argvtrg == 0) //没有出现参数不连续的情况
  231. {
  232. //调用命令,带参数
  233. (*(cli_cmd_t *)(&(stmy->_p_cmd_hander)))(p_cli, agvc, cmd_argv);
  234. }
  235. else
  236. {
  237. cli_fprintf(p_cli, NRF_CLI_ERROR, "\tPlase try once again! ");
  238. }
  239. if(agvc>0)p_cli->cmdwp = (unsigned char)((unsigned int)(&cmd_argv[agvc - 1][strlen(cmd_argv[agvc - 1])]) - (unsigned int)&p_cli->cmdbuf[0]);
  240. for (int i = 0; i < agvc; i++)
  241. {
  242. cmd_argv[i][strlen(cmd_argv[i])] = ' ';
  243. }
  244. }
  245. cli_printf(p_cli, "\n");
  246. print_name;
  247. p_cli->cmdbuf[p_cli->cmdwp++] = '*';
  248. for(unsigned char i=p_cli->cmdwp-1;i>p_cli->cmdrp-1;i--)
  249. {
  250. if(p_cli->cmdbuf[i]!= p_cli->cmdbuf[(unsigned char)(i-(p_cli->cmdwp-p_cli->cmdrp))])
  251. {
  252. //添加到运行历史
  253. p_cli->cmdrp = p_cli->cmdwp;
  254. return ;
  255. }
  256. }
  257. p_cli->cmdwp = p_cli->cmdrp;
  258. return;
  259. }
  260. }
  261. }
  262. p_cli->cmdbuf[p_cli->cmdwp] = 0;
  263. cli_fprintf(p_cli, NRF_CLI_ERROR, "\tCan not find cmd [");
  264. for (unsigned char i = p_cli->cmdrp; i != p_cli->cmdwp; i++)
  265. p_cli->char_put(p_cli->cmdbuf[i]);
  266. cli_fprintf(p_cli, NRF_CLI_ERROR, "]\n");
  267. print_name;
  268. p_cli->cmdwp = p_cli->cmdrp;
  269. }
  270. void Enter_pcs(cli_t *p_cli)
  271. {
  272. if (p_cli->cmdwp == p_cli->cmdrp)
  273. {
  274. print_name;
  275. }
  276. else
  277. {
  278. cmd_pcs(p_cli);
  279. }
  280. p_cli->historyrp = p_cli->cmdwp;
  281. }
  282. void F4_pcs(cli_t *p_cli)
  283. {
  284. NRF_CLI_VT100_CMD(p_cli, NRF_CLI_VT100_CURSORHOME);
  285. NRF_CLI_VT100_CMD(p_cli, NRF_CLI_VT100_CLEARSCREEN);
  286. print_name;
  287. }
  288. void F5_pcs(cli_t *p_cli)
  289. {
  290. Up_pcs(p_cli);
  291. cli_printf(p_cli, "\r\n");
  292. Enter_pcs(p_cli);
  293. }
  294. void cli_process(cli_t *p_cli)
  295. {
  296. static unsigned char FN = 0;
  297. unsigned char key = 0;
  298. if (p_cli->char_ok())
  299. {
  300. key = p_cli->char_get();
  301. switch (key)
  302. {
  303. #if 1
  304. case 0x08: //Backspace
  305. Backspace_pcs(p_cli);
  306. break;
  307. case 0x09: //Tab
  308. Tab_pcs(p_cli);
  309. break;
  310. case 0x0d:
  311. FN = 20;
  312. break;
  313. case 0x0a: //Enter
  314. if (FN == 20)
  315. {
  316. Enter_pcs(p_cli);
  317. FN = 0;
  318. }
  319. break;
  320. case 0x1B: //Esc
  321. FN = 1;
  322. break;
  323. case 'A':
  324. if (FN == 1)
  325. {
  326. Up_pcs(p_cli);
  327. FN = 0;
  328. }
  329. else
  330. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  331. break;
  332. case 'B':
  333. if (FN == 1)
  334. {
  335. Down_pcs(p_cli);
  336. FN = 0;
  337. }
  338. else
  339. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  340. break;
  341. case 'C':
  342. if (FN == 1)
  343. {
  344. Right_pcs(p_cli);
  345. FN = 0;
  346. }
  347. else
  348. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  349. break;
  350. case 'D':
  351. if (FN == 1)
  352. {
  353. Left_pcs(p_cli);
  354. FN = 0;
  355. }
  356. else
  357. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  358. break;
  359. case 'O': //
  360. if (FN == 1)
  361. FN = 2;
  362. else
  363. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  364. break;
  365. case 'P':
  366. if (FN == 2)
  367. {
  368. FN = 0;
  369. p_cli->char_put('F');
  370. p_cli->char_put('1');
  371. }
  372. else
  373. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  374. break;
  375. case 'Q':
  376. if (FN == 2)
  377. {
  378. FN = 0;
  379. p_cli->char_put('F');
  380. p_cli->char_put('2');
  381. }
  382. else
  383. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  384. break;
  385. case 'R':
  386. if (FN == 2)
  387. {
  388. FN = 0;
  389. p_cli->char_put('F');
  390. p_cli->char_put('3');
  391. }
  392. else
  393. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  394. break;
  395. case 'S':
  396. if (FN == 2)
  397. {
  398. FN = 0;
  399. F4_pcs(p_cli); //F4按钮
  400. }
  401. else
  402. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  403. break;
  404. case '[':
  405. FN = 1;
  406. break;
  407. case '0':
  408. if (FN == 2)
  409. FN = 9;
  410. else
  411. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  412. break;
  413. case '1':
  414. if (FN == 2)
  415. FN = 10;
  416. else if (FN == 1)
  417. FN = 2;
  418. else
  419. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  420. break;
  421. case '2':
  422. if (FN == 1)
  423. FN = 2;
  424. else
  425. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  426. break;
  427. case '3':
  428. if (FN == 2)
  429. FN = 11;
  430. else
  431. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  432. break;
  433. case '4':
  434. if (FN == 2)
  435. FN = 12;
  436. else
  437. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  438. break;
  439. case '5':
  440. if (FN == 2)
  441. {
  442. FN = 5;
  443. }
  444. else
  445. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  446. break;
  447. case '7':
  448. if (FN == 2)
  449. {
  450. FN = 6;
  451. }
  452. else
  453. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  454. break;
  455. case '8':
  456. if (FN == 2)
  457. {
  458. FN = 7;
  459. }
  460. else
  461. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  462. break;
  463. case '9':
  464. if (FN == 2)
  465. {
  466. FN = 8;
  467. }
  468. else
  469. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  470. break;
  471. case '~':
  472. switch (FN)
  473. {
  474. case 5:
  475. F5_pcs(p_cli);
  476. break;
  477. case 6:
  478. p_cli->char_put('F');
  479. p_cli->char_put('6');
  480. FN = 0;
  481. break;
  482. case 7:
  483. p_cli->char_put('F');
  484. p_cli->char_put('7');
  485. FN = 0;
  486. break;
  487. case 8:
  488. p_cli->char_put('F');
  489. p_cli->char_put('8');
  490. FN = 0;
  491. break;
  492. case 9:
  493. p_cli->char_put('F');
  494. p_cli->char_put('9');
  495. FN = 0;
  496. break;
  497. case 10:
  498. p_cli->char_put('F');
  499. p_cli->char_put('1');
  500. p_cli->char_put('0');
  501. FN = 0;
  502. break;
  503. case 11:
  504. p_cli->char_put('F');
  505. p_cli->char_put('1');
  506. p_cli->char_put('1');
  507. FN = 0;
  508. break;
  509. case 12:
  510. p_cli->char_put('F');
  511. p_cli->char_put('1');
  512. p_cli->char_put('2');
  513. FN = 0;
  514. break;
  515. default:
  516. SEGGER_RTT_Write(0, &key, 1);
  517. break;
  518. }
  519. break;
  520. case 0x7f: //Delete
  521. Delete_pcs(p_cli);
  522. break;
  523. #endif
  524. default:
  525. p_cli->cmdbuf[p_cli->cmdwp++] = key;
  526. break;
  527. }
  528. }
  529. extern void recall_cmd_pcs(cli_t *p_cli);
  530. recall_cmd_pcs(p_cli);
  531. }
  532. void cli_exe_cmd(cli_t *p_cli,char *cmd)
  533. {
  534. int len =strlen(cmd);
  535. if(len>128)return;
  536. for(unsigned char i= 0;i<len;i++)
  537. {
  538. p_cli->cmdbuf[p_cli->cmdwp++]=cmd[i];
  539. }
  540. Enter_pcs(p_cli);
  541. }
  542. void clc_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  543. {
  544. NRF_CLI_VT100_CMD(p_cli, NRF_CLI_VT100_CURSORHOME);
  545. NRF_CLI_VT100_CMD(p_cli, NRF_CLI_VT100_CLEARSCREEN);
  546. }
  547. CLI_CMD_REGISTER(clc, "clear sereen", clc_pcs);
  548. CLI_CMD_REGISTER(clear, "clear sereen", clc_pcs);
  549. void History_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  550. {
  551. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "[1]History");
  552. }
  553. CLI_CMD_REGISTER(history, "Cli cmd history", History_pcs);
  554. void print_param_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  555. {
  556. for (int i = 0; i < argc; i++)
  557. {
  558. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "%s\r\n", argv[i]);
  559. }
  560. }
  561. CLI_CMD_REGISTER(print_param, "Cli cmd history", print_param_pcs);
  562. #define RECALL_CMD_LEN_MAX 30
  563. unsigned char recall_cmd_buff[RECALL_CMD_LEN_MAX];
  564. static int recall_cmd_buff_len=0;
  565. static unsigned int recall_cmd_pcs_interval = 0;
  566. static int recall_cmd_times = 0;
  567. static char allcall=0;
  568. void recall_cmd_pcs(cli_t *p_cli)
  569. {
  570. static unsigned int cun = 0;
  571. if ((recall_cmd_times > 0)||(allcall))
  572. {
  573. if (cun >= recall_cmd_pcs_interval)
  574. {
  575. cun = 0;
  576. for(int i=0;i<recall_cmd_buff_len;i++)
  577. {
  578. p_cli->cmdbuf[p_cli->cmdwp++]=recall_cmd_buff[i];
  579. }
  580. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "recall times %d ...\r\n",recall_cmd_times);
  581. Enter_pcs(p_cli);
  582. if(!allcall)recall_cmd_times--;
  583. }
  584. cun++;
  585. }
  586. }
  587. void recall_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  588. {
  589. if (argc == 0)
  590. {
  591. recall_cmd_times = 0;
  592. allcall=0;
  593. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "help: recall interval times cmd ...");
  594. }
  595. else if (argc >= 3)
  596. {
  597. recall_cmd_pcs_interval = atoi(argv[0]);
  598. recall_cmd_times = atoi(argv[1]);
  599. if((recall_cmd_times==0)||(recall_cmd_pcs_interval==0))
  600. {
  601. if((recall_cmd_times==0)&&(recall_cmd_pcs_interval!=0)&&(argv[1][0]=='*'))
  602. {
  603. allcall=1;
  604. }
  605. else
  606. {
  607. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "help: recall interval times cmd ...\r\n");
  608. cli_fprintf(p_cli, NRF_CLI_VT100_COLOR_CYAN, "interval and times is a number\r\n");
  609. return ;
  610. }
  611. }
  612. recall_cmd_buff_len=0;
  613. for (int i = 2; i < argc; i++)
  614. {
  615. memcpy(&recall_cmd_buff[recall_cmd_buff_len],argv[i],strlen(argv[i]));
  616. recall_cmd_buff_len+=strlen(argv[i]);
  617. recall_cmd_buff[recall_cmd_buff_len++]=' ';
  618. }
  619. cli_printf(p_cli, "recall [ ");
  620. for(int i=0;i<recall_cmd_buff_len;i++)
  621. {
  622. p_cli->char_put(recall_cmd_buff[i]);
  623. }
  624. if(allcall){cli_printf(p_cli, " ] interval =%d times= **** success\r\n",recall_cmd_pcs_interval);
  625. }else {cli_printf(p_cli, " ] interval =%d times= %d success\r\n",recall_cmd_pcs_interval,recall_cmd_times);
  626. }SEGGER_RTT_Write(0,recall_cmd_buff,recall_cmd_buff_len);
  627. }
  628. else
  629. {
  630. cli_printf(p_cli, "recall_pcs -> param err");
  631. }
  632. }
  633. CLI_CMD_REGISTER(recall, "Cli cmd history", recall_pcs);
  634. char rttok(void)
  635. {
  636. if (SEGGER_RTT_HasKey())
  637. return 1;
  638. return 0;
  639. }
  640. unsigned char rttget(void)
  641. {
  642. unsigned char buf[60];
  643. SEGGER_RTT_Read(0, buf, 60);
  644. return buf[0];
  645. }
  646. void rttput(unsigned char p)
  647. {
  648. unsigned char buf[60];
  649. buf[0] = p;
  650. SEGGER_RTT_Write(0, buf, 1);
  651. }
  652. CLI_DEFINE(clirtt, "CLI^$:", rttok, rttget, rttput);
  653. int mai5n(void)
  654. {
  655. while (1)
  656. cli_process(&clirtt);
  657. }