更新 #define ROOT_PATH "/sd/debuglog" //设置保存路径

alarmer.c 添加定时启动时的sem   timerIsReady();
cfg.c 更新 set_cfg逻辑 及 updateAllSysCfg
main.c 清理

updateAllSysCfg 待完善,有bug
This commit is contained in:
CSSC-WORK\murmur 2023-08-29 19:29:58 +08:00
parent 1c3826c35d
commit 8050a35073
10 changed files with 140 additions and 160 deletions

View File

@ -1,4 +1 @@
setCommWindow 概率性崩溃,疑似与写入配置有关
setCommWindow 崩溃,疑似传参不对
写入log到文件采用独立线程避免错误
rtc 容易导致程序崩溃

View File

@ -76,6 +76,7 @@ void pdTT_callback(rt_alarm_t alarm, time_t timestamp)
void poTT2_callback(rt_alarm_t alarm, time_t timestamp)
{
LOG_I("power UP TT by INTERVAL RTC");
timerIsReady();
initTT();
}
//每个开窗设置对应两个rtc闹钟一个上电一个下电
@ -85,7 +86,7 @@ static struct rt_alarm *alarm[4+1];//支持2组开窗共4个闹钟加一个
void InitAlarm()
{
struct rt_alarm_setup setup;
time_t now;
static time_t now;
struct tm p_tm;
/* 获取当前时间戳,并把下一秒时间设置为闹钟时间 */
now = time(NULL);
@ -184,7 +185,7 @@ void updateAlarm(uint8_t *t, size_t len)
// rt_alarm_delete(alarm[0]); //
// }
// alarm[0] = rt_alarm_create(poTT_callback, &setup);
rt_alarm_control(alarm[0], RT_ALARM_CTRL_MODIFY, (void *)&setup);
rt_alarm_control(alarm[0], RT_ALARM_CTRL_MODIFY, &setup);
setup.wktime.tm_hour = t[2]; //开窗1闭合点
setup.wktime.tm_min = t[3]; //开窗1开启点
@ -291,7 +292,7 @@ int isInWindowZone()
if (isIn1 || isIn2)
{
LOG_D("is in window zone.");
LOG_I("is in window zone.");
return 1;
}
else {

View File

@ -54,35 +54,25 @@ typedef struct
*/
int set_cfg(const char *k, long v)
{
// return;
// setLock();
// if (rt_strcmp(v,"NULL") == 0) {//delete key
// v = NULL;
//
// }
// clearLock();
int rst = 0;
if (v == get_cfg(k)) {
LOG_D("nothing needs to change.");
// clearLock();
return 1;
// LOG_D("nothing needs to change.");
rst = 1;
}
else {
setLock();
// int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
// int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
clearLock();
}
if (rst == 1) {
LOG_I("set value success.");
//以下消息队列通知各线程更新参数
// rt_sem_release(cfgUpdate);
// LOG_I("set value success.");
}
else {
LOG_E("set value fault.");
}
clearLock();
return rst;
}

View File

@ -32,9 +32,10 @@ static struct rt_event chkSta; //发送条件含两部分1-超时或文件
rt_sem_t TTReady= RT_NULL;//天通具备发送状态后 rt_sem_release(TTReady);
rt_sem_t cfgUpdate = RT_NULL;
rt_sem_t shuntDownTT = RT_NULL;
rt_sem_t okTosend = RT_NULL;
rt_sem_t cfgUpdate = RT_NULL;//配置文件更新
rt_sem_t shuntDownTT = RT_NULL;//关闭TT
rt_sem_t okTosend = RT_NULL;//可以发送后续文件
rt_sem_t okToreport = RT_NULL;//配置信息ACK
static rt_thread_t initThread=RT_NULL;
static rt_thread_t deinitThread=RT_NULL;
//void TTisReady(void)
@ -58,7 +59,7 @@ SYS_CFG scfg={
/**
*
*/
static void updatecfg(void)
static void initCfg(void)
{
//无配置文件则新建
@ -134,6 +135,9 @@ static void updatecfg(void)
}
}
else {
close(fd);
}
scfg.maxTTWaitTime = get_cfg("maxTTWaitTime");
scfg.maxTTRetryCnt = get_cfg("maxTTRetryCnt");
@ -150,41 +154,49 @@ static void updatecfg(void)
updateAlarm(scfg.openWindowTime, len);
LOG_D("cfg updated.");
}
static void updatecfg(void)
{
//等待更新
while(1)
{
if(rt_sem_take(cfgUpdate, rt_tick_from_millisecond(10*1000)) == RT_EOK)//10s写入一次数据到文件
rt_thread_mdelay(10*1000);//10s写入一次数据到文件
if(rt_sem_take(cfgUpdate, RT_WAITING_NO) == RT_EOK)
{
size_t len= sizeof(scfg);
updateAllSysCfg(&scfg, len);
uint8_t tmp[len];
memcpy(tmp,&scfg,len);
updateAllSysCfg(tmp, len);
}
}
}
void sysSemInit()
{
okTosend = rt_sem_create("okTosend", 1, RT_IPC_FLAG_PRIO);//同一时间仅一个线程发送文件
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO);//更新cfg
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_PRIO);//同一时间仅一个线程发送文件
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_FIFO);//更新cfg
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);//关闭TT
okToreport = rt_sem_create("reportINFO", 0, RT_IPC_FLAG_FIFO);//关闭TT
rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);//检查天通状态
// rt_sem_release(cfgUpdate); //上电更新值
updatecfg();
initCfg();
// void reportINFO();
reportINFO();
/* 创建 serial 线程 */
// rt_thread_t thread = rt_thread_create("updatecfg", updatecfg, RT_NULL, 1024 * 1, 27, 10);
// /* 创建成功则启动线程 */
// if (thread != RT_NULL)
// {
// rt_thread_startup(thread);
// }
// else
// {
// LOG_E("thread 'updatecfg' create failure.");
// return;
// }
rt_thread_t thread = rt_thread_create("updatecfg", updatecfg, RT_NULL, 1024 * 1, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("thread 'updatecfg' create failure.");
return;
}
// LOG_D("sysSemInit DONE.");
}
@ -210,7 +222,10 @@ void sysEventInit(void)
void sysInit(void)
{
sysSemInit();
// sysEventInit();
if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机
initTT();
setWindowMode();
}
}
//INIT_COMPONENT_EXPORT(sysInit);
@ -287,8 +302,10 @@ static void upSendFile_thread_entry(void *parameter)
clearFileToSend(f->fname);
// list_thread();
rt_sem_release(okTosend);
}
//当前文件处理完后置位
rt_sem_release(okTosend);
}
/**
@ -343,7 +360,7 @@ void getAndSendFile()
return;
}
// rt_sem_release(okTosend);//初始赋值
rt_sem_release(okTosend);//初始赋值
while(cnt)
{
int i=0;
@ -584,7 +601,7 @@ void deInitTT_thread_entry()
// initThread = RT_NULL;
deinitThread = RT_NULL;
list_thread();
// list_thread();
}
/**

View File

@ -18,7 +18,17 @@
extern SYS_CFG scfg;
extern int cryptSingleMsg(uint8_t *din, size_t len, uint8_t *dout);
extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,float y);
void selfTest(void);
extern rt_sem_t okToreport;
#define CFG_ACK
/**
* ack信号
*/
void ack(void)
{
#ifdef CFG_ACK
rt_sem_release(okToreport);
#endif
}
/**
* ASCII字符形式存入log
* @param din
@ -86,7 +96,7 @@ void setCommMode(int isTT)
scfg.commMode=isTT;
rt_sem_release(cfgUpdate);
LOG_D("set commMode to %s",isTT?"TT":"BD");
selfTest();
ack();
}
int getCommMode()
@ -214,7 +224,7 @@ void upSend_thread_entry(void* parameter)
* @param len
* @return
*/
RT_WEAK int upSend(uint8_t *din, size_t len)
int upSend(uint8_t *din, size_t len)
{
LOG_D("try to upsend to TT.");
//return;
@ -358,6 +368,7 @@ void setCommWindow(uint8_t *t, size_t len)
memcpy(scfg.openWindowTime,t,len);
rt_sem_release(cfgUpdate);
// LOG_D("updated new CommWindow zone");
ack();
}
@ -398,7 +409,7 @@ void openWindow(int t)
rt_timer_start(timer1);
LOG_D("手动开窗完成,%d分钟后自动关窗。",t);
}
selfTest();
ack();
}
/**
@ -500,7 +511,7 @@ int reportDepth(uint8_t *din,size_t len)
void updateAllSysCfg(uint8_t *cfg, size_t len)
{
LOG_I("FUNC = update SYSCFG");
SYS_CFG ts;
// SYS_CFG ts;
memcpy(&scfg,cfg,len);
//详见SYS_CFG的定义
/**
@ -519,22 +530,26 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
uint8_t locRepInterval;
*/
set_cfg("sendInterval",scfg.sendInterval);
set_cfg("maxTTWaitTime",scfg.maxTTWaitTime);
set_cfg("maxTTRetryCnt",scfg.maxTTRetryCnt);
set_cfg("minTTPeriCnt",scfg.minTTPeriCnt);
set_cfg("minTTsinal",scfg.minTTsinal);
set_cfg("timeout",scfg.timeout);
int rst=1;
rst &= set_cfg("sendInterval",scfg.sendInterval);
rst &= set_cfg("maxTTWaitTime",scfg.maxTTWaitTime);
rst &= set_cfg("maxTTRetryCnt",scfg.maxTTRetryCnt);
rst &= set_cfg("minTTPeriCnt",scfg.minTTPeriCnt);
rst &= set_cfg("minTTsinal",scfg.minTTsinal);
rst &= set_cfg("timeout",scfg.timeout);
char tmpstr[20];
bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr);
set_cfgs("openWindowTime",tmpstr);
set_cfg("maxSizePerFile", scfg.maxSizePerFile);
set_cfg("commMode",scfg.commMode);
set_cfg("selfDesSW",scfg.selfDesSW);
set_cfg("locAlert",scfg.locAlert);
set_cfg("locRepInterval",scfg.locRepInterval);
rst &= set_cfg("maxSizePerFile", scfg.maxSizePerFile);
rst &= set_cfg("commMode",scfg.commMode);
rst &= set_cfg("selfDesSW",scfg.selfDesSW);
rst &= set_cfg("locAlert",scfg.locAlert);
rst &= set_cfg("locRepInterval",scfg.locRepInterval);
if (rst) {
LOG_I("set value success.");
}
}
/**
*
@ -646,24 +661,24 @@ int isInFence(uint8_t *loc);
* 10s更新一次
* @return
*/
static void reportLoc_thread_entry(void *parameter)
void reportLoc_thread_entry(void *parameter)
{
#define CHECK_INTERVAL 6000
size_t i = 0;
while (isTCPok())
static size_t i = 0;
while (1 || isTCPok())
{
// static size_t i = 0;
int isReadyToSendLoc=0;
uint8_t rst[200];
int len = packLocMsg(rst);
if (!len) {//无有效位置数据
// return;
rt_thread_mdelay(500);//添加延时避免死循环卡死线程
continue;
}
//检测是否在围栏内
if (!isInFence(rst+len-11))//不在围栏内
if (len && !isInFence(rst+len-11))//不在围栏内
{
rst[8]=1;
isReadyToSendLoc = 1;
@ -680,58 +695,13 @@ static void reportLoc_thread_entry(void *parameter)
if (isReadyToSendLoc) {
upSend(rst, len);
}
//LOG_D("i=%d s",i*CHECK_INTERVAL/1000);
}
}
//创建定时任务默认时间5分钟采集发送
/**
*
*/
//static void upSendLoc_thread_entry(void *parameter)
//{
// while(1)
// {
// if (rt_sem_take(isReadyToSendLoc, RT_WAITING_FOREVER)) {
// uint8_t rst[200];
// size_t len = packAndChkLoc(rst);
// upSend(rst, len);
// }
// }
//}
//cb_upSendLoc()
//{
// if (isTCPok()) {
//// packAndSendLoc();
// rt_sem_release(isReadyToSendLoc);
// }
// else {
// rt_timer_delete(repLoc);
// }
//}
void reportLoc()
{
// isReadyToSendLoc = rt_sem_create("SendLoc", 0, RT_IPC_FLAG_PRIO);
// repLoc = rt_timer_create("repLoc", cb_upSendLoc,
// RT_NULL, 10,
// RT_TIMER_FLAG_PERIODIC);
/* 创建 serial 线程 */
// rt_thread_t thread = rt_thread_create("sendLoc", upSendLoc_thread_entry, RT_NULL, 1024 * 1, 27, 10);
// /* 创建成功则启动线程 */
// if (thread != RT_NULL)
// {
// rt_thread_startup(thread);
// }
// else
// {
// LOG_E("thread 'sendLoc' create failure.");
// return;
// }
rt_thread_t thread = rt_thread_create("RPLoc", reportLoc_thread_entry, RT_NULL, 1024 * 5, 28, 10);
rt_thread_t thread = rt_thread_create("RPLoc", reportLoc_thread_entry, RT_NULL, 1024 * 5, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
@ -764,9 +734,6 @@ int depthAlert(uint8_t *din, int len)
// rt_memcpy(dout+10, din, len);//5aa5从第11字节开始共len个字节
// LOG_HEX("depth",16,dout,len+10);
// //加密。因加密后数据长度会变化,故不能只加密位置数据。
// nlen = cryptSingleMsg(din, len+10, dout);
// LOG_HEX("crypt",16,dout,nlen);
// LOG_D("位置数据加密完成");
// upSend(dout, nlen);
}
@ -908,11 +875,6 @@ void ttRunCMD(uint8_t *din, size_t len)
break;
case _CFG_COMM_WINDOW:
setCommWindow(din+8,din[7]);//只支持两组开窗开窗时间为小时、分钟UTC+0
// char tmpstr[20];
// bytes2str(din+8,din[7], 10, ",", tmpstr);
// set_cfgs("openWindowTime",tmpstr);
break;
case _CMD_OPEN_WINDOW:
openWindow(din[7]?((din[8] << 8) + din[9]):0);//两字节开窗时间
@ -1521,7 +1483,35 @@ int isEthUP()
}
void reportInfo_thread(void)
{
while (1)
{
if (rt_sem_take(okToreport, RT_WAITING_FOREVER) == RT_EOK)
{
LOG_D("send cfg ACK");
selfTest();
}
}
}
void reportINFO(void)
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("reportINFO", reportInfo_thread, RT_NULL, 1024 * 1, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("thread 'updatecfg' create failure.");
return;
}
}
//INIT_APP_EXPORT(reportINFO);
#define FUNC_DEMO

