修复isInByte数据类型错误导致索引不能大于255的bug

修复过长BIN类型数据使用trDataTolog写数据异常的bug
修改系统时钟为50->100MHz,msg_pool大小为256B->4k,串口buffer为4->40k
更新版本号为2.6d
This commit is contained in:
CSSC-WORK\murmur 2023-10-27 10:15:22 +08:00
parent eb2da0915e
commit 3169b24a24
8 changed files with 36 additions and 23 deletions

View File

@ -198,7 +198,7 @@ static void serial485_thread_entry(void *parameter)
struct rx_msg msg; struct rx_msg msg;
rt_err_t result; rt_err_t result;
rt_uint32_t rx_length=0;//单次收到的数据长度 rt_uint32_t rx_length=0;//单次收到的数据长度
static char rx_buffer[RT_SERIAL_RB_BUFSZ/4 + 1]; static char rx_buffer[1024 + 1];
while (1) while (1)
{ {

View File

@ -1633,7 +1633,7 @@ void parseRS232(uint8_t *din, size_t len)
trDataTolog(din, len, 0); trDataTolog(din, len, 0);
uint8_t index[10]; uint16_t index[10];
uint8_t tmpHead[]={0x35, 0x41, 0x41, 0x35}; uint8_t tmpHead[]={0x35, 0x41, 0x41, 0x35};
size_t n=isInByte(din, len, tmpHead, sizeof(tmpHead), index); size_t n=isInByte(din, len, tmpHead, sizeof(tmpHead), index);
// LOG_D("n=%d",n); // LOG_D("n=%d",n);
@ -1663,20 +1663,26 @@ void parseRS232(uint8_t *din, size_t len)
{ {
//bin //bin
LOG_I("type = BIN"); LOG_I("type = BIN");
char tmp[200]="";
trDataTolog(bytes2str(din, len, 16, " ", tmp), strlen(tmp), 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);
uint8_t index[10]; uint16_t index[20];
size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index); size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index);
if (!n) { if (!n) {
LOG_W("RS232中无匹配帧[BIN]"); LOG_W("RS232中无匹配帧[BIN]");
return; return;
} }
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
{ {
//按帧头分割 //按帧头分割
uint8_t ndin[200]; uint8_t ndin[300];
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);

View File

@ -165,6 +165,6 @@ void updateDebuglogName(void)
isToUpdate = 1; isToUpdate = 1;
} }
MSH_CMD_EXPORT(updateDebuglogName,debug日志的文件名); //MSH_CMD_EXPORT(updateDebuglogName,更新debug日志的文件名);
//MSH_CMD_EXPORT(initLogFileBackend,initLogFileBackend); MSH_CMD_EXPORT(initLogFileBackend,initLogFileBackend);
INIT_COMPONENT_EXPORT(initLogFileBackend); INIT_COMPONENT_EXPORT(initLogFileBackend);

View File

@ -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.55d",bytes2str(t, 3, 10, "", str)); rt_kprintf("SW Version: %s, build-%s\n","2.6d",bytes2str(t, 3, 10, "", str));
} }
MSH_CMD_EXPORT(show_version,); 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 *bytes2str(uint8_t *din, size_t count, int radix, char *sep, char *str)
{ {
char rst[600]="";//=malloc(512); char rst[600+10]="";//=malloc(512);
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
char s[10]=""; char s[10]="";
@ -350,19 +350,20 @@ uint8_t bccCRC(uint8_t *din, size_t count)
* @param dout * @param dout
* @return int * @return int
*/ */
size_t isInByte(uint8_t *din, size_t len, uint8_t *s, size_t slen, uint8_t *dout) size_t isInByte(uint8_t *din, size_t len, uint8_t *s, size_t slen, uint16_t *dout)
{ {
size_t cnt = 0; size_t cnt = 0;
uint8_t tmp[len]; uint16_t tmp[20];
for (size_t i = 0; i < len - slen+1; i++) for (size_t i = 0; i < len - slen+1; i++)
{ {
if (memcmp(din + i, s, slen) == 0) if (memcmp(din + i, s, slen) == 0)
{ {
tmp[cnt++] = i; // tmp[cnt++] = i;
dout[cnt++]=i;
i = i+slen-1; i = i+slen-1;
} }
} }
memcpy(dout,tmp,cnt); // memcpy(dout,tmp,cnt*sizeof(uint16_t));
return cnt; return cnt;
} }

View File

@ -52,6 +52,7 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
rt_err_t result; rt_err_t result;
static rt_size_t cachecnt=0; static rt_size_t cachecnt=0;
#ifdef CHECK_LEN
cachecnt += size; cachecnt += size;
if (cachecnt < MIN_FRAME_LEN) { if (cachecnt < MIN_FRAME_LEN) {
LOG_W("not enough data, cached and waiting...");//处理半包 LOG_W("not enough data, cached and waiting...");//处理半包
@ -59,7 +60,10 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
} }
msg.dev = dev; msg.dev = dev;
msg.size = cachecnt; msg.size = cachecnt;
#else
msg.dev = dev;
msg.size = size;
#endif
result = rt_mq_send(&rx_mq, &msg, sizeof(msg)); result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
if ( result == -RT_EFULL) if ( result == -RT_EFULL)
{ {
@ -67,6 +71,7 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
LOG_W("message queue full"); LOG_W("message queue full");
} }
cachecnt = 0; cachecnt = 0;
return result; return result;
} }
@ -78,7 +83,7 @@ static void serial_thread_entry(void *parameter)
{ {
// struct rx_msg msg; // struct rx_msg msg;
rt_err_t result; rt_err_t result;
rt_uint32_t rx_length=0;//单次收到的数据长度 size_t rx_length=0;//单次收到的数据长度
static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1]; static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
while (1) while (1)
@ -93,7 +98,7 @@ static void serial_thread_entry(void *parameter)
/* 从串口读取数据*/ /* 从串口读取数据*/
rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size); rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
if (!rx_length) { if (!rx_length) {
LOG_W("read from RS232 error"); // LOG_W("read from RS232 error,should be %d Bytes",msg.size);
continue; continue;
} }
LOG_I("%d Bytes received from RS232",rx_length); LOG_I("%d Bytes received from RS232",rx_length);
@ -108,7 +113,7 @@ static int uart_dma_sample(int argc, char *argv[])
{ {
rt_err_t ret = RT_EOK; rt_err_t ret = RT_EOK;
char uart_name[RT_NAME_MAX]; char uart_name[RT_NAME_MAX];
static char msg_pool[256]; static char msg_pool[256*4*2];
char str[] = {0x01,0x03,0x00,0x00,0x00,0x1d,0x85,0xc3}; char str[] = {0x01,0x03,0x00,0x00,0x00,0x1d,0x85,0xc3};
if (argc == 2) if (argc == 2)
@ -172,7 +177,8 @@ static int uart_dma_sample(int argc, char *argv[])
} }
/* 导出到 msh 命令列表中 */ /* 导出到 msh 命令列表中 */
//MSH_CMD_EXPORT(uart_dma_sample, uart device dma sample); //MSH_CMD_EXPORT(uart_dma_sample, uart device dma sample);
INIT_COMPONENT_EXPORT(uart_dma_sample); //INIT_COMPONENT_EXPORT(uart_dma_sample);
INIT_APP_EXPORT(uart_dma_sample);
/** /**
* 3S * 3S

View File

@ -44,7 +44,7 @@ extern "C"
#define BSP_CLOCK_SOURCE ("HSI") #define BSP_CLOCK_SOURCE ("HSI")
#define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)0) #define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)0)
#define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)50) #define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)100)
/*-------------------------- CLOCK CONFIG END --------------------------*/ /*-------------------------- CLOCK CONFIG END --------------------------*/

