From 98a895fb3e7a50f6604a57446b9f8ca71f24bbf5 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 8 Sep 2023 16:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0485=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=B8=8D=E9=87=87=E7=94=A8mutex=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4rtc=E9=97=B9=E9=92=9F?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=9B=B4=E6=96=B0debug=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6=E5=90=8D=20func.c=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E9=87=8D=E5=A4=8D=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20func.h=20=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E5=AE=8F?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=B3=A8=E9=87=8A=20getinfo.c=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DTT=E5=85=B3=E6=9C=BA=E5=90=8E=E6=9C=AA=E5=A4=8D?= =?UTF-8?q?=E4=BD=8D=E7=8A=B6=E6=80=81=E4=BF=A1=E6=81=AF=E7=9A=84bug=20log?= =?UTF-8?q?2file.c=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0debug=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6=E5=90=8D=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20ttTR.c=20=E5=A2=9E=E5=8A=A0msg=5Fpool=E5=8F=8ATTRx=5FMSG?= =?UTF-8?q?=E7=9A=84=E5=A4=A7=E5=B0=8F=20=E5=A2=9E=E5=8A=A0ULOG=5FASYNC=5F?= =?UTF-8?q?OUTPUT=5FBUF=5FSIZE=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/RS_485.c | 21 ++++++------- applications/alarmer.c | 24 +++++++++----- applications/func/func.c | 26 +++++++-------- applications/func/func.h | 12 +++---- applications/getinfo.c | 8 ++++- applications/log2file.c | 68 +++++++++++++++++++++++++++++++--------- applications/ttTR/ttTR.c | 2 +- applications/ttTR/ttTR.h | 2 +- rtconfig.h | 2 +- 9 files changed, 109 insertions(+), 56 deletions(-) diff --git a/applications/RS_485.c b/applications/RS_485.c index efaae2d..c1c6933 100644 --- a/applications/RS_485.c +++ b/applications/RS_485.c @@ -95,9 +95,11 @@ typedef struct{ }BATT_INFO; static BATT_INFO batt; +static int readyToSend=1; static void timer485_cb() { // rt_mutex_release(sendcmd); + readyToSend = 1; } static int b2v(uint8_t *din) { @@ -167,9 +169,9 @@ static void T485_thread_entry(void *parameter) while (1) { //发送指令 -// if (rt_mutex_take(sendcmd, RT_WAITING_FOREVER) == RT_EOK) - if(rt_mutex_take(sendcmd, rt_tick_from_millisecond(1*60*1000)) != RT_EOK) + if (readyToSend) { + readyToSend = 0; uint8_t cmd[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x1d, 0x85, 0xc3 }; //send cmd @@ -178,7 +180,7 @@ static void T485_thread_entry(void *parameter) rt_pin_write(TR485_RE, PIN_LOW); LOG_D("send 485"); } -// rt_thread_mdelay(60*1000); + rt_thread_mdelay(10*1000); } } @@ -289,14 +291,11 @@ static int uart485_dma_sample(int argc, char *argv[]) ret = RT_ERROR; } - sendcmd = rt_mutex_create("reqBatt", RT_IPC_FLAG_FIFO); - rt_mutex_take(sendcmd, RT_WAITING_FOREVER); - LOG_I("RS485 inited ok"); -// timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(1*60*1000), RT_TIMER_FLAG_PERIODIC); -// -// /* 启动定时器1 */ -// if (timer485 != RT_NULL) -// rt_timer_start(timer485); + timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(1*60*1000), RT_TIMER_FLAG_PERIODIC); + + /* 启动定时器1 */ + if (timer485 != RT_NULL) + rt_timer_start(timer485); return ret; } diff --git a/applications/alarmer.c b/applications/alarmer.c index 8c7ad12..01d2375 100644 --- a/applications/alarmer.c +++ b/applications/alarmer.c @@ -99,6 +99,15 @@ void poTT2_callback(rt_alarm_t alarm, time_t timestamp) timerIsReady(); initTT(); } +/** + * 定时更新debug文件名 + * @param alarm + * @param timestamp + */ +void updatelog_callback(rt_alarm_t alarm, time_t timestamp) +{ + updateDebuglogName(); +} void addDefaultAlarm() { @@ -119,13 +128,13 @@ void addDefaultAlarm() setup.wktime.tm_min = 0; //p_tm.tm_min; setup.wktime.tm_sec = 0; //p_tm.tm_sec; - setup.wktime.tm_min = 15; //每小时的1刻钟启动发送 + setup.wktime.tm_min = 1; //每小时的1刻钟启动发送 if (RT_NULL != alarm) { rt_alarm_delete(alarm); // } - alarm = rt_alarm_create(poTT2_callback, &setup); + alarm = rt_alarm_create(updatelog_callback, &setup); if (alarm != RT_NULL) { rt_alarm_start(alarm); @@ -136,6 +145,7 @@ void addDefaultAlarm() } } +#define BOOT_PER_HOUR #ifdef BOOT_PER_HOUR INIT_APP_EXPORT(addDefaultAlarm); #endif @@ -157,7 +167,7 @@ void getAllAlarm() { rt_list_t *next; rt_alarm_t alarm; - cnt = indexBegin; + cnt = 0; for (next = _container.head.next; next != &_container.head; next = next->next) { @@ -172,7 +182,7 @@ void getAllAlarm() void clearAlarm(void) { getAllAlarm(); - for (size_t i = indexBegin; i < cnt; ++i) + for (size_t i = 0; i < cnt-indexBegin; ++i) { rt_alarm_delete(a[i]); } @@ -184,7 +194,7 @@ void clearAlarm(void) void stopAlarm() { getAllAlarm(); - for (size_t i = indexBegin; i < cnt; ++i) + for (size_t i = 0; i < cnt-indexBegin; ++i) { rt_alarm_stop(a[i]); } @@ -196,7 +206,7 @@ void stopAlarm() void startAlarm() { getAllAlarm(); - for (size_t i = indexBegin; i < cnt; ++i) + for (size_t i = 0; i < cnt-indexBegin; ++i) { rt_alarm_start(a[i]); } @@ -274,7 +284,7 @@ int isInWindowZone() getAllAlarm(); int rst = 0; - for (size_t i = indexBegin; i < cnt; i+=2) + for (size_t i = 0; i < cnt-indexBegin; i+=2) { if(isInAlarm(a[i], a[i+1])) { diff --git a/applications/func/func.c b/applications/func/func.c index ac798f5..864ee42 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -305,7 +305,7 @@ void selfTest(void) rst[p++] = bccCRC(rst+2, p-1); ////校验位为1个字节,采用异或运算,从指令的第3个字节开始,到奇偶校验位的前一个字节结束 rst[p++] = 0xED; //结束位 - LOG_HEX("selfTestRes",16,rst,p); +// LOG_HEX("selfTestRes",16,rst,p); //发送结果 upSend(rst,p); } @@ -1595,12 +1595,12 @@ 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 - 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); +// if (chk3SDataValid(tmp, ncnt) != RT_EOK) { +//#ifdef CHECK_3S_DATA +// return; +//#endif +// } parse3SData(tmp,ncnt); } } @@ -1624,12 +1624,12 @@ void parseRS232(uint8_t *din, size_t len) uint8_t ndin[200]; int cnt=(i+11) LOG_HEX("frame",16,ndin,cnt); +// if (chk3SDataValid(ndin, cnt) != RT_EOK) { +//#ifdef CHECK_3S_DATA +// return; +//#endif +// } parse3SData(ndin,cnt); } } diff --git a/applications/func/func.h b/applications/func/func.h index 0f45aff..0905ce9 100644 --- a/applications/func/func.h +++ b/applications/func/func.h @@ -68,14 +68,14 @@ enum #define _CMD_RETRY_DATA 0x7006 //数据重发 #define _CFG_UPDATE_CFG 0x7007 //更新、回传配置信息 -#define _INFO_BATT 0x8888 -#define _INFO_SIGNAL 0x6666 +#define _INFO_BATT 0x8888 //获取电池信息 +#define _INFO_SIGNAL 0x6666//获取历史信号质量 //3S -#define _CMD_DEPTH_REQUEST 0x0601 -#define _CMD_RTC_REQUEST 0x410F -#define _CMD_SET_RTC 0x4006 -#define _INFO_RTC_ANSWER 0x4016 +#define _CMD_DEPTH_REQUEST 0x0601//请求深度 +#define _CMD_RTC_REQUEST 0x410F//请求3s的RTC +#define _CMD_SET_RTC 0x4006 //设置3s的RTC +#define _INFO_RTC_ANSWER 0x4016 //RTC查询回复 //需补充信息 #define _INFO_DEPTH_ANSWER 0x0608 //深度回复 diff --git a/applications/getinfo.c b/applications/getinfo.c index d6833b2..8ebfdba 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -462,7 +462,13 @@ void repGetTT_thread_entry(void* parameter) rulecheck(); rt_thread_mdelay(5 * 1000);//间隔3s更新一次数据 } - rt_memset(rstInfo,0x3f,RST_LEN);//初始化 + rt_memset(rstInfo,0x3f,RST_LEN);//复位 + strcpy(TTinfo->sim,"-"); + strcpy(TTinfo->xh,"-"); + strcpy(TTinfo->jh,"-"); + strcpy(TTinfo->jd,"-"); + strcpy(TTinfo->wd,"-"); + strcpy(TTinfo->ele,"-"); } /** diff --git a/applications/log2file.c b/applications/log2file.c index 8f83190..da01d72 100644 --- a/applications/log2file.c +++ b/applications/log2file.c @@ -77,15 +77,18 @@ static rt_bool_t sys_log_file_backend_filter(struct ulog_backend *backend, rt_ui * @retval None. * @note None. */ -void sys_log_file_backend_init(void) +static char logfilename[50];// = "2023-08-27/2023-08-27#11-"; +static char tmstr[50];//定义时间前缀 +static void sys_log_file_backend_init(void) { static struct ulog_file_be *file_be = &sys_log_file; uint8_t id = sys_id; file_be->parent = sys_log_backend; - static char logfilename[50];// = "2023-08-27/2023-08-27#11-"; - static char tmstr[50];//定义时间前缀 - +// char logfilename[50];// = "2023-08-27/2023-08-27#11-"; +// char tmstr[50];//定义时间前缀 + memset(logfilename,0,50); + memset(tmstr,0,50); getTimestmp(tmstr);// 2023-08-27 11-44-42-65 tmstr[10]='#';//2023-08-27#11- tmstr[14]='\0'; @@ -93,21 +96,24 @@ void sys_log_file_backend_init(void) //以天为独立文件夹 strncpy(logfilename,tmstr,10); char dir[30]=ROOT_PATH; - mkdir(dir, 0); - rt_thread_mdelay(500); + mkdir(dir, 0);//sd/debug + rt_thread_mdelay(100); strcat(dir,"/"); - strcat(dir,logfilename); + strcat(dir,logfilename);//sd/debug/2023-08-27 // LOG_D("dir=%s",dir); mkdir(dir, 0); - rt_thread_mdelay(500); + rt_thread_mdelay(100); strcat(logfilename,"/"); - +// LOG_D("f=%s",logfilename); //总路径不能太长 strcat(logfilename,tmstr+11);//sd/debug/2023-09-03/11- // LOG_D("f=%s",tmstr); // LOG_D("f=%s",logfilename); // ulog_file_backend_deinit(file_be); + + ulog_file_backend_disable(file_be); //先关闭 + ulog_file_backend_deinit(file_be); ulog_file_backend_init( file_be, strcat(logfilename,table[id].name), table[id].dir_path, @@ -121,12 +127,44 @@ void sys_log_file_backend_init(void) ulog_backend_filter_t filter = sys_log_file_backend_filter; // ulog_backend_set_filter(&file_be->parent,filter); } - -void updateLogFileBackend() +static int isToUpdate = 1; +static void sys_log_init_thread_entry(void *parameter) { - ulog_file_backend_deinit(&sys_log_file); - sys_log_file_backend_init(); + while (1) + { + if(isToUpdate) + { + isToUpdate = 0; + sys_log_file_backend_init(); + } + rt_thread_mdelay(30*1000); + } } -MSH_CMD_EXPORT(sys_log_file_backend_init,log2file); -INIT_APP_EXPORT(sys_log_file_backend_init); +static void initLogFileBackend() +{ + /* 创建 serial 线程 */ + rt_thread_t thread = rt_thread_create("updateLogName", sys_log_init_thread_entry, RT_NULL, 1024*5, 29, 10); + /* 创建成功则启动线程 */ + if (thread != RT_NULL) + { + rt_thread_startup(thread); + } + else + { + LOG_E("failed to create 'updateLogName'"); + } +} + +/** + * 更新debug日志的文件名 + */ +void updateDebuglogName(void) +{ +// rt_mutex_release(updateLogName); + isToUpdate = 1; +} + +MSH_CMD_EXPORT(updateDebuglogName,更新debug日志的文件名); +//MSH_CMD_EXPORT(initLogFileBackend,initLogFileBackend); +INIT_APP_EXPORT(initLogFileBackend); diff --git a/applications/ttTR/ttTR.c b/applications/ttTR/ttTR.c index cf5699f..f3e9441 100644 --- a/applications/ttTR/ttTR.c +++ b/applications/ttTR/ttTR.c @@ -132,7 +132,7 @@ int tcpRec(unsigned char *recv_data) struct rt_messagequeue TTrx_mq; void init_mq(void) { - static char msg_pool[1024]; + static char msg_pool[1024*2]; /* 初始化消息队列 */ int result = rt_mq_init(&TTrx_mq, "TTrx_mq", msg_pool, /* 存放消息的缓冲区 */ diff --git a/applications/ttTR/ttTR.h b/applications/ttTR/ttTR.h index 7dad86b..06a11f9 100644 --- a/applications/ttTR/ttTR.h +++ b/applications/ttTR/ttTR.h @@ -14,7 +14,7 @@ //struct rt_messagequeue TTrx_mq; typedef struct { - rt_uint8_t data[200]; + rt_uint8_t data[512]; int size; }TTRx_MSG; diff --git a/rtconfig.h b/rtconfig.h index a850c60..c496344 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -204,7 +204,7 @@ #define ULOG_ASSERT_ENABLE #define ULOG_LINE_BUF_SIZE 256 #define ULOG_USING_ASYNC_OUTPUT -#define ULOG_ASYNC_OUTPUT_BUF_SIZE 1024*10 +#define ULOG_ASYNC_OUTPUT_BUF_SIZE 1024*20 #define ULOG_ASYNC_OUTPUT_BY_THREAD #define ULOG_ASYNC_OUTPUT_THREAD_STACK 10240 #define ULOG_ASYNC_OUTPUT_THREAD_PRIORITY 29