View File

@ -201,9 +201,9 @@ static void rulecheck(void)
}
if (okCnt >= scfg.minTTPeriCnt) {
//TT具备发送条件
LOG_I("----");
// LOG_I("----");
TTIsReady();
LOG_I("符合规则TT具备发送状态。");
// LOG_I("符合规则TT具备发送状态。");
okCnt = scfg.minTTPeriCnt -1;
}
// if (okCnt > minTTPeriCnt) {

View File

@ -10,7 +10,7 @@
#include <..\rt-thread\components\utilities\ulog\backend\ulog_be.h>
#include "usrcfg.h"
/*
*
*/
@ -34,7 +34,7 @@ typedef enum
motion_id,
}ulog_file_be_name;
#define ROOT_PATH "/sd/debuglog" //设置保存路径
#define ROOT_PATH ROOT_PATH_DEBUG //设置保存路径
#define FILE_SIZE 10*1024 //设置单个文件大小
#define BUFF_SIZE 1*1024 //设备缓存区大小

View File

@ -24,7 +24,7 @@
// LOG_D("key irq callback");
//}
//extern void sysInit(void);
int main(void)
{
@ -46,14 +46,14 @@ int main(void)
rt_pin_mode(TR485_RE, PIN_MODE_OUTPUT);
rt_pin_write(TR485_RE, PIN_LOW);
//sysSemInit
sysInit();
// sysEventInit();
if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机
initTT();
setWindowMode();
// pwTT_thread_entry("1");
}
// if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机
// initTT();
// setWindowMode();
//// pwTT_thread_entry("1");
// }
@ -78,22 +78,6 @@ int main(void)
//fastlz_test -c demo.bin f.bin
//
//RT_WEAK void initTT()
//{
//
//}
//
//RT_WEAK void deInitTT()
//{
//
//}
INIT_APP_EXPORT(main);
extern int rt_hw_stm32_eth_init(void);
MSH_CMD_EXPORT(rt_hw_stm32_eth_init, );

View File

@ -158,7 +158,7 @@ static int uart_dma_sample(int argc, char *argv[])
#endif
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("RS232", serial_thread_entry, RT_NULL, 1024*10, 25+1, 10);
rt_thread_t thread = rt_thread_create("RS232", serial_thread_entry, RT_NULL, 1024*10, 25-1, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{

View File

@ -56,8 +56,9 @@ typedef struct
//struct rt_event sw_check;//软件条件
#define ROOT_PATH_LOG "/sd/log/"
#define ROOT_PATH_DATA "/sd/rxdata/"
#define ROOT_PATH_LOG "/sd/log/" //收发数据
#define ROOT_PATH_DATA "/sd/cdata/" //缓存数据
#define ROOT_PATH_DEBUG "/sd/debug/" //调试日志
#define CRYPT_BEFRE_PACK
#define UPDATE_INTERVAL 10