View File

@ -105,7 +105,7 @@
#define RT_USING_SERIAL #define RT_USING_SERIAL
#define RT_USING_SERIAL_V1 #define RT_USING_SERIAL_V1
#define RT_SERIAL_USING_DMA #define RT_SERIAL_USING_DMA
#define RT_SERIAL_RB_BUFSZ 4096 #define RT_SERIAL_RB_BUFSZ 4096*10
#define RT_USING_PHY #define RT_USING_PHY
#define RT_USING_PIN #define RT_USING_PIN
#define RT_USING_ADC #define RT_USING_ADC
@ -204,9 +204,9 @@
#define ULOG_ASSERT_ENABLE #define ULOG_ASSERT_ENABLE
#define ULOG_LINE_BUF_SIZE 256 #define ULOG_LINE_BUF_SIZE 256
//#define ULOG_USING_ASYNC_OUTPUT //#define ULOG_USING_ASYNC_OUTPUT
#define ULOG_ASYNC_OUTPUT_BUF_SIZE 1024*20 #define ULOG_ASYNC_OUTPUT_BUF_SIZE 1024*5
#define ULOG_ASYNC_OUTPUT_BY_THREAD #define ULOG_ASYNC_OUTPUT_BY_THREAD
#define ULOG_ASYNC_OUTPUT_THREAD_STACK 10240 #define ULOG_ASYNC_OUTPUT_THREAD_STACK 1024*5
#define ULOG_ASYNC_OUTPUT_THREAD_PRIORITY 29 #define ULOG_ASYNC_OUTPUT_THREAD_PRIORITY 29
/* log format */ /* log format */