van_bsp_debug_shell.c 21 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /******************************************************************
  2. * Copyright (C) 2023 - 2023 OneChip, Inc. All rights reserved.
  3. * File name: van_bsp_debug_shell.c
  4. * Author: fanyidong Date:2020.11.21
  5. * Description: 单片机仿shell函数
  6. * Others:
  7. * History:
  8. 1. Date:
  9. Author:
  10. Modification:
  11. *****************************************************************/
  12. #include <stdarg.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <van_bsp_debug_uart.h>
  16. #include "onechip_include_header.h"
  17. #define FYD_DEBUG_PRINT Van_Device_Printf
  18. #define VAN_PRINT_HIGH 0
  19. typedef unsigned int (*fundef)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *);
  20. #define COMPARE_ALIGN 0
  21. #define DISBUF_LEN 512
  22. typedef struct
  23. {
  24. char * functionname;
  25. fundef function;
  26. } FUNCALLTYPE;
  27. typedef struct
  28. {
  29. char * variablename;
  30. unsigned int *variableaddr;
  31. } VAREDITTYPE;
  32. #define DEBUG_FUNFLAG (unsigned int)0x3a6e7566 // fun:
  33. #define DEBUG_VERFLAG (unsigned int)0x3a726576 // ver:
  34. #define DEBUG_CANFLAG (unsigned int)0x3a6e6163 // can:
  35. unsigned int gloublePrintLevel = VAN_LOG_ERROR|VAN_LOG_INFO|VAN_LOG_TEMP|VAN_LOG_WIFI; //
  36. unsigned int gloublePrintSwitch = 0; //
  37. unsigned char debugcmdbuf[132] = {0};
  38. unsigned int debugcmdbuflast = 0;
  39. unsigned int debugcmdbufheader = 0;
  40. unsigned int debugtest1(int hexint1);
  41. unsigned int debugtest2(int hexint1, int hexint2);
  42. #define DEBUGFUNCTION(Function) \
  43. { \
  44. #Function, (fundef)Function \
  45. }
  46. #define DEBUGVARIABLE(VARIABLE) \
  47. { \
  48. #VARIABLE, (unsigned int *)&VARIABLE \
  49. }
  50. extern bool set_io(unsigned int ioState);
  51. unsigned int debugver;
  52. FUNCALLTYPE debugFunctionList[] = {DEBUGFUNCTION(debugtest1),
  53. // DEBUGFUNCTION(Van_UART_Sys_Ctr_SendTest),
  54. // DEBUGFUNCTION(showPid),
  55. // DEBUGFUNCTION(Van_UART_Sys_Get_Debuging),
  56. {NULL, 0}};
  57. VAREDITTYPE debugVariableList[]
  58. = {DEBUGVARIABLE(debugver),
  59. // DEBUGVARIABLE(p_rec_flag),
  60. // DEBUGVARIABLE(p_rec_data_flag),
  61. // DEBUGVARIABLE(p_DecodeNew),
  62. // DEBUGVARIABLE(p_recSystemMsg),
  63. // DEBUGVARIABLE(p_Rep_flag),
  64. // DEBUGVARIABLE(p_Rep_data_flag),
  65. // DEBUGVARIABLE(p_Ans_flag),
  66. // DEBUGVARIABLE(p_Ans_data_flag),
  67. // DEBUGVARIABLE(p_Ans_flag_1),
  68. // DEBUGVARIABLE(p_Ans_data_flag_1),
  69. // DEBUGVARIABLE(comAnsOutTimeDebug),
  70. // DEBUGVARIABLE(resetSysUart),
  71. {NULL, 0}};
  72. unsigned int AsiicTorHexChar(const char *cmd, unsigned char *hexchar)
  73. {
  74. unsigned char temp = 0;
  75. if (cmd == 0)
  76. {
  77. return 0;
  78. }
  79. if (('0' <= *cmd) && (*cmd <= '9'))
  80. {
  81. temp += *cmd - '0';
  82. }
  83. else if (('A' <= *cmd) && (*cmd <= 'F'))
  84. {
  85. temp += *cmd - '7';
  86. }
  87. else if (('a' <= *cmd) && (*cmd <= 'f'))
  88. {
  89. temp += *cmd - 'W';
  90. }
  91. else
  92. {
  93. return 1;
  94. }
  95. temp = temp * 0x10;
  96. cmd++;
  97. if (('0' <= *cmd) && (*cmd <= '9'))
  98. {
  99. temp += *cmd - '0';
  100. }
  101. else if (('A' <= *cmd) && (*cmd <= 'F'))
  102. {
  103. temp += *cmd - '7';
  104. }
  105. else if (('a' <= *cmd) && (*cmd <= 'f'))
  106. {
  107. temp += *cmd - 'W';
  108. }
  109. else
  110. {
  111. return 1;
  112. }
  113. *hexchar = temp;
  114. return 0;
  115. }
  116. unsigned int AsiicTorHexShort(const char *cmd, unsigned short *hexshort)
  117. {
  118. unsigned short temp = 0;
  119. unsigned int i;
  120. if (cmd == 0)
  121. {
  122. return 0;
  123. }
  124. for (i = 0; i < 4; i++)
  125. {
  126. temp = temp * 0x10;
  127. if (('0' <= *cmd) && (*cmd <= '9'))
  128. {
  129. temp += *cmd - '0';
  130. }
  131. else if (('A' <= *cmd) && (*cmd <= 'F'))
  132. {
  133. temp += *cmd - '7';
  134. }
  135. else if (('a' <= *cmd) && (*cmd <= 'f'))
  136. {
  137. temp += *cmd - 'W';
  138. }
  139. else
  140. {
  141. return 1;
  142. }
  143. cmd++;
  144. }
  145. *hexshort = temp;
  146. return 0;
  147. }
  148. unsigned int AsiicTorHexInt(const char *cmd, unsigned int *hexint)
  149. {
  150. unsigned int temp = 0;
  151. if (cmd == 0)
  152. {
  153. return 0;
  154. }
  155. while (*cmd)
  156. {
  157. temp = temp * 0x10;
  158. if (('0' <= *cmd) && (*cmd <= '9'))
  159. {
  160. temp += *cmd - '0';
  161. }
  162. else if (('A' <= *cmd) && (*cmd <= 'F'))
  163. {
  164. temp += *cmd - '7';
  165. }
  166. else if (('a' <= *cmd) && (*cmd <= 'f'))
  167. {
  168. temp += *cmd - 'W';
  169. }
  170. else
  171. {
  172. return 1;
  173. }
  174. cmd++;
  175. }
  176. *hexint = temp;
  177. return 0;
  178. }
  179. unsigned int INTAsiicTorHexInt(const char *cmd, unsigned int *hexint)
  180. {
  181. unsigned int temp = 0;
  182. unsigned int isMinus = 0;
  183. if (cmd == 0)
  184. {
  185. return 0;
  186. }
  187. if (*cmd == '-')
  188. {
  189. isMinus = 1;
  190. cmd++;
  191. }
  192. while (*cmd)
  193. {
  194. temp = temp * 10;
  195. if (('0' <= *cmd) && (*cmd <= '9'))
  196. {
  197. temp += *cmd - '0';
  198. }
  199. else
  200. {
  201. return 1;
  202. }
  203. cmd++;
  204. }
  205. if (isMinus)
  206. {
  207. *hexint = -temp;
  208. }
  209. else
  210. {
  211. *hexint = temp;
  212. }
  213. return 0;
  214. }
  215. unsigned int HexCharTorAsiic(unsigned char *asiccbuf, unsigned char hexchar)
  216. {
  217. unsigned short temp = 0;
  218. unsigned int i;
  219. if (asiccbuf == 0)
  220. {
  221. return 1;
  222. }
  223. for (i = 0; i < 2; i++)
  224. {
  225. temp = (hexchar & 0xf0) >> 4;
  226. if (temp < 10)
  227. {
  228. *asiccbuf = '0' + temp;
  229. }
  230. else
  231. {
  232. *asiccbuf = '7' + temp;
  233. }
  234. asiccbuf++;
  235. hexchar = hexchar << 4;
  236. }
  237. return 0;
  238. }
  239. unsigned int HexShortToAsiicr(char *asiccbuf, unsigned short hexshort)
  240. {
  241. unsigned short temp = 0;
  242. unsigned int i;
  243. if (asiccbuf == 0)
  244. {
  245. return 1;
  246. }
  247. for (i = 0; i < 4; i++)
  248. {
  249. temp = (hexshort & 0xf000) >> 12;
  250. if (temp < 10)
  251. {
  252. *asiccbuf = '0' + temp;
  253. }
  254. else
  255. {
  256. *asiccbuf = '7' + temp;
  257. }
  258. asiccbuf++;
  259. hexshort = hexshort << 4;
  260. }
  261. return 0;
  262. }
  263. unsigned int HexIntAsiicToAsiicr(char *asiccbuf, unsigned int hexint)
  264. {
  265. unsigned int temp = 0;
  266. unsigned int i;
  267. if (asiccbuf == 0)
  268. {
  269. return 1;
  270. }
  271. for (i = 0; i < 8; i++)
  272. {
  273. temp = (hexint & 0xf0000000) >> 28;
  274. if (temp < 10)
  275. {
  276. *asiccbuf = '0' + temp;
  277. }
  278. else
  279. {
  280. *asiccbuf = '7' + temp;
  281. }
  282. asiccbuf++;
  283. hexint = hexint << 4;
  284. }
  285. return 0;
  286. }
  287. unsigned int IntAsiicToAsiicr(char *asiccbuf, int hexint)
  288. {
  289. unsigned int temp = 0;
  290. unsigned int i = 0;
  291. if (asiccbuf == 0)
  292. {
  293. return 1;
  294. }
  295. if (hexint < 0)
  296. {
  297. *asiccbuf = '-';
  298. asiccbuf++;
  299. hexint = -hexint;
  300. i++;
  301. }
  302. temp = hexint / 1000000000;
  303. if (temp)
  304. {
  305. *asiccbuf = '0' + temp;
  306. hexint = hexint % 1000000000;
  307. i++;
  308. }
  309. temp = hexint / 100000000;
  310. if (temp)
  311. {
  312. *asiccbuf = '0' + temp;
  313. hexint = hexint % 100000000;
  314. i++;
  315. }
  316. temp = hexint / 10000000;
  317. if (temp)
  318. {
  319. *asiccbuf = '0' + temp;
  320. hexint = hexint % 10000000;
  321. i++;
  322. }
  323. temp = hexint / 1000000;
  324. if (temp)
  325. {
  326. *asiccbuf = '0' + temp;
  327. hexint = hexint % 1000000;
  328. i++;
  329. }
  330. temp = hexint / 100000;
  331. if (temp)
  332. {
  333. *asiccbuf = '0' + temp;
  334. hexint = hexint % 100000;
  335. i++;
  336. }
  337. temp = hexint / 10000;
  338. if (temp)
  339. {
  340. *asiccbuf = '0' + temp;
  341. hexint = hexint % 10000;
  342. i++;
  343. }
  344. temp = hexint / 1000;
  345. if (temp)
  346. {
  347. *asiccbuf = '0' + temp;
  348. hexint = hexint % 1000;
  349. i++;
  350. }
  351. temp = hexint / 100;
  352. if (temp)
  353. {
  354. *asiccbuf = '0' + temp;
  355. hexint = hexint % 100;
  356. i++;
  357. }
  358. temp = hexint / 10;
  359. if (temp)
  360. {
  361. *asiccbuf = '0' + temp;
  362. hexint = hexint % 10;
  363. i++;
  364. }
  365. *asiccbuf = '0' + temp;
  366. i++;
  367. return i;
  368. }
  369. unsigned int debugtest1(int hexint1)
  370. {
  371. FYD_DEBUG_PRINT(VAN_PRINT_HIGH,"%s:pra1[0x%x]:\n\r", __func__,
  372. hexint1);
  373. return (hexint1);
  374. }
  375. unsigned int debugtest2(int hexint1, int hexint2)
  376. {
  377. FYD_DEBUG_PRINT(VAN_PRINT_HIGH,"%s:pra1[0x%x]:pra2[0x%x]:\n\r",
  378. __func__, hexint1, hexint2);
  379. return (hexint1 + hexint2);
  380. }
  381. int funnamecmp(unsigned char *callfun, unsigned char *funlist)
  382. {
  383. while (*callfun && *funlist)
  384. {
  385. if (*callfun != *funlist)
  386. {
  387. return 0;
  388. }
  389. else
  390. {
  391. callfun++;
  392. funlist++;
  393. }
  394. }
  395. if (*callfun == 0 && *funlist == 0 )
  396. return 1;
  397. else
  398. return 0;
  399. }
  400. void debugcall(unsigned char *cmdbuf)
  401. {
  402. unsigned char functionname[32] = {0};
  403. unsigned char parabuf[32] = {0};
  404. unsigned int i = 0;
  405. unsigned int j = 0;
  406. unsigned int k = 0;
  407. unsigned int para[10] = {0};
  408. unsigned int result = 0;
  409. unsigned int paraDecimal; //
  410. FUNCALLTYPE *findfun = debugFunctionList;
  411. while (*(cmdbuf + i) != '(' && *(cmdbuf + i))
  412. {
  413. functionname[i] = *(cmdbuf + i);
  414. i++;
  415. }
  416. if (*(cmdbuf + i) != '(')
  417. {
  418. return;
  419. }
  420. i++; //find '('
  421. for (j = 0; j < 10; j++)
  422. {
  423. paraDecimal = 1;
  424. k = 0;
  425. if ((*(cmdbuf + i) == '0')
  426. && (*(cmdbuf + i + 1) == 'x' || *(cmdbuf + i + 1) == 'X'))
  427. {
  428. i = i + 2;
  429. paraDecimal = 0;
  430. }
  431. while (*(cmdbuf + i) != ',' && *(cmdbuf + i) != ')' && *(cmdbuf + i))
  432. {
  433. parabuf[k++] = *(cmdbuf + i);
  434. i++;
  435. }
  436. parabuf[k++] = '\0';
  437. if (paraDecimal)
  438. {
  439. INTAsiicTorHexInt((const char *)parabuf, &para[j]);
  440. }
  441. else
  442. {
  443. AsiicTorHexInt((const char *)parabuf, &para[j]);
  444. }
  445. if (*(cmdbuf + i) == ')')
  446. {
  447. break;
  448. }
  449. i++; //skip space
  450. }
  451. while (findfun->functionname)
  452. {
  453. if (funnamecmp(functionname, (unsigned char *)findfun->functionname))
  454. {
  455. break;
  456. }
  457. findfun++;
  458. }
  459. if (findfun->function)
  460. {
  461. result = (unsigned int)findfun->function((void *)para[0], (void *)para[1],
  462. (void *)para[2], (void *)para[3],
  463. (void *)para[4], (void *)para[5],
  464. (void *)para[6], (void *)para[7],
  465. (void *)para[8], (void *)para[9]);
  466. FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "%s = 0x%x \r\n", functionname,
  467. result);
  468. }
  469. else
  470. {
  471. FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "Pleas add %s to function list\n",
  472. functionname);
  473. }
  474. }
  475. void debugvarb(unsigned char *varbbuf)
  476. {
  477. unsigned char variablename[32] = {0};
  478. unsigned char parabuf[32] = {0};
  479. unsigned int i = 0;
  480. unsigned int j = 0;
  481. unsigned int k = 0;
  482. unsigned int para[5] = {0, 0, 0, 0, 0};
  483. unsigned int paraDecimal; //decmail flag
  484. unsigned int readwriteFlag = 0; //
  485. VAREDITTYPE *findvarb = debugVariableList;
  486. /*get fun name*/
  487. while (*(varbbuf + i) != '(')
  488. {
  489. variablename[i] = *(varbbuf + i);
  490. i++;
  491. }
  492. i++; //find (
  493. for (j = 0; j < 5; j++)
  494. {
  495. paraDecimal = 1;
  496. k = 0;
  497. if ((*(varbbuf + i) == '0')
  498. && (*(varbbuf + i + 1) == 'x' || *(varbbuf + i + 1) == 'X'))
  499. {
  500. i = i + 2;
  501. paraDecimal = 0;
  502. }
  503. while (*(varbbuf + i) != ',' && *(varbbuf + i) != ')')
  504. {
  505. parabuf[k++] = *(varbbuf + i);
  506. i++;
  507. readwriteFlag = 1;
  508. }
  509. parabuf[k++] = '\0';
  510. if (paraDecimal)
  511. {
  512. INTAsiicTorHexInt((const char *)parabuf, &para[j]);
  513. }
  514. else
  515. {
  516. AsiicTorHexInt((const char *)parabuf, &para[j]);
  517. }
  518. if (*(varbbuf + i) == ')')
  519. {
  520. break;
  521. }
  522. i++; //find space
  523. }
  524. while (findvarb->variablename)
  525. {
  526. if (funnamecmp(variablename, (unsigned char *)findvarb->variablename))
  527. {
  528. break;
  529. }
  530. findvarb++;
  531. }
  532. if (findvarb->variableaddr)
  533. {
  534. if (readwriteFlag)
  535. {
  536. *(findvarb->variableaddr) = para[0];
  537. }
  538. FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "%s = 0x%x\r\n", variablename,
  539. *(findvarb->variableaddr));
  540. }
  541. else
  542. {
  543. FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "Pleas add %s to variable list\r\n",
  544. variablename);
  545. }
  546. }
  547. void debugcan(unsigned char *buf)
  548. {
  549. unsigned char canbuf[32] = {0};
  550. unsigned char caninf[8] = {0};
  551. unsigned int i = 1;
  552. unsigned int j = 0;
  553. while (*(buf + i) != ')')
  554. {
  555. canbuf[j++] = *(buf + i);
  556. i++;
  557. }
  558. for (i = 0; i < 8; i++)
  559. {
  560. AsiicTorHexChar((const char *)&canbuf[2 * i], &caninf[i]);
  561. }
  562. }
  563. int cmppare_hear(unsigned char *buf, unsigned char *header ){
  564. if(buf[0]==header[0]&&buf[1]==header[1]&&buf[2]==header[2]&&buf[3]==header[3]){
  565. return 1;
  566. }
  567. return 0;
  568. }
  569. void decodedebugfunction(void)
  570. {
  571. unsigned int seekstart;
  572. unsigned char cmdbuf[64] = {0};
  573. unsigned int i, j;
  574. unsigned int cmdflag = 0;
  575. unsigned int buflen = 0;
  576. unsigned int buflencon = 0;
  577. unsigned int dataleft = (debugcmdbuflast + 128 -debugcmdbufheader)%128;
  578. if(dataleft > 32){
  579. Van_Device_Printf(VAN_LOG_NOTICE, "debug buffer have:%d\n\r***", dataleft);
  580. }
  581. if ((debugcmdbufheader + 6) < debugcmdbuflast)
  582. {
  583. seekstart = debugcmdbufheader;
  584. #ifdef COMPARE_ALIGN
  585. while (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  586. {
  587. if((seekstart + 6) < debugcmdbuflast){
  588. seekstart++;
  589. }else{
  590. break;
  591. }
  592. }
  593. #else
  594. while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG
  595. && (seekstart + 6) < debugcmdbuflast)
  596. {
  597. seekstart++;
  598. }
  599. #endif
  600. #ifdef COMPARE_ALIGN
  601. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  602. #else
  603. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
  604. #endif
  605. {
  606. i = seekstart + 4;
  607. j = 0;
  608. buflen = debugcmdbuflast - i;
  609. buflencon = 0;
  610. while (debugcmdbuf[i] != ')' && buflencon < buflen)
  611. {
  612. cmdbuf[j++] = debugcmdbuf[i++];
  613. buflencon++;
  614. }
  615. if (debugcmdbuf[i] == ')')
  616. {
  617. cmdflag = 1;
  618. cmdbuf[j++] = ')';
  619. debugcmdbufheader = i;
  620. }
  621. i++;
  622. }
  623. }
  624. else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
  625. && (debugcmdbufheader > debugcmdbuflast))
  626. {
  627. seekstart = debugcmdbufheader;
  628. for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
  629. {
  630. #ifdef COMPARE_ALIGN
  631. if (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  632. #else
  633. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG)
  634. #endif
  635. {
  636. seekstart++;
  637. }
  638. else
  639. {
  640. break;
  641. }
  642. }
  643. #ifdef COMPARE_ALIGN
  644. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  645. #else
  646. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
  647. #endif
  648. {
  649. i = (seekstart + 4) % 128;
  650. j = 0;
  651. if (i < debugcmdbuflast)
  652. {
  653. buflen = debugcmdbuflast - i;
  654. }
  655. else
  656. {
  657. buflen = debugcmdbuflast + 128 - i;
  658. }
  659. buflencon = 0;
  660. while (debugcmdbuf[i % 128] != ')' && buflencon < buflen)
  661. {
  662. cmdbuf[j++] = debugcmdbuf[i % 128];
  663. buflencon++;
  664. i++;
  665. }
  666. i = i % 128;
  667. if (debugcmdbuf[i] == ')')
  668. {
  669. cmdflag = 1;
  670. cmdbuf[j++] = ')';
  671. debugcmdbufheader = i;
  672. }
  673. i++;
  674. }
  675. else
  676. {
  677. seekstart = 0;
  678. for (; (seekstart + 6) < (debugcmdbuflast);)
  679. {
  680. #ifdef COMPARE_ALIGN
  681. if (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  682. #else
  683. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG)
  684. #endif
  685. {
  686. seekstart++;
  687. }
  688. #ifdef COMPARE_ALIGN
  689. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
  690. #else
  691. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
  692. #endif
  693. {
  694. i = (seekstart + 4);
  695. j = 0;
  696. if (i < debugcmdbuflast)
  697. {
  698. buflen = debugcmdbuflast - i;
  699. }
  700. else
  701. {
  702. buflen = debugcmdbuflast + 128 - i;
  703. }
  704. buflencon = 0;
  705. while (debugcmdbuf[i] != ')' && buflencon < buflen)
  706. {
  707. cmdbuf[j++] = debugcmdbuf[i];
  708. i++;
  709. buflencon++;
  710. }
  711. if (debugcmdbuf[i] == ')')
  712. {
  713. cmdflag = 1;
  714. cmdbuf[j++] = ')';
  715. debugcmdbufheader = i;
  716. }
  717. i++;
  718. break;
  719. }
  720. }
  721. }
  722. }
  723. if (cmdflag)
  724. {
  725. debugcall(cmdbuf);
  726. }
  727. }
  728. void decodedebugvariable(void)
  729. {
  730. unsigned int seekstart;
  731. unsigned char varbuf[64];
  732. unsigned int i, j;
  733. unsigned int cmdflag = 0;
  734. unsigned int buflencon = 0;
  735. unsigned int buflen = 0;
  736. if ((debugcmdbufheader + 6) < debugcmdbuflast)
  737. {
  738. seekstart = debugcmdbufheader;
  739. #ifdef COMPARE_ALIGN
  740. while (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  741. {
  742. if((seekstart + 6) < debugcmdbuflast){
  743. seekstart++;
  744. }else{
  745. break;
  746. }
  747. }
  748. #else
  749. while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG
  750. && (seekstart + 6) < debugcmdbuflast)
  751. {
  752. seekstart++;
  753. }
  754. #endif
  755. #ifdef COMPARE_ALIGN
  756. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  757. #else
  758. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
  759. #endif
  760. {
  761. i = seekstart + 4;
  762. j = 0;
  763. while (debugcmdbuf[i] != ')' && i < debugcmdbuflast) { varbuf[j++] = debugcmdbuf[i++]; }
  764. if(debugcmdbuf[i] == ')'){
  765. cmdflag = 1;
  766. varbuf[j++] = ')';
  767. debugcmdbufheader = i;
  768. }
  769. i++;
  770. }
  771. }
  772. else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
  773. && (debugcmdbufheader > debugcmdbuflast))
  774. {
  775. seekstart = debugcmdbufheader;
  776. for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
  777. {
  778. #ifdef COMPARE_ALIGN
  779. if (0 == cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  780. #else
  781. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG)
  782. #endif
  783. {
  784. seekstart++;
  785. }
  786. else
  787. {
  788. break;
  789. }
  790. }
  791. #ifdef COMPARE_ALIGN
  792. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  793. #else
  794. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
  795. #endif
  796. {
  797. i = (seekstart + 4) % 128;
  798. j = 0;
  799. if (i < debugcmdbuflast)
  800. {
  801. buflen = debugcmdbuflast - i;
  802. }
  803. else
  804. {
  805. buflen = debugcmdbuflast + 128 - i;
  806. }
  807. buflencon = 0;
  808. while (debugcmdbuf[i % 128] != ')' && buflencon < buflen)
  809. {
  810. varbuf[j++] = debugcmdbuf[i % 128];
  811. i++;
  812. }
  813. if(debugcmdbuf[i % 128] == ')'){
  814. cmdflag = 1;
  815. varbuf[j++] = ')';
  816. debugcmdbufheader = i % 128;
  817. }
  818. i++;
  819. }
  820. else
  821. {
  822. seekstart = 0;
  823. for (; (seekstart + 6) < (debugcmdbuflast);)
  824. {
  825. #ifdef COMPARE_ALIGN
  826. if (0 == cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  827. #else
  828. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG)
  829. #endif
  830. {
  831. seekstart++;
  832. }
  833. #ifdef COMPARE_ALIGN
  834. if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
  835. #else
  836. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
  837. #endif
  838. {
  839. i = (seekstart + 4);
  840. j = 0;
  841. if (i < debugcmdbuflast)
  842. {
  843. buflen = debugcmdbuflast - i;
  844. }
  845. else
  846. {
  847. buflen = debugcmdbuflast + 128 - i;
  848. }
  849. buflencon = 0;
  850. while (debugcmdbuf[i] != ')'&& buflencon < buflen)
  851. {
  852. varbuf[j++] = debugcmdbuf[i];
  853. i++;
  854. }
  855. if(debugcmdbuf[i % 128] == ')'){
  856. cmdflag = 1;
  857. varbuf[j++] = ')';
  858. debugcmdbufheader = i % 128;
  859. }
  860. i++;
  861. break;
  862. }
  863. }
  864. }
  865. }
  866. if (cmdflag)
  867. {
  868. debugvarb(varbuf);
  869. }
  870. }
  871. void decodedebugCAN(unsigned char *caninf)
  872. {
  873. unsigned int seekstart;
  874. unsigned char canbuf[64];
  875. unsigned int i, j;
  876. unsigned int cmdflag = 0;
  877. if ((debugcmdbufheader + 6) < debugcmdbuflast)
  878. {
  879. seekstart = debugcmdbufheader;
  880. while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG
  881. && (seekstart + 6) < debugcmdbuflast)
  882. {
  883. seekstart++;
  884. }
  885. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
  886. {
  887. i = seekstart + 4;
  888. j = 0;
  889. cmdflag = 1;
  890. while (debugcmdbuf[i] != ')') { canbuf[j++] = debugcmdbuf[i++]; }
  891. canbuf[j++] = ')';
  892. i++;
  893. debugcmdbufheader = i;
  894. }
  895. }
  896. else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
  897. && (debugcmdbufheader > debugcmdbuflast))
  898. {
  899. seekstart = debugcmdbufheader;
  900. for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
  901. {
  902. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG)
  903. {
  904. seekstart++;
  905. }
  906. else
  907. {
  908. break;
  909. }
  910. }
  911. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
  912. {
  913. i = (seekstart + 4) % 128;
  914. j = 0;
  915. cmdflag = 1;
  916. while (debugcmdbuf[i % 128] != ')')
  917. {
  918. canbuf[j++] = debugcmdbuf[i % 128];
  919. i++;
  920. }
  921. canbuf[j++] = ')';
  922. i++;
  923. debugcmdbufheader = i % 128;
  924. }
  925. else
  926. {
  927. seekstart = 0;
  928. for (; (seekstart + 6) < (debugcmdbuflast);)
  929. {
  930. if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG)
  931. {
  932. seekstart++;
  933. }
  934. if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
  935. {
  936. i = (seekstart + 4);
  937. j = 0;
  938. cmdflag = 1;
  939. while (debugcmdbuf[i] != ')')
  940. {
  941. canbuf[j++] = debugcmdbuf[i];
  942. i++;
  943. }
  944. canbuf[j++] = ')';
  945. i++;
  946. debugcmdbufheader = i;
  947. break;
  948. }
  949. }
  950. }
  951. }
  952. if (cmdflag)
  953. {
  954. debugcan(canbuf);
  955. }
  956. }
  957. void addinputtocmdbuf(unsigned char *cmdbuf, unsigned int len)
  958. {
  959. unsigned int i;
  960. for (i = 0; i < len; i++)
  961. {
  962. debugcmdbuf[debugcmdbuflast] = *(cmdbuf + i);
  963. if (debugcmdbuflast < 4)
  964. *(unsigned int *)&debugcmdbuf[128]
  965. = *(unsigned int *)&debugcmdbuf[0];
  966. debugcmdbuflast++;
  967. if (debugcmdbuflast == 128)
  968. debugcmdbuflast = 0;
  969. }
  970. }
  971. void addChartoCmdBuf(unsigned char inputchar)
  972. {
  973. debugcmdbuf[debugcmdbuflast] = inputchar;
  974. if (debugcmdbuflast < 4)
  975. *(unsigned int *)&debugcmdbuf[128] = *(unsigned int *)&debugcmdbuf[0];
  976. debugcmdbuflast++;
  977. if (debugcmdbuflast == 128)
  978. debugcmdbuflast = 0;
  979. }
  980. /****************************************************************
  981. * 函数名: Van_Device_Printf
  982. * 创建时间: 2021/04/22
  983. * 创建人: 范义东
  984. * 函数说明:调试打印接口函数
  985. * 输入参数: dev 传 NULL 采用本地定义
  986. devNum 数码
  987. * 输出参数: *name
  988. * 返回值 : void
  989. ****************************************************************/
  990. void Van_Device_Printf(unsigned int printLevel, const char *cmd, ...)
  991. {
  992. char buf[DISBUF_LEN] = {0};
  993. int buflen = 0;
  994. __disable_irq();
  995. if ((gloublePrintLevel & printLevel) || (printLevel==VAN_LOG_ALLPRINT))
  996. {
  997. va_list args; //定义一个va_list类型的变量,用来储存单个参数
  998. va_start(args, cmd); //使args指向可变参数的第一个参数
  999. vsprintf(buf, cmd, args); //必须用vprintf等带V的
  1000. va_end(args); //结束可变参数的获取
  1001. buflen = strlen((const char *)buf);
  1002. Van_Debug_UART_Send_DMA((unsigned char *)buf, buflen); //将收到的信息发送出
  1003. }
  1004. __enable_irq();
  1005. return;
  1006. }
  1007. /****************************************************************
  1008. * 函数名: find_stm32_Peripherals
  1009. * 创建时间: 2021/04/22
  1010. * 创建人: 范义东
  1011. * 函数说明:调试打印接口函数
  1012. * 输入参数: peripheralsAdd 地址指针
  1013. * 输出参数: *name
  1014. * 返回值 : void
  1015. ****************************************************************/
  1016. void find_stm32_Peripherals(void *peripheralsAdd, char *name)
  1017. {
  1018. }