From 62408256d1d6b3dd78f8e91f52fba44f6ea84ee0 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 25 Aug 2023 16:36:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E9=83=A8=E5=88=86=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config | 6 ++- applications/cfg.c | 25 +++++---- applications/core.c | 11 ++-- applications/func/func.c | 110 +++++++++++---------------------------- applications/getinfo.c | 4 +- applications/log2file.c | 2 +- applications/tools.c | 7 ++- applications/uart_3S.c | 2 +- rtconfig.h | 7 ++- 9 files changed, 73 insertions(+), 101 deletions(-) diff --git a/.config b/.config index 4b2d048..d41f21f 100644 --- a/.config +++ b/.config @@ -338,7 +338,11 @@ CONFIG_ULOG_OUTPUT_LVL=7 CONFIG_ULOG_USING_ISR_LOG=y CONFIG_ULOG_ASSERT_ENABLE=y 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 diff --git a/applications/cfg.c b/applications/cfg.c index 618d7bc..4ff3625 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -21,7 +21,7 @@ #include "cfg.h" -static uint8_t islock=0; +volatile static uint8_t islock=0; static void setLock() { while(islock) @@ -300,18 +300,26 @@ static void clear_sta(void) } MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据) -static uint8_t nislock=0; +volatile size_t nislock=0; static void nsetLock() { +// LOG_D("--%d--",nislock); + size_t cnt=10; while(nislock) { rt_thread_mdelay(1000); + LOG_W("file is locked."); + cnt += 1; + if (cnt>10) { + break; + } } nislock=1; } static void nclearLock() { nislock=0; + LOG_W("file is unlocked."); } @@ -346,7 +354,7 @@ void postFileInfo(const char *fin, uint8_t index) strcpy(msg.fname,fin); msg.index=index; /* 创建 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) { @@ -368,7 +376,7 @@ size_t getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v) { // char buf[MAX_KEY_LEN]; // char kstr[MAX_KEY_LEN]; - nsetLock(); +// nsetLock(); 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++) { 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; } } - nclearLock(); +// nclearLock(); return len; } /** @@ -436,12 +444,11 @@ int updateLstFile(const char *fin) nsetLock(); int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND); + nclearLock(); if (!rst) { LOG_E("update lst file error."); - nclearLock(); return RT_ERROR; } - nclearLock(); return RT_EOK; } @@ -452,14 +459,14 @@ int updateLstFile(const char *fin) */ int getLstFile(const char *k) { - nsetLock(); +// nsetLock(); char tmp[60]; int rst = ini_gets(SECTION_LST_FILE, "lst", "000",tmp,60, FILE_TO_SEND); if (rst == 3) { rst=0; } strcpy(k,tmp); - nclearLock(); +// nclearLock(); return rst; } diff --git a/applications/core.c b/applications/core.c index 8b793c9..5f1e746 100644 --- a/applications/core.c +++ b/applications/core.c @@ -74,6 +74,7 @@ static void updatecfg(void) scfg.minTTsinal = get_cfg("minTTsinal"); scfg.timeout = get_cfg("timeout"); scfg.maxSizePerFile = get_cfg("maxSizePerFile"); + scfg.locRepInterval = get_cfg("locRepInterval"); char str[20]; get_cfgs("openWindowTime",str); @@ -88,7 +89,7 @@ static void updatecfg(void) 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 shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);//关闭TT rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);//检查天通状态 @@ -266,7 +267,7 @@ void getAndSendFile() return; } - rt_sem_release(okTosend);//初始赋值 +// rt_sem_release(okTosend);//初始赋值 while(cnt) { int i=0; @@ -474,7 +475,7 @@ void initTT_thread_entry() tcpRecMQ(); //开启tcp接收线程 recTT(); repGetTT(); -// reportLoc(); + reportLoc(); } } @@ -518,7 +519,7 @@ void initTT() if (initThread != RT_NULL) { 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) { @@ -534,7 +535,7 @@ void initTT() if (deinitThread != RT_NULL) { 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) { diff --git a/applications/func/func.c b/applications/func/func.c index e704b11..2e679ea 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -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) { -// 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"; initDataLogPath(fn); -// LOG_D("fn=%s",fn); -// LOG_HEX("d",16,din,len); 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; while (fd < 0) { - rt_thread_mdelay(500); + rt_thread_mdelay(200); fd = open(fn, O_WRONLY | O_CREAT | O_APPEND); trycnt +=1; 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); return -RT_ERROR; } @@ -165,19 +148,17 @@ void upSend_thread_entry(void* parameter) // LOG_HEX("--",16,msg->data,msg->len); //check status - uint8_t sta = 1; + uint8_t trycnt = 0; while (1 && !isTTjh()) //判断TT状态 { - static uint8_t trycnt = 0; rt_thread_mdelay(4000); trycnt += 1; if (trycnt > 3) { - sta = 0; //try 3 time break; } } - if (!sta) { + if (!isTTjh()) { //cache to file LOG_W("TT is not ready, try to cache %d bytes data to file.",msg->len); cacheDataToFile(msg->data, msg->len); @@ -217,8 +198,8 @@ void upSend_thread_entry(void* parameter) cacheDataToFile(msg->data, msg->len); } } - rt_sem_release(one_msg_send_done); - list_thread(); +// rt_sem_release(one_msg_send_done); +// list_thread(); return ; } /** @@ -231,9 +212,9 @@ RT_WEAK int upSend(uint8_t *din, size_t len) { LOG_D("try to upsend to TT."); - if (one_msg_send_done == RT_NULL) { - one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO); - } +// if (one_msg_send_done == RT_NULL) { +// one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO); +// } static SMSG msg; memset(&msg, 0, sizeof(SMSG)); @@ -241,12 +222,12 @@ RT_WEAK int upSend(uint8_t *din, size_t len) msg.len=len; // LOG_D("0--%p",&msg); //仅创建一个线程用于发送 - if (rt_sem_take(one_msg_send_done, rt_tick_from_millisecond(10000)) != RT_EOK) { - //10s等待,上一发送仍未完成 - LOG_E("wait error, try to cache %d bytes data to file.",msg.len); - cacheDataToFile(msg.data, msg.len); - return -RT_ERROR; - } +// if (rt_sem_take(one_msg_send_done, rt_tick_from_millisecond(10000)) != RT_EOK) { +// //10s等待,上一发送仍未完成 +// LOG_E("wait error, try to cache %d bytes data to file.",msg.len); +// cacheDataToFile(msg.data, msg.len); +// return -RT_ERROR; +// } /* 创建 serial 线程 */ 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() { 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; rt_uint8_t sysSta=1,commSpeed=0; //长度 @@ -651,7 +632,7 @@ int isInFence(uint8_t *loc); * 打包并检测位置数据 默认10s更新一次 * @return */ -static void packAndSendLoc_thread_entry(void *parameter) +static void reportLoc_thread_entry(void *parameter) { #define CHECK_INTERVAL 15000 size_t i = 0; @@ -677,6 +658,7 @@ static void packAndSendLoc_thread_entry(void *parameter) i += 1 ; if (i*CHECK_INTERVAL > scfg.locRepInterval * 60 * 1000)//定时发送,默认5分钟 { +// LOG_D("%d/%d",i*15,scfg.locRepInterval * 60); i=0; isReadyToSendLoc = 1; } @@ -735,7 +717,7 @@ void reportLoc() // LOG_E("thread 'sendLoc' create failure."); // 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) { @@ -1181,64 +1163,30 @@ static uint8_t iscdlock=0; int cacheDataToFile(uint8_t *din, size_t len) { LOG_I("FUNC = cache to upsend"); -// static uint16_t cnt = 0; -// 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); + int rst = -RT_ERROR; + char f[60]=""; getLstCacheFileName(f); //lock file - if (iscdlock) { + while (iscdlock) { rt_thread_mdelay(1000); } - iscdlock=1; int fd = open(f, O_WRONLY | O_CREAT | O_APPEND); if (fd < 0) { LOG_E("open file %s failed!", f); - return -RT_ERROR; + goto _exit; } else { + iscdlock=1; int rst = write(fd, din, len); if (rst != len) { LOG_E("write to file %s failed!", f); - close(fd); - iscdlock=0; - return -RT_ERROR; + goto _exit; } // cnt += len; close(fd); @@ -1249,11 +1197,15 @@ int cacheDataToFile(uint8_t *din, size_t len) postFileInfo(f,0);//加入待发列表 updateCacheFileName();//更新文件名 } + rst=RT_EOK; + } +_exit: + if (fd) { + close(fd); } - iscdlock=0; - return RT_EOK; + return rst; } void d_cacheData() { diff --git a/applications/getinfo.c b/applications/getinfo.c index ab9e152..740ab06 100644 --- a/applications/getinfo.c +++ b/applications/getinfo.c @@ -371,7 +371,7 @@ void getTT(int argc, char **argv) } /* 创建 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) { @@ -469,7 +469,7 @@ void repGetTT(void) {} memset(rstInfo,0x3f,RST_LEN);//初始化 /* 创建 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) { diff --git a/applications/log2file.c b/applications/log2file.c index a52bafb..cb25b7b 100644 --- a/applications/log2file.c +++ b/applications/log2file.c @@ -69,4 +69,4 @@ void sys_log_file_backend_init(void) ulog_file_backend_enable(file_be); //必须使能才能有效 } 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); diff --git a/applications/tools.c b/applications/tools.c index e51c3bd..a5b0b06 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -406,9 +406,12 @@ char *getLstCacheFileName(char *fin) // getNewCacheFileName(fin); // } char f[60]; - while (!getLstFile(f)) { +// while (!getLstFile(f)) { +// updateCacheFileName(); +// rt_thread_mdelay(1000); +// } + if (!getLstFile(f)) { updateCacheFileName(); - rt_thread_mdelay(1000); } strcpy(fin,f); return fin; diff --git a/applications/uart_3S.c b/applications/uart_3S.c index 980db95..29edcbd 100644 --- a/applications/uart_3S.c +++ b/applications/uart_3S.c @@ -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*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) { diff --git a/rtconfig.h b/rtconfig.h index 72e8737..e7de1da 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -205,6 +205,11 @@ #define ULOG_USING_ISR_LOG #define ULOG_ASSERT_ENABLE #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 */ @@ -390,5 +395,5 @@ /* end of samples: kernel and components samples */ #define RT_STUDIO_BUILT_IN -#define HAL_SRAM_MODULE_ENABLED + #endif