屏蔽部分文件锁

This commit is contained in:
CSSC-WORK\murmur 2023-08-25 16:36:00 +08:00
parent 3228e770c7
commit 62408256d1
9 changed files with 73 additions and 101 deletions

View File

@ -338,7 +338,11 @@ CONFIG_ULOG_OUTPUT_LVL=7
CONFIG_ULOG_USING_ISR_LOG=y CONFIG_ULOG_USING_ISR_LOG=y
CONFIG_ULOG_ASSERT_ENABLE=y CONFIG_ULOG_ASSERT_ENABLE=y
CONFIG_ULOG_LINE_BUF_SIZE=256 CONFIG_ULOG_LINE_BUF_SIZE=256
# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set CONFIG_ULOG_USING_ASYNC_OUTPUT=y
CONFIG_ULOG_ASYNC_OUTPUT_BUF_SIZE=2048
CONFIG_ULOG_ASYNC_OUTPUT_BY_THREAD=y
CONFIG_ULOG_ASYNC_OUTPUT_THREAD_STACK=2048
CONFIG_ULOG_ASYNC_OUTPUT_THREAD_PRIORITY=30
# #
# log format # log format

View File

@ -21,7 +21,7 @@
#include "cfg.h" #include "cfg.h"
static uint8_t islock=0; volatile static uint8_t islock=0;
static void setLock() static void setLock()
{ {
while(islock) while(islock)
@ -300,18 +300,26 @@ static void clear_sta(void)
} }
MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, ) MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, )
static uint8_t nislock=0; volatile size_t nislock=0;
static void nsetLock() static void nsetLock()
{ {
// LOG_D("--%d--",nislock);
size_t cnt=10;
while(nislock) while(nislock)
{ {
rt_thread_mdelay(1000); rt_thread_mdelay(1000);
LOG_W("file is locked.");
cnt += 1;
if (cnt>10) {
break;
}
} }
nislock=1; nislock=1;
} }
static void nclearLock() static void nclearLock()
{ {
nislock=0; nislock=0;
LOG_W("file is unlocked.");
} }
@ -346,7 +354,7 @@ void postFileInfo(const char *fin, uint8_t index)
strcpy(msg.fname,fin); strcpy(msg.fname,fin);
msg.index=index; msg.index=index;
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("filelist", setFileToSend_thread_entry, (void *)&msg, 1024*2, 30-2, 10); rt_thread_t thread = rt_thread_create("filelist", setFileToSend_thread_entry, (void *)&msg, 1024*5, 30-2, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {
@ -368,7 +376,7 @@ size_t getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v)
{ {
// char buf[MAX_KEY_LEN]; // char buf[MAX_KEY_LEN];
// char kstr[MAX_KEY_LEN]; // char kstr[MAX_KEY_LEN];
nsetLock(); // nsetLock();
size_t len=0; size_t len=0;
for (size_t k = 0; ini_getkey(SECTION_TO_SEND, k, kstr[len], MAX_KEY_LEN, FILE_TO_SEND) > 0; k++) { for (size_t k = 0; ini_getkey(SECTION_TO_SEND, k, kstr[len], MAX_KEY_LEN, FILE_TO_SEND) > 0; k++) {
v[len] = ini_getl(SECTION_TO_SEND, kstr[len], -1, FILE_TO_SEND); v[len] = ini_getl(SECTION_TO_SEND, kstr[len], -1, FILE_TO_SEND);
@ -377,7 +385,7 @@ size_t getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v)
break; break;
} }
} }
nclearLock(); // nclearLock();
return len; return len;
} }
/** /**
@ -436,12 +444,11 @@ int updateLstFile(const char *fin)
nsetLock(); nsetLock();
int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND); int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND);
nclearLock();
if (!rst) { if (!rst) {
LOG_E("update lst file error."); LOG_E("update lst file error.");
nclearLock();
return RT_ERROR; return RT_ERROR;
} }
nclearLock();
return RT_EOK; return RT_EOK;
} }
@ -452,14 +459,14 @@ int updateLstFile(const char *fin)
*/ */
int getLstFile(const char *k) int getLstFile(const char *k)
{ {
nsetLock(); // nsetLock();
char tmp[60]; char tmp[60];
int rst = ini_gets(SECTION_LST_FILE, "lst", "000",tmp,60, FILE_TO_SEND); int rst = ini_gets(SECTION_LST_FILE, "lst", "000",tmp,60, FILE_TO_SEND);
if (rst == 3) { if (rst == 3) {
rst=0; rst=0;
} }
strcpy(k,tmp); strcpy(k,tmp);
nclearLock(); // nclearLock();
return rst; return rst;
} }

View File

