完善trDataTolog逻辑
修复pack_data一处bug 屏蔽部分LOG_HEX
This commit is contained in:
parent
b65fb0a66a
commit
005d3b689e
@ -566,7 +566,7 @@ void getAndSendFile()
|
|||||||
static int index[MAX_KEY_LEN];
|
static int index[MAX_KEY_LEN];
|
||||||
char f[cnt][MAX_KEY_LEN];
|
char f[cnt][MAX_KEY_LEN];
|
||||||
getFilesToSend(f, index);
|
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--)//倒序发送
|
for (int i = cnt-1; i > -1; i--)//倒序发送
|
||||||
{
|
{
|
||||||
LOG_D("f[%d]=%s",i,f[i]);
|
LOG_D("f[%d]=%s",i,f[i]);
|
||||||
|
@ -42,7 +42,7 @@ void ack(void)
|
|||||||
int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
|
int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
|
||||||
{
|
{
|
||||||
// return RT_EOK;
|
// return RT_EOK;
|
||||||
char fn[60] = "\n";
|
char fn[60];
|
||||||
initDataLogPath(fn);
|
initDataLogPath(fn);
|
||||||
|
|
||||||
int fd = open(fn, O_WRONLY | O_CREAT | O_APPEND);
|
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]: ");
|
strcat(log,isTx?" [T]: ":" [R]: ");
|
||||||
write(fd, log, strlen(log));
|
write(fd, log, strlen(log));
|
||||||
|
|
||||||
len = cryp_data(din, len, din);//加密数据
|
uint8_t tmp[1024];
|
||||||
bytes2str(din, len, 16, " ", din);
|
len = cryp_data(din, len, tmp);//加密数据
|
||||||
len = strlen(din);
|
bytes2str(tmp, len, 16, "", tmp);
|
||||||
int rst = write(fd, din, len);
|
len = strlen(tmp);
|
||||||
|
|
||||||
|
int rst = write(fd, tmp, len);
|
||||||
if (rst != len)
|
if (rst != len)
|
||||||
{
|
{
|
||||||
LOG_E("write to file %s failed!", fn);
|
LOG_E("write to file %s failed!", fn);
|
||||||
@ -217,7 +219,7 @@ void upSend_thread_entry(void* parameter)
|
|||||||
#else
|
#else
|
||||||
size_t rst = packMsg(&cfg, tmpmsg->data, msg->len, dout);//packMsgs
|
size_t rst = packMsg(&cfg, tmpmsg->data, msg->len, dout);//packMsgs
|
||||||
#endif
|
#endif
|
||||||
LOG_HEX("upSend", 27, dout, rst);
|
// LOG_HEX("upSend", 27, dout, rst);
|
||||||
if (rst)
|
if (rst)
|
||||||
{
|
{
|
||||||
if (sendMsg(dout, rst) == RT_EOK)
|
if (sendMsg(dout, rst) == RT_EOK)
|
||||||
@ -1022,7 +1024,7 @@ void clearAllData()
|
|||||||
*/
|
*/
|
||||||
void reSend(uint8_t *din, uint8_t len)
|
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");
|
LOG_I("FUNC = resend file");
|
||||||
char f[60]="";
|
char f[60]="";
|
||||||
strcat(f,ROOT_PATH_DATA);
|
strcat(f,ROOT_PATH_DATA);
|
||||||
@ -1034,6 +1036,10 @@ void reSend(uint8_t *din, uint8_t len)
|
|||||||
strcat(f,"/");
|
strcat(f,"/");
|
||||||
strcat(f,str);
|
strcat(f,str);
|
||||||
strcat(f,".bin");
|
strcat(f,".bin");
|
||||||
|
if (!getFileSize(f)) {
|
||||||
|
LOG_W("'%f' is empty.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
LOG_D("resend '%s'",f);
|
LOG_D("resend '%s'",f);
|
||||||
|
|
||||||
|
|
||||||
@ -1687,12 +1693,7 @@ void parseRS232(uint8_t *din, size_t len)
|
|||||||
ndin[cnt]='\0';
|
ndin[cnt]='\0';
|
||||||
uint8_t tmp[200];
|
uint8_t tmp[200];
|
||||||
size_t ncnt = str2Byte(ndin, 2, 16, tmp)-1;//结尾有\r\n
|
size_t ncnt = str2Byte(ndin, 2, 16, tmp)-1;//结尾有\r\n
|
||||||
if (n>1) LOG_HEX("frame",16,tmp,ncnt);
|
// if (n>1) LOG_HEX("frame",16,tmp,ncnt);
|
||||||
// if (chk3SDataValid(tmp, ncnt) != RT_EOK) {
|
|
||||||
//#ifdef CHECK_3S_DATA
|
|
||||||
// return;
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
parse3SData(tmp,ncnt);
|
parse3SData(tmp,ncnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1700,14 +1701,7 @@ void parseRS232(uint8_t *din, size_t len)
|
|||||||
{
|
{
|
||||||
//bin
|
//bin
|
||||||
LOG_I("type = BIN");
|
LOG_I("type = BIN");
|
||||||
|
trDataTolog(din, len, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t index[20];
|
uint16_t index[20];
|
||||||
size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index);
|
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];
|
uint8_t ndin[MAX_LEN_3S];
|
||||||
int cnt=(i+1<n)?index[i+1]-index[i]:len-index[i];
|
int cnt=(i+1<n)?index[i+1]-index[i]:len-index[i];
|
||||||
memcpy(ndin,din+index[i],cnt);
|
memcpy(ndin,din+index[i],cnt);
|
||||||
if (n>1) LOG_HEX("frame",16,ndin,cnt);
|
// if (n>1) LOG_HEX("frame",16,ndin,cnt);
|
||||||
// if (chk3SDataValid(ndin, cnt) != RT_EOK) {
|
|
||||||
//#ifdef CHECK_3S_DATA
|
|
||||||
// return;
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
parse3SData(ndin,cnt);
|
parse3SData(ndin,cnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1918,6 +1907,7 @@ size_t decryptCdata(const char *fin, uint8_t *dout)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 加密待发的缓存文件,覆盖源文件
|
* 加密待发的缓存文件,覆盖源文件
|
||||||
|
* 当文件内容不再更新时调用此文件
|
||||||
* @param f 缓存文件
|
* @param f 缓存文件
|
||||||
*/
|
*/
|
||||||
void cryptCdata(const char *f)
|
void cryptCdata(const char *f)
|
||||||
|
@ -86,7 +86,7 @@ void show_version(void)
|
|||||||
char str[30];
|
char str[30];
|
||||||
uint8_t t[10];
|
uint8_t t[10];
|
||||||
size_t len=time2Byte(t);
|
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,显示版本号);
|
MSH_CMD_EXPORT(show_version,显示版本号);
|
||||||
|
@ -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 *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++)
|
for (size_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
char s[10]="";
|
char s[10]="";
|
||||||
|
@ -290,9 +290,10 @@ int sendMsg(const rt_uint8_t *msg, size_t len)
|
|||||||
#endif
|
#endif
|
||||||
// return RT_EOK;
|
// return RT_EOK;
|
||||||
//已发送数据存入log文件
|
//已发送数据存入log文件
|
||||||
char str[600];
|
// char str[600];
|
||||||
bytes2str(msg, len, 16, " ", str);
|
// bytes2str(msg, len, 16, " ", str);
|
||||||
trDataTolog(str, strlen(str), 1);
|
// trDataTolog(str, strlen(str), 1);
|
||||||
|
trDataTolog(msg, len, 1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
|
||||||
|
@ -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];
|
uint8_t decryptData[2048];
|
||||||
size_t file_size = decryptCdata(fin, decryptData);
|
size_t file_size = decryptCdata(fin, decryptData);
|
||||||
|
// LOG_HEX("de",16,decryptData,file_size);
|
||||||
if (!file_size) {
|
if (!file_size) {
|
||||||
LOG_E("failed to decrypt");
|
LOG_E("failed to decrypt");
|
||||||
return 0;
|
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_memset(buffer, 0x00, flen);
|
||||||
rt_memcpy(buffer, decryptData, block_size);
|
rt_memcpy(buffer, decryptData+i, block_size);
|
||||||
uint8_t index = (i / flen);
|
uint8_t index = (i / flen);
|
||||||
cfg.fcurpiece[0] = index + 1;
|
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];
|
static uint8_t tmp[200];
|
||||||
uint8_t len = cryptSingleMsg(buffer, block_size, tmp);
|
uint8_t len = cryptSingleMsg(buffer, block_size, tmp);
|
||||||
uint8_t col = packMsg(&cfg, tmp, len, dout[index]);
|
uint8_t col = packMsg(&cfg, tmp, len, dout[index]);
|
||||||
|
// LOG_HEX("de",16,dout[index],col);
|
||||||
arrLen[index] = col;
|
arrLen[index] = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,15 +553,16 @@ void recTT_thread_entry()
|
|||||||
}
|
}
|
||||||
readTCPData(bf, msg.size);
|
readTCPData(bf, msg.size);
|
||||||
LOG_I("%d Bytes received from TT",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);
|
// memcpy(bf,msg.data,msg.size);
|
||||||
dlen=msg.size;
|
dlen=msg.size;
|
||||||
//存入log
|
//存入log
|
||||||
char tmp[1024]="";//接收的数据不会很长,200足矣
|
// char tmp[1024]="";//接收的数据不会很长,200足矣
|
||||||
trDataTolog(bytes2str(bf, dlen, 16, " ", tmp), strlen(tmp), 0);
|
// trDataTolog(bytes2str(bf, dlen, 16, " ", tmp), strlen(tmp), 0);
|
||||||
|
trDataTolog(bf,dlen, 0);
|
||||||
//此处调用处理函数
|
//此处调用处理函数
|
||||||
parseTTData(bf,dlen);
|
parseTTData(bf,dlen);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ static void serial_thread_entry(void *parameter)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOG_I("%d Bytes received from RS232",rx_length);
|
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);
|
parseRS232(rx_buffer, rx_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user