van_bsp_debug_shell.c 22 KB

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