| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106 |
- /******************************************************************
- * Copyright (C) 2023 - 2023 OneChip, Inc. All rights reserved.
- * File name: van_bsp_debug_shell.c
- * Author: fanyidong Date:2020.11.21
- * Description: 单片机仿shell函数
- * Others:
- * History:
- 1. Date:
- Author:
- Modification:
- *****************************************************************/
- #include <stdarg.h>
- #include <stdio.h>
- #include <string.h>
- #include <van_bsp_debug_uart.h>
- #include "onechip_include_header.h"
- #define FYD_DEBUG_PRINT Van_Device_Printf
-
- #define VAN_PRINT_HIGH 0
- typedef unsigned int (*fundef)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *);
- #define COMPARE_ALIGN 0
- #define DISBUF_LEN 512
- typedef struct
- {
- char * functionname;
- fundef function;
- } FUNCALLTYPE;
- typedef struct
- {
- char * variablename;
- unsigned int *variableaddr;
- } VAREDITTYPE;
- #define DEBUG_FUNFLAG (unsigned int)0x3a6e7566 // fun:
- #define DEBUG_VERFLAG (unsigned int)0x3a726576 // ver:
- #define DEBUG_CANFLAG (unsigned int)0x3a6e6163 // can:
- unsigned int gloublePrintLevel = VAN_LOG_ERROR|VAN_LOG_INFO|VAN_LOG_TEMP|VAN_LOG_WIFI; //
- unsigned int gloublePrintSwitch = 0; //
- unsigned char debugcmdbuf[132] = {0};
- unsigned int debugcmdbuflast = 0;
- unsigned int debugcmdbufheader = 0;
- unsigned int debugtest1(int hexint1);
- unsigned int debugtest2(int hexint1, int hexint2);
- #define DEBUGFUNCTION(Function) \
- { \
- #Function, (fundef)Function \
- }
- #define DEBUGVARIABLE(VARIABLE) \
- { \
- #VARIABLE, (unsigned int *)&VARIABLE \
- }
- extern bool set_io(unsigned int ioState);
- unsigned int debugver;
- FUNCALLTYPE debugFunctionList[] = {DEBUGFUNCTION(debugtest1),
- // DEBUGFUNCTION(Van_UART_Sys_Ctr_SendTest),
- DEBUGFUNCTION(com_pwm_test),
- DEBUGFUNCTION(show_com_pwm),
- // DEBUGFUNCTION(showPid),
- // DEBUGFUNCTION(Van_UART_Sys_Get_Debuging),
- {NULL, 0}};
- extern int printDrvStatusFlag;
- extern unsigned int onechip_log_level;
- extern unsigned int onechip_testflag;
- extern unsigned int p_rec_flag;
- extern unsigned int p_rec_data_flag;
- extern unsigned int p_DecodeNew;
- extern unsigned int p_recSystemMsg;
- extern unsigned int p_Rep_flag;
- extern unsigned int p_Rep_data_flag;
- extern unsigned int p_Ans_flag;
- extern unsigned int p_Ans_data_flag;
- extern unsigned int p_Ans_flag_1;
- extern unsigned int p_Ans_data_flag_1;
- extern unsigned int print_chip_pwm;
- extern unsigned int comAnsOutTimeDebug;
- extern unsigned int dealOutTimeDebug;
- extern uint32_t TMC5160SPIFlag;
- extern uint32_t resetSysUart;
- VAREDITTYPE debugVariableList[]
- = {DEBUGVARIABLE(debugver),
- // DEBUGVARIABLE(p_rec_flag),
- // DEBUGVARIABLE(p_rec_data_flag),
- // DEBUGVARIABLE(p_DecodeNew),
- // DEBUGVARIABLE(p_recSystemMsg),
- // DEBUGVARIABLE(p_Rep_flag),
- // DEBUGVARIABLE(p_Rep_data_flag),
- // DEBUGVARIABLE(p_Ans_flag),
- // DEBUGVARIABLE(p_Ans_data_flag),
- // DEBUGVARIABLE(p_Ans_flag_1),
- // DEBUGVARIABLE(p_Ans_data_flag_1),
- // DEBUGVARIABLE(comAnsOutTimeDebug),
- // DEBUGVARIABLE(resetSysUart),
-
- {NULL, 0}};
- unsigned int AsiicTorHexChar(const char *cmd, unsigned char *hexchar)
- {
- unsigned char temp = 0;
- if (cmd == 0)
- {
- return 0;
- }
- if (('0' <= *cmd) && (*cmd <= '9'))
- {
- temp += *cmd - '0';
- }
- else if (('A' <= *cmd) && (*cmd <= 'F'))
- {
- temp += *cmd - '7';
- }
- else if (('a' <= *cmd) && (*cmd <= 'f'))
- {
- temp += *cmd - 'W';
- }
- else
- {
- return 1;
- }
- temp = temp * 0x10;
- cmd++;
- if (('0' <= *cmd) && (*cmd <= '9'))
- {
- temp += *cmd - '0';
- }
- else if (('A' <= *cmd) && (*cmd <= 'F'))
- {
- temp += *cmd - '7';
- }
- else if (('a' <= *cmd) && (*cmd <= 'f'))
- {
- temp += *cmd - 'W';
- }
- else
- {
- return 1;
- }
- *hexchar = temp;
- return 0;
- }
- unsigned int AsiicTorHexShort(const char *cmd, unsigned short *hexshort)
- {
- unsigned short temp = 0;
- unsigned int i;
- if (cmd == 0)
- {
- return 0;
- }
- for (i = 0; i < 4; i++)
- {
- temp = temp * 0x10;
- if (('0' <= *cmd) && (*cmd <= '9'))
- {
- temp += *cmd - '0';
- }
- else if (('A' <= *cmd) && (*cmd <= 'F'))
- {
- temp += *cmd - '7';
- }
- else if (('a' <= *cmd) && (*cmd <= 'f'))
- {
- temp += *cmd - 'W';
- }
- else
- {
- return 1;
- }
- cmd++;
- }
- *hexshort = temp;
- return 0;
- }
- unsigned int AsiicTorHexInt(const char *cmd, unsigned int *hexint)
- {
- unsigned int temp = 0;
- if (cmd == 0)
- {
- return 0;
- }
- while (*cmd)
- {
- temp = temp * 0x10;
- if (('0' <= *cmd) && (*cmd <= '9'))
- {
- temp += *cmd - '0';
- }
- else if (('A' <= *cmd) && (*cmd <= 'F'))
- {
- temp += *cmd - '7';
- }
- else if (('a' <= *cmd) && (*cmd <= 'f'))
- {
- temp += *cmd - 'W';
- }
- else
- {
- return 1;
- }
- cmd++;
- }
- *hexint = temp;
- return 0;
- }
- unsigned int INTAsiicTorHexInt(const char *cmd, unsigned int *hexint)
- {
- unsigned int temp = 0;
- unsigned int isMinus = 0;
- if (cmd == 0)
- {
- return 0;
- }
- if (*cmd == '-')
- {
- isMinus = 1;
- cmd++;
- }
- while (*cmd)
- {
- temp = temp * 10;
- if (('0' <= *cmd) && (*cmd <= '9'))
- {
- temp += *cmd - '0';
- }
- else
- {
- return 1;
- }
- cmd++;
- }
- if (isMinus)
- {
- *hexint = -temp;
- }
- else
- {
- *hexint = temp;
- }
- return 0;
- }
- unsigned int HexCharTorAsiic(unsigned char *asiccbuf, unsigned char hexchar)
- {
- unsigned short temp = 0;
- unsigned int i;
- if (asiccbuf == 0)
- {
- return 1;
- }
- for (i = 0; i < 2; i++)
- {
- temp = (hexchar & 0xf0) >> 4;
- if (temp < 10)
- {
- *asiccbuf = '0' + temp;
- }
- else
- {
- *asiccbuf = '7' + temp;
- }
- asiccbuf++;
- hexchar = hexchar << 4;
- }
- return 0;
- }
- unsigned int HexShortToAsiicr(char *asiccbuf, unsigned short hexshort)
- {
- unsigned short temp = 0;
- unsigned int i;
- if (asiccbuf == 0)
- {
- return 1;
- }
- for (i = 0; i < 4; i++)
- {
- temp = (hexshort & 0xf000) >> 12;
- if (temp < 10)
- {
- *asiccbuf = '0' + temp;
- }
- else
- {
- *asiccbuf = '7' + temp;
- }
- asiccbuf++;
- hexshort = hexshort << 4;
- }
- return 0;
- }
- unsigned int HexIntAsiicToAsiicr(char *asiccbuf, unsigned int hexint)
- {
- unsigned int temp = 0;
- unsigned int i;
- if (asiccbuf == 0)
- {
- return 1;
- }
- for (i = 0; i < 8; i++)
- {
- temp = (hexint & 0xf0000000) >> 28;
- if (temp < 10)
- {
- *asiccbuf = '0' + temp;
- }
- else
- {
- *asiccbuf = '7' + temp;
- }
- asiccbuf++;
- hexint = hexint << 4;
- }
- return 0;
- }
- unsigned int IntAsiicToAsiicr(char *asiccbuf, int hexint)
- {
- unsigned int temp = 0;
- unsigned int i = 0;
- if (asiccbuf == 0)
- {
- return 1;
- }
- if (hexint < 0)
- {
- *asiccbuf = '-';
- asiccbuf++;
- hexint = -hexint;
- i++;
- }
- temp = hexint / 1000000000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 1000000000;
- i++;
- }
- temp = hexint / 100000000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 100000000;
- i++;
- }
- temp = hexint / 10000000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 10000000;
- i++;
- }
- temp = hexint / 1000000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 1000000;
- i++;
- }
- temp = hexint / 100000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 100000;
- i++;
- }
- temp = hexint / 10000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 10000;
- i++;
- }
- temp = hexint / 1000;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 1000;
- i++;
- }
- temp = hexint / 100;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 100;
- i++;
- }
- temp = hexint / 10;
- if (temp)
- {
- *asiccbuf = '0' + temp;
- hexint = hexint % 10;
- i++;
- }
- *asiccbuf = '0' + temp;
- i++;
- return i;
- }
- unsigned int debugtest1(int hexint1)
- {
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH,"%s:pra1[0x%x]:\n\r", __func__,
- hexint1);
- return (hexint1);
- }
- unsigned int debugtest2(int hexint1, int hexint2)
- {
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH,"%s:pra1[0x%x]:pra2[0x%x]:\n\r",
- __func__, hexint1, hexint2);
- return (hexint1 + hexint2);
- }
- int funnamecmp(unsigned char *callfun, unsigned char *funlist)
- {
- while (*callfun && *funlist)
- {
- if (*callfun != *funlist)
- {
- return 0;
- }
- else
- {
- callfun++;
- funlist++;
- }
- }
- if (*callfun == 0 && *funlist == 0 )
- return 1;
- else
- return 0;
- }
- void debugcall(unsigned char *cmdbuf)
- {
- unsigned char functionname[32] = {0};
- unsigned char parabuf[32] = {0};
- unsigned int i = 0;
- unsigned int j = 0;
- unsigned int k = 0;
- unsigned int para[10] = {0};
- unsigned int result = 0;
- unsigned int paraDecimal; //
- FUNCALLTYPE *findfun = debugFunctionList;
- while (*(cmdbuf + i) != '(' && *(cmdbuf + i))
- {
- functionname[i] = *(cmdbuf + i);
- i++;
- }
- if (*(cmdbuf + i) != '(')
- {
- return;
- }
- i++; //find '('
- for (j = 0; j < 10; j++)
- {
- paraDecimal = 1;
- k = 0;
- if ((*(cmdbuf + i) == '0')
- && (*(cmdbuf + i + 1) == 'x' || *(cmdbuf + i + 1) == 'X'))
- {
- i = i + 2;
- paraDecimal = 0;
- }
- while (*(cmdbuf + i) != ',' && *(cmdbuf + i) != ')' && *(cmdbuf + i))
- {
- parabuf[k++] = *(cmdbuf + i);
- i++;
- }
- parabuf[k++] = '\0';
- if (paraDecimal)
- {
- INTAsiicTorHexInt((const char *)parabuf, ¶[j]);
- }
- else
- {
- AsiicTorHexInt((const char *)parabuf, ¶[j]);
- }
- if (*(cmdbuf + i) == ')')
- {
- break;
- }
- i++; //skip space
- }
- while (findfun->functionname)
- {
- if (funnamecmp(functionname, (unsigned char *)findfun->functionname))
- {
- break;
- }
- findfun++;
- }
- if (findfun->function)
- {
- result = (unsigned int)findfun->function((void *)para[0], (void *)para[1],
- (void *)para[2], (void *)para[3],
- (void *)para[4], (void *)para[5],
- (void *)para[6], (void *)para[7],
- (void *)para[8], (void *)para[9]);
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "%s = 0x%x \r\n", functionname,
- result);
- }
- else
- {
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "Pleas add %s to function list\n",
- functionname);
- }
- }
- void debugvarb(unsigned char *varbbuf)
- {
- unsigned char variablename[32] = {0};
- unsigned char parabuf[32] = {0};
- unsigned int i = 0;
- unsigned int j = 0;
- unsigned int k = 0;
- unsigned int para[5] = {0, 0, 0, 0, 0};
- unsigned int paraDecimal; //decmail flag
- unsigned int readwriteFlag = 0; //
- VAREDITTYPE *findvarb = debugVariableList;
- /*get fun name*/
- while (*(varbbuf + i) != '(')
- {
- variablename[i] = *(varbbuf + i);
- i++;
- }
- i++; //find (
- for (j = 0; j < 5; j++)
- {
- paraDecimal = 1;
- k = 0;
- if ((*(varbbuf + i) == '0')
- && (*(varbbuf + i + 1) == 'x' || *(varbbuf + i + 1) == 'X'))
- {
- i = i + 2;
- paraDecimal = 0;
- }
- while (*(varbbuf + i) != ',' && *(varbbuf + i) != ')')
- {
- parabuf[k++] = *(varbbuf + i);
- i++;
- readwriteFlag = 1;
- }
- parabuf[k++] = '\0';
- if (paraDecimal)
- {
- INTAsiicTorHexInt((const char *)parabuf, ¶[j]);
- }
- else
- {
- AsiicTorHexInt((const char *)parabuf, ¶[j]);
- }
- if (*(varbbuf + i) == ')')
- {
- break;
- }
- i++; //find space
- }
- while (findvarb->variablename)
- {
- if (funnamecmp(variablename, (unsigned char *)findvarb->variablename))
- {
- break;
- }
- findvarb++;
- }
- if (findvarb->variableaddr)
- {
- if (readwriteFlag)
- {
- *(findvarb->variableaddr) = para[0];
- }
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "%s = 0x%x\r\n", variablename,
- *(findvarb->variableaddr));
- }
- else
- {
- FYD_DEBUG_PRINT(VAN_PRINT_HIGH, "Pleas add %s to variable list\r\n",
- variablename);
- }
- }
- void debugcan(unsigned char *buf)
- {
- unsigned char canbuf[32] = {0};
- unsigned char caninf[8] = {0};
- unsigned int i = 1;
- unsigned int j = 0;
- while (*(buf + i) != ')')
- {
- canbuf[j++] = *(buf + i);
- i++;
- }
- for (i = 0; i < 8; i++)
- {
- AsiicTorHexChar((const char *)&canbuf[2 * i], &caninf[i]);
- }
- }
- int cmppare_hear(unsigned char *buf, unsigned char *header ){
- if(buf[0]==header[0]&&buf[1]==header[1]&&buf[2]==header[2]&&buf[3]==header[3]){
- return 1;
- }
- return 0;
- }
- void decodedebugfunction(void)
- {
- unsigned int seekstart;
- unsigned char cmdbuf[64] = {0};
- unsigned int i, j;
- unsigned int cmdflag = 0;
- unsigned int buflen = 0;
- unsigned int buflencon = 0;
- unsigned int dataleft = (debugcmdbuflast + 128 -debugcmdbufheader)%128;
- if(dataleft > 32){
- Van_Device_Printf(VAN_LOG_NOTICE, "debug buffer have:%d\n\r***", dataleft);
- }
- if ((debugcmdbufheader + 6) < debugcmdbuflast)
- {
- seekstart = debugcmdbufheader;
- #ifdef COMPARE_ALIGN
- while (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- {
- if((seekstart + 6) < debugcmdbuflast){
- seekstart++;
- }else{
- break;
- }
- }
- #else
- while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG
- && (seekstart + 6) < debugcmdbuflast)
- {
- seekstart++;
- }
- #endif
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
- #endif
- {
- i = seekstart + 4;
- j = 0;
- buflen = debugcmdbuflast - i;
- buflencon = 0;
- while (debugcmdbuf[i] != ')' && buflencon < buflen)
- {
- cmdbuf[j++] = debugcmdbuf[i++];
- buflencon++;
- }
- if (debugcmdbuf[i] == ')')
- {
- cmdflag = 1;
- cmdbuf[j++] = ')';
- debugcmdbufheader = i;
- }
- i++;
- }
- }
- else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
- && (debugcmdbufheader > debugcmdbuflast))
- {
- seekstart = debugcmdbufheader;
- for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
- {
- #ifdef COMPARE_ALIGN
- if (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG)
- #endif
- {
- seekstart++;
- }
- else
- {
- break;
- }
- }
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
- #endif
- {
- i = (seekstart + 4) % 128;
- j = 0;
- if (i < debugcmdbuflast)
- {
- buflen = debugcmdbuflast - i;
- }
- else
- {
- buflen = debugcmdbuflast + 128 - i;
- }
- buflencon = 0;
- while (debugcmdbuf[i % 128] != ')' && buflencon < buflen)
- {
- cmdbuf[j++] = debugcmdbuf[i % 128];
- buflencon++;
- i++;
- }
- i = i % 128;
- if (debugcmdbuf[i] == ')')
- {
- cmdflag = 1;
- cmdbuf[j++] = ')';
- debugcmdbufheader = i;
- }
- i++;
- }
- else
- {
- seekstart = 0;
- for (; (seekstart + 6) < (debugcmdbuflast);)
- {
- #ifdef COMPARE_ALIGN
- if (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_FUNFLAG)
- #endif
- {
- seekstart++;
- }
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"fun:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_FUNFLAG)
- #endif
- {
- i = (seekstart + 4);
- j = 0;
- if (i < debugcmdbuflast)
- {
- buflen = debugcmdbuflast - i;
- }
- else
- {
- buflen = debugcmdbuflast + 128 - i;
- }
- buflencon = 0;
- while (debugcmdbuf[i] != ')' && buflencon < buflen)
- {
- cmdbuf[j++] = debugcmdbuf[i];
- i++;
- buflencon++;
- }
- if (debugcmdbuf[i] == ')')
- {
- cmdflag = 1;
- cmdbuf[j++] = ')';
- debugcmdbufheader = i;
- }
- i++;
- break;
- }
- }
- }
- }
- if (cmdflag)
- {
- debugcall(cmdbuf);
- }
- }
- void decodedebugvariable(void)
- {
- unsigned int seekstart;
- unsigned char varbuf[64];
- unsigned int i, j;
- unsigned int cmdflag = 0;
- unsigned int buflencon = 0;
- unsigned int buflen = 0;
- if ((debugcmdbufheader + 6) < debugcmdbuflast)
- {
- seekstart = debugcmdbufheader;
- #ifdef COMPARE_ALIGN
- while (0==cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- {
- if((seekstart + 6) < debugcmdbuflast){
- seekstart++;
- }else{
- break;
- }
- }
- #else
- while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG
- && (seekstart + 6) < debugcmdbuflast)
- {
- seekstart++;
- }
- #endif
-
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
- #endif
- {
- i = seekstart + 4;
- j = 0;
- while (debugcmdbuf[i] != ')' && i < debugcmdbuflast) { varbuf[j++] = debugcmdbuf[i++]; }
- if(debugcmdbuf[i] == ')'){
- cmdflag = 1;
- varbuf[j++] = ')';
- debugcmdbufheader = i;
- }
- i++;
- }
- }
- else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
- && (debugcmdbufheader > debugcmdbuflast))
- {
- seekstart = debugcmdbufheader;
- for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
- {
- #ifdef COMPARE_ALIGN
- if (0 == cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG)
- #endif
- {
- seekstart++;
- }
- else
- {
- break;
- }
- }
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
- #endif
-
- {
- i = (seekstart + 4) % 128;
- j = 0;
- if (i < debugcmdbuflast)
- {
- buflen = debugcmdbuflast - i;
- }
- else
- {
- buflen = debugcmdbuflast + 128 - i;
- }
- buflencon = 0;
- while (debugcmdbuf[i % 128] != ')' && buflencon < buflen)
- {
- varbuf[j++] = debugcmdbuf[i % 128];
- i++;
- }
- if(debugcmdbuf[i % 128] == ')'){
- cmdflag = 1;
- varbuf[j++] = ')';
- debugcmdbufheader = i % 128;
- }
- i++;
- }
- else
- {
- seekstart = 0;
- for (; (seekstart + 6) < (debugcmdbuflast);)
- {
- #ifdef COMPARE_ALIGN
- if (0 == cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_VERFLAG)
- #endif
-
- {
- seekstart++;
- }
- #ifdef COMPARE_ALIGN
- if (cmppare_hear(&debugcmdbuf[seekstart],(unsigned char *)"ver:"))
- #else
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_VERFLAG)
- #endif
- {
- i = (seekstart + 4);
- j = 0;
- if (i < debugcmdbuflast)
- {
- buflen = debugcmdbuflast - i;
- }
- else
- {
- buflen = debugcmdbuflast + 128 - i;
- }
- buflencon = 0;
- while (debugcmdbuf[i] != ')'&& buflencon < buflen)
- {
- varbuf[j++] = debugcmdbuf[i];
- i++;
- }
- if(debugcmdbuf[i % 128] == ')'){
- cmdflag = 1;
- varbuf[j++] = ')';
- debugcmdbufheader = i % 128;
- }
- i++;
- break;
- }
- }
- }
- }
- if (cmdflag)
- {
- debugvarb(varbuf);
- }
- }
- void decodedebugCAN(unsigned char *caninf)
- {
- unsigned int seekstart;
- unsigned char canbuf[64];
- unsigned int i, j;
- unsigned int cmdflag = 0;
- if ((debugcmdbufheader + 6) < debugcmdbuflast)
- {
- seekstart = debugcmdbufheader;
- while (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG
- && (seekstart + 6) < debugcmdbuflast)
- {
- seekstart++;
- }
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
- {
- i = seekstart + 4;
- j = 0;
- cmdflag = 1;
- while (debugcmdbuf[i] != ')') { canbuf[j++] = debugcmdbuf[i++]; }
- canbuf[j++] = ')';
- i++;
- debugcmdbufheader = i;
- }
- }
- else if (((debugcmdbufheader + 6) < (debugcmdbuflast + 128))
- && (debugcmdbufheader > debugcmdbuflast))
- {
- seekstart = debugcmdbufheader;
- for (; ((seekstart + 6) < (debugcmdbuflast + 128)) && seekstart < 128;)
- {
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG)
- {
- seekstart++;
- }
- else
- {
- break;
- }
- }
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
- {
- i = (seekstart + 4) % 128;
- j = 0;
- cmdflag = 1;
- while (debugcmdbuf[i % 128] != ')')
- {
- canbuf[j++] = debugcmdbuf[i % 128];
- i++;
- }
- canbuf[j++] = ')';
- i++;
- debugcmdbufheader = i % 128;
- }
- else
- {
- seekstart = 0;
- for (; (seekstart + 6) < (debugcmdbuflast);)
- {
- if (*(unsigned int *)&debugcmdbuf[seekstart] != DEBUG_CANFLAG)
- {
- seekstart++;
- }
- if (*(unsigned int *)&debugcmdbuf[seekstart] == DEBUG_CANFLAG)
- {
- i = (seekstart + 4);
- j = 0;
- cmdflag = 1;
- while (debugcmdbuf[i] != ')')
- {
- canbuf[j++] = debugcmdbuf[i];
- i++;
- }
- canbuf[j++] = ')';
- i++;
- debugcmdbufheader = i;
- break;
- }
- }
- }
- }
- if (cmdflag)
- {
- debugcan(canbuf);
- }
- }
- void addinputtocmdbuf(unsigned char *cmdbuf, unsigned int len)
- {
- unsigned int i;
- for (i = 0; i < len; i++)
- {
- debugcmdbuf[debugcmdbuflast] = *(cmdbuf + i);
- if (debugcmdbuflast < 4)
- *(unsigned int *)&debugcmdbuf[128]
- = *(unsigned int *)&debugcmdbuf[0];
- debugcmdbuflast++;
- if (debugcmdbuflast == 128)
- debugcmdbuflast = 0;
- }
- }
- void addChartoCmdBuf(unsigned char inputchar)
- {
- debugcmdbuf[debugcmdbuflast] = inputchar;
- if (debugcmdbuflast < 4)
- *(unsigned int *)&debugcmdbuf[128] = *(unsigned int *)&debugcmdbuf[0];
- debugcmdbuflast++;
- if (debugcmdbuflast == 128)
- debugcmdbuflast = 0;
- }
- /****************************************************************
- * 函数名: Van_Device_Printf
- * 创建时间: 2021/04/22
- * 创建人: 范义东
- * 函数说明:调试打印接口函数
- * 输入参数: dev 传 NULL 采用本地定义
- devNum 数码
- * 输出参数: *name
- * 返回值 : void
- ****************************************************************/
- void Van_Device_Printf(unsigned int printLevel, const char *cmd, ...)
- {
- char buf[DISBUF_LEN] = {0};
- int buflen = 0;
- __disable_irq();
- if ((gloublePrintLevel & printLevel) || (printLevel==VAN_LOG_ALLPRINT))
- {
- va_list args; //定义一个va_list类型的变量,用来储存单个参数
- va_start(args, cmd); //使args指向可变参数的第一个参数
- vsprintf(buf, cmd, args); //必须用vprintf等带V的
- va_end(args); //结束可变参数的获取
- buflen = strlen((const char *)buf);
- Van_Debug_UART_Send_DMA((unsigned char *)buf, buflen); //将收到的信息发送出
-
- }
- __enable_irq();
- return;
- }
- /****************************************************************
- * 函数名: find_stm32_Peripherals
- * 创建时间: 2021/04/22
- * 创建人: 范义东
- * 函数说明:调试打印接口函数
- * 输入参数: peripheralsAdd 地址指针
-
- * 输出参数: *name
- * 返回值 : void
- ****************************************************************/
- void find_stm32_Peripherals(void *peripheralsAdd, char *name)
- {
-
- }
|