| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108 |
- /******************************************************************
- * 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_NOTICE; //
- 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)
- {
- 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)
- {
-
- }
|