From 348f2688e2383efc5eed4aedb8fc9f4a492e1977 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Wed, 30 Aug 2023 10:45:32 +0800 Subject: [PATCH] =?UTF-8?q?cfg.c=20=E9=80=BB=E8=BE=91=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?chkAndSendFile=5Fthread=5Fentry=20=E4=B8=8D=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=20EVENT=20chksta=20=E4=B8=8D=E8=83=BD=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/cfg.c | 38 +++++++++++++++++--------------------- applications/core.c | 34 +++++++++++++++++++++------------- applications/func/func.c | 28 +++++++++++++++++----------- applications/getinfo.c | 1 + 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/applications/cfg.c b/applications/cfg.c index 40aceab..ec21bc9 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -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; } /** diff --git a/applications/core.c b/applications/core.c index 8f086c6..7f7a148 100644 --- a/applications/core.c +++ b/applications/core.c @@ -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,剩余超时时间); diff --git a/applications/func/func.c b/applications/func/func.c index bef28c2..31096ba 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -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 { diff --git a/applications/getinfo.c b/applications/getinfo.c index 17a79a6..3e430a7 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -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;