From 005d3b689eadb7e256c35b2bfce391279c603643 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Thu, 16 Nov 2023 16:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84trDataTolog=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8Dpack=5Fdata=E4=B8=80=E5=A4=84bug=20?= =?UTF-8?q?=E5=B1=8F=E8=94=BD=E9=83=A8=E5=88=86LOG=5FHEX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/core.c | 2 +- applications/func/func.c | 44 +++++++++++++++----------------------- applications/main.c | 2 +- applications/tools.c | 2 +- applications/ttTR/ttTR.c | 7 +++--- applications/ttmsg/ttmsg.c | 12 ++++++----- applications/uart_3S.c | 2 +- 7 files changed, 32 insertions(+), 39 deletions(-) diff --git a/applications/core.c b/applications/core.c index 8755bb9..1b8a2b5 100644 --- a/applications/core.c +++ b/applications/core.c @@ -566,7 +566,7 @@ void getAndSendFile() static int index[MAX_KEY_LEN]; char f[cnt][MAX_KEY_LEN]; getFilesToSend(f, index); - for (int var = 0; var < 2; ++var) { + for (int var = 0; var < 1; ++var) { for (int i = cnt-1; i > -1; i--)//倒序发送 { LOG_D("f[%d]=%s",i,f[i]); diff --git a/applications/func/func.c b/applications/func/func.c index 7603c5d..987c005 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -42,7 +42,7 @@ void ack(void) int trDataTolog(uint8_t *din, size_t len, uint8_t isTx) { // return RT_EOK; - char fn[60] = "\n"; + char fn[60]; initDataLogPath(fn); int fd = open(fn, O_WRONLY | O_CREAT | O_APPEND); @@ -70,10 +70,12 @@ int trDataTolog(uint8_t *din, size_t len, uint8_t isTx) strcat(log,isTx?" [T]: ":" [R]: "); write(fd, log, strlen(log)); - len = cryp_data(din, len, din);//加密数据 - bytes2str(din, len, 16, " ", din); - len = strlen(din); - int rst = write(fd, din, len); + uint8_t tmp[1024]; + len = cryp_data(din, len, tmp);//加密数据 + bytes2str(tmp, len, 16, "", tmp); + len = strlen(tmp); + + int rst = write(fd, tmp, len); if (rst != len) { LOG_E("write to file %s failed!", fn); @@ -217,7 +219,7 @@ void upSend_thread_entry(void* parameter) #else size_t rst = packMsg(&cfg, tmpmsg->data, msg->len, dout);//packMsgs #endif - LOG_HEX("upSend", 27, dout, rst); +// LOG_HEX("upSend", 27, dout, rst); if (rst) { if (sendMsg(dout, rst) == RT_EOK) @@ -1022,7 +1024,7 @@ void clearAllData() */ void reSend(uint8_t *din, uint8_t len) { -//file example: sd/rxdata/2023_08_23/23_08_23_08_31_44_14.bin +//file example: sd/cdata/2023_08_23/23_08_23_08_31_44_14.bin LOG_I("FUNC = resend file"); char f[60]=""; strcat(f,ROOT_PATH_DATA); @@ -1034,6 +1036,10 @@ void reSend(uint8_t *din, uint8_t len) strcat(f,"/"); strcat(f,str); strcat(f,".bin"); + if (!getFileSize(f)) { + LOG_W("'%f' is empty."); + return; + } LOG_D("resend '%s'",f); @@ -1687,12 +1693,7 @@ void parseRS232(uint8_t *din, size_t len) ndin[cnt]='\0'; uint8_t tmp[200]; size_t ncnt = str2Byte(ndin, 2, 16, tmp)-1;//结尾有\r\n - if (n>1) LOG_HEX("frame",16,tmp,ncnt); -// if (chk3SDataValid(tmp, ncnt) != RT_EOK) { -//#ifdef CHECK_3S_DATA -// return; -//#endif -// } +// if (n>1) LOG_HEX("frame",16,tmp,ncnt); parse3SData(tmp,ncnt); } } @@ -1700,14 +1701,7 @@ void parseRS232(uint8_t *din, size_t len) { //bin LOG_I("type = BIN"); - - for (size_t var = 0; var < len; var=var+200) { - char tmp[len*4]; - bytes2str(din+var, (len-var)>200?200:(len-var), 16, " ", tmp); - trDataTolog(tmp, strlen(tmp), 0); - } -// trDataTolog(bytes2str(din, len, 16, " ", tmp), strlen(tmp), 0); - + trDataTolog(din, len, 0); uint16_t index[20]; size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index); @@ -1722,12 +1716,7 @@ void parseRS232(uint8_t *din, size_t len) uint8_t ndin[MAX_LEN_3S]; int cnt=(i+11) LOG_HEX("frame",16,ndin,cnt); -// if (chk3SDataValid(ndin, cnt) != RT_EOK) { -//#ifdef CHECK_3S_DATA -// return; -//#endif -// } +// if (n>1) LOG_HEX("frame",16,ndin,cnt); parse3SData(ndin,cnt); } } @@ -1918,6 +1907,7 @@ size_t decryptCdata(const char *fin, uint8_t *dout) /** * 加密待发的缓存文件,覆盖源文件 + * 当文件内容不再更新时调用此文件 * @param f 缓存文件 */ void cryptCdata(const char *f) diff --git a/applications/main.c b/applications/main.c index c5ada8a..6fdfa15 100644 --- a/applications/main.c +++ b/applications/main.c @@ -86,7 +86,7 @@ void show_version(void) char str[30]; uint8_t t[10]; size_t len=time2Byte(t); - rt_kprintf("SW Version: %s, build-%s\n","2.7d",bytes2str(t, 3, 10, "", str)); + rt_kprintf("SW Version: %s, build-%s\n","2.8d",bytes2str(t, 3, 10, "", str)); } MSH_CMD_EXPORT(show_version,显示版本号); diff --git a/applications/tools.c b/applications/tools.c index b4de68d..3c75b75 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -231,7 +231,7 @@ char *int2str(int num, char *str, int radix) */ char *bytes2str(uint8_t *din, size_t count, int radix, char *sep, char *str) { - char rst[600+10]="";//=malloc(512); + char rst[1024]="";//=malloc(512); for (size_t i = 0; i < count; i++) { char s[10]=""; diff --git a/applications/ttTR/ttTR.c b/applications/ttTR/ttTR.c index fee6c24..fa1afb6 100644 --- a/applications/ttTR/ttTR.c +++ b/applications/ttTR/ttTR.c @@ -290,9 +290,10 @@ int sendMsg(const rt_uint8_t *msg, size_t len) #endif // return RT_EOK; //已发送数据存入log文件 - char str[600]; - bytes2str(msg, len, 16, " ", str); - trDataTolog(str, strlen(str), 1); +// char str[600]; +// bytes2str(msg, len, 16, " ", str); +// trDataTolog(str, strlen(str), 1); + trDataTolog(msg, len, 1); return RT_EOK; diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 7796398..ad71640 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -373,6 +373,7 @@ rt_uint8_t pack_data(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ uint8_t decryptData[2048]; size_t file_size = decryptCdata(fin, decryptData); +// LOG_HEX("de",16,decryptData,file_size); if (!file_size) { LOG_E("failed to decrypt"); return 0; @@ -426,7 +427,7 @@ rt_uint8_t pack_data(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ } rt_memset(buffer, 0x00, flen); - rt_memcpy(buffer, decryptData, block_size); + rt_memcpy(buffer, decryptData+i, block_size); uint8_t index = (i / flen); cfg.fcurpiece[0] = index + 1; @@ -434,7 +435,7 @@ rt_uint8_t pack_data(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ static uint8_t tmp[200]; uint8_t len = cryptSingleMsg(buffer, block_size, tmp); uint8_t col = packMsg(&cfg, tmp, len, dout[index]); - +// LOG_HEX("de",16,dout[index],col); arrLen[index] = col; } @@ -552,15 +553,16 @@ void recTT_thread_entry() } readTCPData(bf, msg.size); LOG_I("%d Bytes received from TT",msg.size); - LOG_HEX("TTrec", 27, bf, msg.size); +// LOG_HEX("TTrec", 27, bf, msg.size); //复制数据 // memcpy(bf,msg.data,msg.size); dlen=msg.size; //存入log - char tmp[1024]="";//接收的数据不会很长,200足矣 - trDataTolog(bytes2str(bf, dlen, 16, " ", tmp), strlen(tmp), 0); +// char tmp[1024]="";//接收的数据不会很长,200足矣 +// trDataTolog(bytes2str(bf, dlen, 16, " ", tmp), strlen(tmp), 0); + trDataTolog(bf,dlen, 0); //此处调用处理函数 parseTTData(bf,dlen); } diff --git a/applications/uart_3S.c b/applications/uart_3S.c index 96c26e4..abd2c98 100644 --- a/applications/uart_3S.c +++ b/applications/uart_3S.c @@ -102,7 +102,7 @@ static void serial_thread_entry(void *parameter) continue; } LOG_I("%d Bytes received from RS232",rx_length); - LOG_HEX("232rx:",16,rx_buffer,rx_length);//print what received. +// LOG_HEX("232rx:",16,rx_buffer,rx_length);//print what received. parseRS232(rx_buffer, rx_length); }