更新 checkFlash 逻辑,在开始时检测

更新 checkManualWindow 逻辑
修复 SYS_CFG 中 isMaWin 的类型错误

cfg.c 中文件锁采用mutex
This commit is contained in:
CSSC-WORK\murmur 2023-09-06 09:51:08 +08:00
parent 710ffb8e62
commit 47fe7c90ee
5 changed files with 28 additions and 21 deletions

View File

@ -27,14 +27,15 @@ static rt_mutex_t isCfgOk=RT_NULL;
static rt_mutex_t isTosendOk=RT_NULL; static rt_mutex_t isTosendOk=RT_NULL;
void initCfgMutex() void initCfgMutex()
{ {
isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO); isCfgOk = rt_mutex_create("isCfgOk", RT_IPC_FLAG_FIFO);
isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO); isTosendOk = rt_mutex_create("isTosendOk", RT_IPC_FLAG_FIFO);
} }
INIT_APP_EXPORT(initCfgMutex); INIT_APP_EXPORT(initCfgMutex);
static void setLock() static void setLock()
{ {
// rt_mutex_take(isCfgOk, RT_WAITING_FOREVER); rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
// LOG_W("------file locked------");
return; return;
while(islock) while(islock)
{ {
@ -45,9 +46,9 @@ static void setLock()
} }
static void clearLock() static void clearLock()
{ {
rt_mutex_release(isCfgOk);
// LOG_W("=====file unlocked=====");
return; return;
// rt_mutex_release(isCfgOk);
// return;
islock=0; islock=0;
LOG_W("------file unlocked"); LOG_W("------file unlocked");
} }
@ -308,8 +309,9 @@ MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据)
volatile size_t nislock=0; volatile size_t nislock=0;
static void nsetLock() static void nsetLock()
{ {
// rt_mutex_take(isTosendOk, RT_WAITING_FOREVER); rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
// return; LOG_W("------file locked------");
return;
// LOG_D("--%d--",nislock); // LOG_D("--%d--",nislock);
size_t cnt=10; size_t cnt=10;
while(nislock) while(nislock)
@ -325,8 +327,9 @@ static void nsetLock()
} }
static void nclearLock() static void nclearLock()
{ {
// rt_mutex_release(isTosendOk); rt_mutex_release(isTosendOk);
// return; LOG_W("=====file unlocked=====");
return;
nislock=0; nislock=0;
LOG_W("file is unlocked."); LOG_W("file is unlocked.");
} }

View File

@ -165,7 +165,7 @@ void initFiles()
} }
} }
checkFlash(); // checkFlash();
} }
/** /**
@ -182,8 +182,9 @@ static void initCfg(void)
scfg.timeout = get_cfg("timeout"); scfg.timeout = get_cfg("timeout");
scfg.maxSizePerFile = get_cfg("maxSizePerFile"); scfg.maxSizePerFile = get_cfg("maxSizePerFile");
scfg.locRepInterval = get_cfg("locRepInterval"); scfg.locRepInterval = get_cfg("locRepInterval");
scfg.isMaWin = get_cfg("isMaWin");
char str[256]; char str[sizeof(scfg.openWindowTime)*4];
get_cfgs("openWindowTime", str); get_cfgs("openWindowTime", str);
size_t len = str2Byte(str, 3, 10, scfg.openWindowTime); size_t len = str2Byte(str, 3, 10, scfg.openWindowTime);
// LOG_HEX("win",16,scfg.openWindowTime,len); // LOG_HEX("win",16,scfg.openWindowTime,len);
@ -196,8 +197,8 @@ static void updatecfg(void)
//等待更新 //等待更新
while(1) while(1)
{ {
rt_thread_mdelay(10*1000);//10s写入一次数据到文件 // rt_thread_mdelay(10*1000);//10s写入一次数据到文件
if(rt_sem_take(cfgUpdate, RT_WAITING_NO) == RT_EOK) if(rt_sem_take(cfgUpdate, RT_WAITING_FOREVER) == RT_EOK)
{ {
updateAllSysCfg(&scfg, 0); updateAllSysCfg(&scfg, 0);
} }

View File

@ -413,8 +413,7 @@ int isManualWindow(void)
} }
void checkManualWindow(void) void checkManualWindow(void)
{ {
int rst = get_cfg("isMaWin"); int rst = scfg.isMaWin;
scfg.isMaWin = rst;
if (rst < 0) {//none if (rst < 0) {//none
return; return;
} }
@ -425,7 +424,7 @@ void checkManualWindow(void)
//设置定时器,定时器到则关窗 //设置定时器,定时器到则关窗
/* 创建定时器,单次定时器 */ /* 创建定时器,单次定时器 */
rt_timer_t timer1; rt_timer_t timer1;
timer1 = rt_timer_create("window", closeWindow, timer1 = rt_timer_create("manualModeWindow", closeWindow,
RT_NULL, rt_tick_from_millisecond(rst*60*1000), RT_NULL, rt_tick_from_millisecond(rst*60*1000),
RT_TIMER_FLAG_ONE_SHOT); RT_TIMER_FLAG_ONE_SHOT);
/* 启动定时器 */ /* 启动定时器 */
@ -596,7 +595,7 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
rst &= set_cfg("minTTsinal",scfg.minTTsinal); rst &= set_cfg("minTTsinal",scfg.minTTsinal);
rst &= set_cfg("timeout",scfg.timeout); rst &= set_cfg("timeout",scfg.timeout);
char tmpstr[sizeof(scfg.commMode)*4]; char tmpstr[sizeof(scfg.openWindowTime)*4];
bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr); bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr);
rst &= set_cfgs("openWindowTime",tmpstr); rst &= set_cfgs("openWindowTime",tmpstr);

View File

@ -56,7 +56,7 @@ typedef struct
uint8_t selfDesSW; uint8_t selfDesSW;
uint8_t locAlert; uint8_t locAlert;
uint8_t locRepInterval; uint8_t locRepInterval;
uint8_t isMaWin; int8_t isMaWin;
} SYS_CFG; } SYS_CFG;

View File

@ -81,10 +81,14 @@ void sdmnt_init(void)
} }
/* 导出到自动初始化 */ /* 导出到自动初始化 */
INIT_COMPONENT_EXPORT(sdmnt_init); INIT_COMPONENT_EXPORT(sdmnt_init);
/**
* flash是否损坏
*/
void checkFlash() void checkFlash()
{ {
//判断flash是否损坏 //间接判断。文件存在但大小为零则认为flash已损坏
if (getFileSize("cfg.ini")==0 && getFileSize("map.geojson")==0) if (isFileExit("cfg.ini") && getFileSize("cfg.ini")==0 && isFileExit("map.geojson") && getFileSize("map.geojson")==0)
{ {
LOG_E("the flash is damaged, try formatting to fix."); LOG_E("the flash is damaged, try formatting to fix.");
dfs_mkfs("elm", "W25Q128"); dfs_mkfs("elm", "W25Q128");
@ -92,7 +96,7 @@ void checkFlash()
} }
} }
/* 导出到自动初始化 */ /* 导出到自动初始化 */
//INIT_COMPONENT_EXPORT(checkFlash); INIT_COMPONENT_EXPORT(checkFlash);
void bootinfo() void bootinfo()
{ {