更新485定时逻辑,不采用mutex
添加默认rtc闹钟,用于更新debug日志文件名 func.c 去掉重复校验逻辑 func.h 添加部分宏定义注释 getinfo.c 修复TT关机后未复位状态信息的bug log2file.c 添加更新debug日志文件名的功能 ttTR.c 增加msg_pool及TTRx_MSG的大小 增加ULOG_ASYNC_OUTPUT_BUF_SIZE大小
This commit is contained in:
parent
0c095505ca
commit
98a895fb3e
@ -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;
|
||||
}
|
||||
|
@ -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]))
|
||||
{
|
||||
|
@ -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+1<n)?index[i+1]-index[i]:len-index[i];
|
||||
memcpy(ndin,din+index[i],cnt);
|
||||
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);
|
||||
// if (chk3SDataValid(ndin, cnt) != RT_EOK) {
|
||||
//#ifdef CHECK_3S_DATA
|
||||
// return;
|
||||
//#endif
|
||||
// }
|
||||
parse3SData(ndin,cnt);
|
||||
}
|
||||
}
|
||||
|
@ -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 //深度回复
|
||||
|
||||
|
@ -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,"-");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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, /* 存放消息的缓冲区 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user