@ -74,6 +74,7 @@ static void updatecfg(void)
scfg.minTTsinal = get_cfg("minTTsinal"); scfg.minTTsinal = get_cfg("minTTsinal");
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");
char str[20]; char str[20];
get_cfgs("openWindowTime",str); get_cfgs("openWindowTime",str);
@ -88,7 +89,7 @@ static void updatecfg(void)
void sysSemInit() void sysSemInit()
{ {
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_PRIO);//同一时间仅一个线程发送文件 okTosend = rt_sem_create("okTosend", 1, RT_IPC_FLAG_PRIO);//同一时间仅一个线程发送文件
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO);//更新cfg cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO);//更新cfg
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);//关闭TT shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);//关闭TT
rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);//检查天通状态 rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);//检查天通状态
@ -266,7 +267,7 @@ void getAndSendFile()
return; return;
} }
rt_sem_release(okTosend);//初始赋值 // rt_sem_release(okTosend);//初始赋值
while(cnt) while(cnt)
{ {
int i=0; int i=0;
@ -474,7 +475,7 @@ void initTT_thread_entry()
tcpRecMQ(); //开启tcp接收线程 tcpRecMQ(); //开启tcp接收线程
recTT(); recTT();
repGetTT(); repGetTT();
// reportLoc(); reportLoc();
} }
} }
@ -518,7 +519,7 @@ void initTT()
if (initThread != RT_NULL) { if (initThread != RT_NULL) {
return; return;
} }
initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 1.5, 20, 10); initThread = rt_thread_create("initTT", initTT_thread_entry, RT_NULL, 1024 * 5, 20, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (initThread != RT_NULL) if (initThread != RT_NULL)
{ {
@ -534,7 +535,7 @@ void initTT()
if (deinitThread != RT_NULL) { if (deinitThread != RT_NULL) {
return; return;
} }
deinitThread = rt_thread_create("deInitTT", deInitTT_thread_entry, RT_NULL, 1024 * 2, 19, 10); deinitThread = rt_thread_create("deInitTT", deInitTT_thread_entry, RT_NULL, 1024 * 5, 19, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (deinitThread != RT_NULL) if (deinitThread != RT_NULL)
{ {

View File

@ -26,25 +26,8 @@ extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,f
*/ */
int trDataTolog(uint8_t *din, size_t len, uint8_t isTx) int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
{ {
// char rootDir[22] = ROOT_PATH_LOG;
// mkdir(rootDir, 0);
//
// char tstmp[30] = "";
// char fn[50] = "";
// strcat(fn,rootDir);
// strcat(fn,"20");
// strcat(fn,date2Str(tstmp));//以小时为独立文件
// fn[strlen(fn)-3]='\0';
// strcat(fn,"/");
// mkdir(fn, 0);
//
// strcat(fn,tstmp);
// strcat(fn,".log");
char fn[60] = "\n"; char fn[60] = "\n";
initDataLogPath(fn); initDataLogPath(fn);
// LOG_D("fn=%s",fn);
// LOG_HEX("d",16,din,len);
int fd = open(fn, O_WRONLY | O_CREAT | O_APPEND); int fd = open(fn, O_WRONLY | O_CREAT | O_APPEND);
@ -52,7 +35,7 @@ int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
int trycnt=0; int trycnt=0;
while (fd < 0) while (fd < 0)
{ {
rt_thread_mdelay(500); rt_thread_mdelay(200);
fd = open(fn, O_WRONLY | O_CREAT | O_APPEND); fd = open(fn, O_WRONLY | O_CREAT | O_APPEND);
trycnt +=1; trycnt +=1;
if (trycnt>5) { if (trycnt>5) {
@ -60,7 +43,7 @@ int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
} }
} }
if (trycnt>5) { if (fd<0) {
LOG_E("open file %s failed!", fn); LOG_E("open file %s failed!", fn);
return -RT_ERROR; return -RT_ERROR;
} }
@ -165,19 +148,17 @@ void upSend_thread_entry(void* parameter)
// LOG_HEX("--",16,msg->data,msg->len); // LOG_HEX("--",16,msg->data,msg->len);
//check status //check status
uint8_t sta = 1; uint8_t trycnt = 0;
while (1 && !isTTjh()) //判断TT状态 while (1 && !isTTjh()) //判断TT状态
{ {
static uint8_t trycnt = 0;
rt_thread_mdelay(4000); rt_thread_mdelay(4000);
trycnt += 1; trycnt += 1;
if (trycnt > 3) if (trycnt > 3)
{ {
sta = 0; //try 3 time
break; break;
} }
} }
if (!sta) { if (!isTTjh()) {
//cache to file //cache to file
LOG_W("TT is not ready, try to cache %d bytes data to file.",msg->len); LOG_W("TT is not ready, try to cache %d bytes data to file.",msg->len);
cacheDataToFile(msg->data, msg->len); cacheDataToFile(msg->data, msg->len);
@ -217,8 +198,8 @@ void upSend_thread_entry(void* parameter)
cacheDataToFile(msg->data, msg->len); cacheDataToFile(msg->data, msg->len);
} }
} }
rt_sem_release(one_msg_send_done); // rt_sem_release(one_msg_send_done);
list_thread(); // list_thread();
return ; return ;
} }
/** /**
@ -231,9 +212,9 @@ RT_WEAK int upSend(uint8_t *din, size_t len)
{ {
LOG_D("try to upsend to TT."); LOG_D("try to upsend to TT.");
if (one_msg_send_done == RT_NULL) { // if (one_msg_send_done == RT_NULL) {
one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO); // one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO);
} // }
static SMSG msg; static SMSG msg;
memset(&msg, 0, sizeof(SMSG)); memset(&msg, 0, sizeof(SMSG));
@ -241,12 +222,12 @@ RT_WEAK int upSend(uint8_t *din, size_t len)
msg.len=len; msg.len=len;
// LOG_D("0--%p",&msg); // LOG_D("0--%p",&msg);
//仅创建一个线程用于发送 //仅创建一个线程用于发送
if (rt_sem_take(one_msg_send_done, rt_tick_from_millisecond(10000)) != RT_EOK) { // if (rt_sem_take(one_msg_send_done, rt_tick_from_millisecond(10000)) != RT_EOK) {
//10s等待上一发送仍未完成 // //10s等待上一发送仍未完成
LOG_E("wait error, try to cache %d bytes data to file.",msg.len); // LOG_E("wait error, try to cache %d bytes data to file.",msg.len);
cacheDataToFile(msg.data, msg.len); // cacheDataToFile(msg.data, msg.len);
return -RT_ERROR; // return -RT_ERROR;
} // }
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("upSend", upSend_thread_entry, (void *) &msg, 1024 * 5, 27-1, 10); rt_thread_t thread = rt_thread_create("upSend", upSend_thread_entry, (void *) &msg, 1024 * 5, 27-1, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
@ -268,7 +249,7 @@ RT_WEAK int upSend(uint8_t *din, size_t len)
void selfTest() void selfTest()
{ {
LOG_I("FUNC = selftest"); LOG_I("FUNC = selftest");
rt_uint8_t rst[100]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff}; rt_uint8_t rst[200]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff};
int p = 6; int p = 6;
rt_uint8_t sysSta=1,commSpeed=0; rt_uint8_t sysSta=1,commSpeed=0;
//长度 //长度
@ -651,7 +632,7 @@ int isInFence(uint8_t *loc);
* 10s更新一次 * 10s更新一次
* @return * @return
*/ */
static void packAndSendLoc_thread_entry(void *parameter) static void reportLoc_thread_entry(void *parameter)
{ {
#define CHECK_INTERVAL 15000 #define CHECK_INTERVAL 15000
size_t i = 0; size_t i = 0;
@ -677,6 +658,7 @@ static void packAndSendLoc_thread_entry(void *parameter)
i += 1 ; i += 1 ;
if (i*CHECK_INTERVAL > scfg.locRepInterval * 60 * 1000)//定时发送默认5分钟 if (i*CHECK_INTERVAL > scfg.locRepInterval * 60 * 1000)//定时发送默认5分钟
{ {
// LOG_D("%d/%d",i*15,scfg.locRepInterval * 60);
i=0; i=0;
isReadyToSendLoc = 1; isReadyToSendLoc = 1;
} }
@ -735,7 +717,7 @@ void reportLoc()
// LOG_E("thread 'sendLoc' create failure."); // LOG_E("thread 'sendLoc' create failure.");
// return; // return;
// } // }
rt_thread_t thread = rt_thread_create("RPLoc", packAndSendLoc_thread_entry, RT_NULL, 1024 * 2, 28, 10); rt_thread_t thread = rt_thread_create("RPLoc", reportLoc_thread_entry, RT_NULL, 1024 * 5, 28, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {
@ -1181,64 +1163,30 @@ static uint8_t iscdlock=0;
int cacheDataToFile(uint8_t *din, size_t len) int cacheDataToFile(uint8_t *din, size_t len)
{ {
LOG_I("FUNC = cache to upsend"); LOG_I("FUNC = cache to upsend");
// static uint16_t cnt = 0; int rst = -RT_ERROR;
// LOG_D("already cached %d bytes.", cnt);
// char rootDir[22] = "/sd/rxdata/";
// mkdir(rootDir, 0);
//
// strcat(rootDir, "2023_07_19/");
//
// //name of cachefile
// static char f[60] = "";
//
// if (cnt == 0 || cnt > 1024)
// {
// if (cnt) {
// //加入待发列表
// postFileInfo(f,0);
// }
// //广播待发送文件
// cnt = 0;
// //更新时戳
// char ts[30] = "";
// time2Str(ts);
// //更新文件夹
// strncpy(rootDir + strlen(rootDir) - 9, ts, 8);
// mkdir(rootDir, 0);
//
// //更新文件名
// f[0] = '\0';
// strcat(f, rootDir);
//// strcpy(f,rootDir);
// strcat(f, "23_07_19_16_38_36_36.bin");
//// LOG_D("need to creat new file");
// strncpy(f + strlen(rootDir), ts, strlen(ts));
// }
// LOG_D("f=%s", f);
char f[60]=""; char f[60]="";
getLstCacheFileName(f); getLstCacheFileName(f);
//lock file //lock file
if (iscdlock) { while (iscdlock) {
rt_thread_mdelay(1000); rt_thread_mdelay(1000);
} }
iscdlock=1;
int fd = open(f, O_WRONLY | O_CREAT | O_APPEND); int fd = open(f, O_WRONLY | O_CREAT | O_APPEND);
if (fd < 0) if (fd < 0)
{ {
LOG_E("open file %s failed!", f); LOG_E("open file %s failed!", f);
return -RT_ERROR; goto _exit;
} }
else else
{ {
iscdlock=1;
int rst = write(fd, din, len); int rst = write(fd, din, len);
if (rst != len) if (rst != len)
{ {
LOG_E("write to file %s failed!", f); LOG_E("write to file %s failed!", f);
close(fd); goto _exit;
iscdlock=0;
return -RT_ERROR;
} }
// cnt += len; // cnt += len;
close(fd); close(fd);
@ -1249,11 +1197,15 @@ int cacheDataToFile(uint8_t *din, size_t len)
postFileInfo(f,0);//加入待发列表 postFileInfo(f,0);//加入待发列表
updateCacheFileName();//更新文件名 updateCacheFileName();//更新文件名
} }
rst=RT_EOK;
}
_exit:
if (fd) {
close(fd);
} }
iscdlock=0; iscdlock=0;
return RT_EOK; return rst;
} }
void d_cacheData() void d_cacheData()
{ {

View File

@ -371,7 +371,7 @@ void getTT(int argc, char **argv)
} }
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 1, 25, 10); rt_thread_t thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 5, 25, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {
@ -469,7 +469,7 @@ void repGetTT(void)
{} {}
memset(rstInfo,0x3f,RST_LEN);//初始化 memset(rstInfo,0x3f,RST_LEN);//初始化
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 2, 27, 10); rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 5, 27, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {

View File

@ -69,4 +69,4 @@ void sys_log_file_backend_init(void)
ulog_file_backend_enable(file_be); //必须使能才能有效 ulog_file_backend_enable(file_be); //必须使能才能有效
} }
MSH_CMD_EXPORT(sys_log_file_backend_init,log2file); MSH_CMD_EXPORT(sys_log_file_backend_init,log2file);
//INIT_COMPONENT_EXPORT(sys_log_file_backend_init); INIT_COMPONENT_EXPORT(sys_log_file_backend_init);

View File

@ -406,9 +406,12 @@ char *getLstCacheFileName(char *fin)
// getNewCacheFileName(fin); // getNewCacheFileName(fin);
// } // }
char f[60]; char f[60];
while (!getLstFile(f)) { // while (!getLstFile(f)) {
// updateCacheFileName();
// rt_thread_mdelay(1000);
// }
if (!getLstFile(f)) {
updateCacheFileName(); updateCacheFileName();
rt_thread_mdelay(1000);
} }
strcpy(fin,f); strcpy(fin,f);
return fin; return fin;

View File

@ -158,7 +158,7 @@ static int uart_dma_sample(int argc, char *argv[])
#endif #endif
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("RS232", serial_thread_entry, RT_NULL, 1024*5, 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) if (thread != RT_NULL)
{ {

View File

@ -205,6 +205,11 @@
#define ULOG_USING_ISR_LOG #define ULOG_USING_ISR_LOG
#define ULOG_ASSERT_ENABLE #define ULOG_ASSERT_ENABLE
#define ULOG_LINE_BUF_SIZE 256 #define ULOG_LINE_BUF_SIZE 256
#define ULOG_USING_ASYNC_OUTPUT
#define ULOG_ASYNC_OUTPUT_BUF_SIZE 2048
#define ULOG_ASYNC_OUTPUT_BY_THREAD
#define ULOG_ASYNC_OUTPUT_THREAD_STACK 2048
#define ULOG_ASYNC_OUTPUT_THREAD_PRIORITY 30
/* log format */ /* log format */
@ -390,5 +395,5 @@
/* end of samples: kernel and components samples */ /* end of samples: kernel and components samples */
#define RT_STUDIO_BUILT_IN #define RT_STUDIO_BUILT_IN
#define HAL_SRAM_MODULE_ENABLED
#endif #endif