cfg.c 逻辑更新

chkAndSendFile_thread_entry 不正常 EVENT chksta 不能触发
This commit is contained in:
CSSC-WORK\murmur 2023-08-30 10:45:32 +08:00
parent 8050a35073
commit 348f2688e2
4 changed files with 56 additions and 45 deletions

View File

@ -70,7 +70,7 @@ int set_cfg(const char *k, long v)
// LOG_I("set value success.");
}
else {
LOG_E("set value fault.");
LOG_E("set %s value fault.",k);
}
return rst;
@ -78,36 +78,32 @@ int set_cfg(const char *k, long v)
int set_cfgs(const char *k, const char * v)
{
// setLock();
int rst=0;
if (strcmp(v,"NULL") == 0) {//delete key
v = NULL;
}
char tmp[20];
char tmp[30];
get_cfgs(k,tmp);
// LOG_D("v=%s-----%s",v,tmp);
if (strcmp(v,tmp) == 0) {
LOG_D("nothing needs to change.");
// clearLock();
return 1;
}
setLock();
int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
clearLock();
// int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
if (rst == 1) {
LOG_I("set value success.");
//以下消息队列通知各线程更新参数
// rt_sem_release(cfgUpdate);
// LOG_D("nothing needs to change.");
rst = 1;
}
else {
LOG_E("set value fault.");
setLock();
rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
clearLock();
}
// int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
if (rst == 1) {
// LOG_I("set value success.");
}
else {
LOG_E("set %s value fault.",k);
}
// clearLock();
return rst;
}
/**

View File

@ -163,10 +163,7 @@ static void updatecfg(void)
rt_thread_mdelay(10*1000);//10s写入一次数据到文件
if(rt_sem_take(cfgUpdate, RT_WAITING_NO) == RT_EOK)
{
size_t len= sizeof(scfg);
uint8_t tmp[len];
memcpy(tmp,&scfg,len);
updateAllSysCfg(tmp, len);
updateAllSysCfg(&scfg, 0);
}
}
@ -175,18 +172,18 @@ static void updatecfg(void)
void sysSemInit()
{
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_PRIO);//同一时间仅一个线程发送文件
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_FIFO);//同一时间仅一个线程发送文件
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_FIFO);//更新cfg
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);//关闭TT
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_FIFO);//关闭TT
okToreport = rt_sem_create("reportINFO", 0, RT_IPC_FLAG_FIFO);//关闭TT
rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);//检查天通状态
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
// rt_sem_release(cfgUpdate); //上电更新值
initCfg();
// void reportINFO();
reportINFO();
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("updatecfg", updatecfg, RT_NULL, 1024 * 1, 27, 10);
rt_thread_t thread = rt_thread_create("updatecfg", updatecfg, RT_NULL, 1024 * 5, 27+1, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
@ -222,6 +219,7 @@ void sysEventInit(void)
void sysInit(void)
{
sysSemInit();
sysEventInit();
if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机
initTT();
setWindowMode();
@ -387,14 +385,23 @@ static void chkAndSendFile_thread_entry()
{
while (1)
{
// int e;
LOG_I("等待发送条件(文件就绪或定时%d分钟超时",scfg.sendInterval);
int sta=0;
// LOG_I("等待发送条件(文件就绪或定时%d分钟超时",scfg.sendInterval);
if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足
rt_tick_from_millisecond(5000), RT_NULL) == RT_EOK) //条件1满足
{
LOG_I("等待TT就绪");
LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",scfg.minTTPeriCnt,scfg.minTTsinal);
initTT();
sta = 1;
}
// else {
//// rt_thread_mdelay(500);
// sta = 0;
// continue;
// }
if (!sta) {
continue;
}
for (size_t var = 0; var < scfg.maxTTRetryCnt; var++) //轮询尝试
@ -434,7 +441,7 @@ static void chkAndSendFile_thread_entry()
void chkAndSendFile()
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("chk&send", chkAndSendFile_thread_entry, RT_NULL, 1024 * 2, 19, 10);
rt_thread_t thread = rt_thread_create("chk&send", chkAndSendFile_thread_entry, RT_NULL, 1024 * 5, 19, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
@ -611,6 +618,7 @@ void initTT()
{
/* 创建 serial 线程 */
if (initThread != RT_NULL) {
LOG_W("initThread 未退出");
return;
}
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 20, 10);
@ -655,7 +663,7 @@ void deInitTT()
MSH_CMD_EXPORT_ALIAS(d_upSta,ttisok,TT_IS_OK);
MSH_CMD_EXPORT(fileIsReady,fileIsReady);
MSH_CMD_EXPORT(chkAndSendFile, chkAndSendFile);
//MSH_CMD_EXPORT(upSendFile, upSendFile);
MSH_CMD_EXPORT(getAndSendFile, getAndSendFile);
MSH_CMD_EXPORT(initTT,TT);
MSH_CMD_EXPORT(deInitTT,TT);
MSH_CMD_EXPORT(d_remain,);

View File

@ -165,7 +165,7 @@ void upSend_thread_entry(void* parameter)
//check status
uint8_t trycnt = 0;
while (1 && !isTTjh()) //判断TT状态
while (!isTTjh()) //判断TT状态
{
rt_thread_mdelay(4000);
trycnt += 1;
@ -506,13 +506,15 @@ int reportDepth(uint8_t *din,size_t len)
/**
*
* @param cfg
* @param len
* @param len 使scfg
*/
void updateAllSysCfg(uint8_t *cfg, size_t len)
{
LOG_I("FUNC = update SYSCFG");
// SYS_CFG ts;
memcpy(&scfg,cfg,len);
if (len) {
memcpy(&scfg,cfg,len);
}
//详见SYS_CFG的定义
/**
*
@ -530,23 +532,26 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
uint8_t locRepInterval;
*/
int rst=1;
static 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);
// LOG_D("rst==%d",rst);
char tmpstr[20];
bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr);
set_cfgs("openWindowTime",tmpstr);
rst &= set_cfgs("openWindowTime",tmpstr);
// LOG_D("rst==%d",rst);
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);
// LOG_D("rst=%d",rst);
if (rst) {
LOG_I("set value success.");
}
@ -664,9 +669,10 @@ int isInFence(uint8_t *loc);
void reportLoc_thread_entry(void *parameter)
{
#define CHECK_INTERVAL 6000
static size_t i = 0;
while (1 || isTCPok())
while (isTCPok())
{
static size_t i = 0;
int isReadyToSendLoc=0;
uint8_t rst[200];
@ -687,7 +693,7 @@ void reportLoc_thread_entry(void *parameter)
i += 1 ;
if (i*CHECK_INTERVAL > scfg.locRepInterval * 60 * 1000)//定时发送默认5分钟
{
// LOG_D("%d/%d",i*15,scfg.locRepInterval * 60);
// LOG_D("%d/%d",i*CHECK_INTERVAL,scfg.locRepInterval * 60 *1000);
i=0;
isReadyToSendLoc = 1;
}
@ -778,7 +784,7 @@ int isInFence(uint8_t *loc)
// LOG_D("%lf-%lf", x, y);
int isIN = isInPolgon(x, y);
if (isIN) {
LOG_I("设备在围栏内,位置正常。");
LOG_D("设备在围栏内,位置正常。");
return 1;
}
else {

View File

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