update getLstCacheFileName(), write lst filename to ini

This commit is contained in:
CSSC-WORK\murmur 2023-07-29 17:39:28 +08:00
parent 79d4b61bce
commit 4dbcd25af8
5 changed files with 53 additions and 13 deletions

View File

@ -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, )

View File

@ -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);

View File

@ -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);//更新文件名
}

View File

@ -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;
}

View File

@ -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