From 4dbcd25af829aa8954586b47792caa62927e7796 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Sat, 29 Jul 2023 17:39:28 +0800 Subject: [PATCH] update getLstCacheFileName(), write lst filename to ini --- applications/cfg.c | 38 ++++++++++++++++++++++++++++++++---- applications/cfg.h | 2 +- applications/func/func.c | 5 +++-- applications/tools.c | 19 +++++++++++++----- drivers/stm32f4xx_hal_conf.h | 2 +- 5 files changed, 53 insertions(+), 13 deletions(-) diff --git a/applications/cfg.c b/applications/cfg.c index 889b235..8453ad9 100644 --- a/applications/cfg.c +++ b/applications/cfg.c @@ -47,7 +47,7 @@ void addToList_thread_entry(void *parameter); static void iniUFMsg(void) { /* 初始化消息队列 */ - rt_mq_init(&upfilelist, "updatelist", + rt_mq_init(&upfilelist, "uplist", msg_pool, /* 存放消息的缓冲区 */ sizeof(FILE_INFO), /* 一条消息的最大长度 */ sizeof(msg_pool), /* 存放消息的缓冲区大小 */ @@ -68,7 +68,7 @@ static void iniUFMsg(void) } /* 导出到自动初始化 */ -INIT_COMPONENT_EXPORT(iniUFMsg); +INIT_APP_EXPORT(iniUFMsg); /** * 设置config项 @@ -322,7 +322,7 @@ int clearFileToSend(const char *k) return rst; } -void gf() +static void gf() { int v[MAX_KEY_LEN]; char kstr[10][MAX_KEY_LEN]; @@ -332,7 +332,7 @@ void gf() LOG_I("%s -- %d", kstr[var], v[var]); } } -void add(int argc, char **argv) +static void add(int argc, char **argv) { setFileToSend(argv[1],atoi(argv[2])); gf(); @@ -363,7 +363,37 @@ void postFileInfo(const char *fin, uint8_t index) rt_mq_send(&upfilelist, &msg, sizeof(msg)); } +int updateLstFile(const char *fin) +{ + nsetLock(); + int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND); + if (!rst) { + LOG_E("update lst file error."); + nclearLock(); + return RT_ERROR; + } + nclearLock(); + return RT_EOK; +} + +/** + * 获取最后缓存文件 + * @param k + * @return + */ +int getLstFile(const char *k) +{ + 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(); + return rst; +} MSH_CMD_EXPORT(gf, 查看待发送文件列表) diff --git a/applications/cfg.h b/applications/cfg.h index 30622b0..875bdac 100644 --- a/applications/cfg.h +++ b/applications/cfg.h @@ -26,7 +26,7 @@ #define MAX_KEY_LEN 60 #define SECTION_TO_SEND "tosend" - +#define SECTION_LST_FILE "lstfile" int get_cfg(const char *k); diff --git a/applications/func/func.c b/applications/func/func.c index 4b55d79..f1fe17a 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -960,9 +960,10 @@ int cacheDataToFile(uint8_t *din, size_t len) } // cnt += len; close(fd); - LOG_I("cached %d bytes data to '%s'.",len,f); + size_t size = getFileSize(f); + LOG_I("cached %d bytes data to '%s', new size is %d bytes.",len,f,size); - if (getFileSize(f) > scfg.maxSizePerFile) { + if (size > scfg.maxSizePerFile) { postFileInfo(f,0);//加入待发列表 getNewCacheFileName(f);//更新文件名 } diff --git a/applications/tools.c b/applications/tools.c index 9889eaa..8442638 100644 --- a/applications/tools.c +++ b/applications/tools.c @@ -128,7 +128,10 @@ int time2Byte(uint8_t * t) now = time(RT_NULL); tm = localtime_r(&now, &tm_tmp); - uint8_t tmp[]={tm->tm_year-100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,tm->tm_sec}; + srand((unsigned)now); + uint8_t rnd=(uint8_t)rand()%99; + + uint8_t tmp[]={tm->tm_year-100, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,rnd}; memcpy(t,tmp,sizeof(tmp)); return sizeof(tmp); } @@ -382,7 +385,7 @@ size_t isInByte(uint8_t *din, size_t len, uint8_t *s, size_t slen, uint8_t *dout } -static char cfname[60]=""; +//static char cfname[60]=""; /** * 获取新缓存文件的文件名 * @param fin 指向文件名的数组 @@ -410,7 +413,8 @@ char *getNewCacheFileName(char *fin) // LOG_D("need to creat new file"); strncpy(f + strlen(rootDir), ts, strlen(ts)); - strcpy(cfname,f); +// strcpy(cfname,f); + updateLstFile(f); strcpy(fin,f); return fin; } @@ -424,11 +428,16 @@ char *getNewCacheFileName(char *fin) */ char *getLstCacheFileName(char *fin) { - if (strcmp(cfname,"") == 0) { +// if (strcmp(cfname,"") == 0) { +// getNewCacheFileName(fin); +// } + char f[60]; + if (!getLstFile(f)) { getNewCacheFileName(fin); } - strcpy(fin,cfname); + strcpy(fin,f); return fin; + } diff --git a/drivers/stm32f4xx_hal_conf.h b/drivers/stm32f4xx_hal_conf.h index c502031..14bbc2e 100644 --- a/drivers/stm32f4xx_hal_conf.h +++ b/drivers/stm32f4xx_hal_conf.h @@ -68,7 +68,7 @@ /* #define HAL_I2S_MODULE_ENABLED */ #define HAL_IWDG_MODULE_ENABLED /* #define HAL_LTDC_MODULE_ENABLED */ - #define HAL_RNG_MODULE_ENABLED +/* #define HAL_RNG_MODULE_ENABLED */ #define HAL_RTC_MODULE_ENABLED /* #define HAL_SAI_MODULE_ENABLED */ #define HAL_SD_MODULE_ENABLED