完善trDataTolog逻辑

修复pack_data一处bug
屏蔽部分LOG_HEX
This commit is contained in:
CSSC-WORK\murmur 2023-11-16 16:44:26 +08:00
parent b65fb0a66a
commit 005d3b689e
7 changed files with 32 additions and 39 deletions

View File

@ -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]);

View File

@ -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+1<n)?index[i+1]-index[i]:len-index[i];
memcpy(ndin,din+index[i],cnt);
if (n>1) 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)

View File

@ -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,);

View File

@ -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]="";

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}