2023-05-29 12:49:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
* 2023-05-29 murmur the first version
|
|
|
|
|
*/
|
2023-06-17 10:26:40 +00:00
|
|
|
|
//#include "../packages/minIni-v1.2.0/dev/minIni.h"
|
|
|
|
|
#include "minIni.h"
|
2023-08-27 04:31:54 +00:00
|
|
|
|
#include "cfg.h"
|
2023-05-29 12:49:30 +00:00
|
|
|
|
#ifdef PKG_USING_MININI
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
|
|
|
|
//#define LJW_CFG_FILE_NAME "/cfg.ini"
|
|
|
|
|
//#define FILE_TO_SEND "/sd/tosend.ini"//避免读写出错造成系统配置文件丢失
|
2023-05-29 12:49:30 +00:00
|
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
|
#define LOG_TAG "cfg"
|
|
|
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
|
|
|
#include <ulog.h>
|
|
|
|
|
|
|
|
|
|
|
2023-08-27 04:31:54 +00:00
|
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
|
|
2023-08-25 08:36:00 +00:00
|
|
|
|
volatile static uint8_t islock=0;
|
2023-09-01 08:59:49 +00:00
|
|
|
|
static rt_mutex_t isCfgOk=RT_NULL;
|
|
|
|
|
static rt_mutex_t isTosendOk=RT_NULL;
|
2023-09-02 11:33:16 +00:00
|
|
|
|
void initCfgMutex()
|
2023-09-01 08:59:49 +00:00
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
isCfgOk = rt_mutex_create("isCfgOk", RT_IPC_FLAG_FIFO);
|
|
|
|
|
isTosendOk = rt_mutex_create("isTosendOk", RT_IPC_FLAG_FIFO);
|
2023-09-01 08:59:49 +00:00
|
|
|
|
}
|
2023-09-05 10:53:01 +00:00
|
|
|
|
INIT_APP_EXPORT(initCfgMutex);
|
2023-09-01 08:59:49 +00:00
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
static void setLock()
|
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
rt_mutex_take(isCfgOk, RT_WAITING_FOREVER);
|
|
|
|
|
// LOG_W("------file locked------");
|
2023-09-01 08:59:49 +00:00
|
|
|
|
return;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
while(islock)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_mdelay(1000);
|
2023-08-27 04:31:54 +00:00
|
|
|
|
LOG_W("------file locked");
|
2023-07-29 08:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
islock=1;
|
|
|
|
|
}
|
|
|
|
|
static void clearLock()
|
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
rt_mutex_release(isCfgOk);
|
|
|
|
|
// LOG_W("=====file unlocked=====");
|
2023-09-04 09:45:03 +00:00
|
|
|
|
return;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
islock=0;
|
2023-09-02 11:33:16 +00:00
|
|
|
|
LOG_W("------file unlocked");
|
2023-07-29 08:08:15 +00:00
|
|
|
|
}
|
2023-06-20 10:09:07 +00:00
|
|
|
|
extern rt_sem_t cfgUpdate;
|
2023-08-04 06:09:39 +00:00
|
|
|
|
int get_cfg(const char *k);
|
2023-08-24 03:06:44 +00:00
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2023-08-01 08:27:21 +00:00
|
|
|
|
char fname[60];
|
2023-07-29 08:08:15 +00:00
|
|
|
|
uint8_t index;
|
|
|
|
|
}FILE_INFO;
|
2023-08-04 06:09:39 +00:00
|
|
|
|
|
2023-06-01 02:23:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* 设置config项
|
|
|
|
|
* @param s
|
|
|
|
|
* @param k
|
|
|
|
|
* @param v
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-08-03 03:04:50 +00:00
|
|
|
|
int set_cfg(const char *k, long v)
|
2023-05-30 08:53:31 +00:00
|
|
|
|
{
|
2023-08-29 11:29:58 +00:00
|
|
|
|
int rst = 0;
|
2023-08-04 06:09:39 +00:00
|
|
|
|
if (v == get_cfg(k)) {
|
2023-08-29 11:29:58 +00:00
|
|
|
|
// LOG_D("nothing needs to change.");
|
|
|
|
|
rst = 1;
|
2023-08-04 06:09:39 +00:00
|
|
|
|
}
|
2023-08-29 11:29:58 +00:00
|
|
|
|
else {
|
2023-08-03 03:04:50 +00:00
|
|
|
|
|
2023-08-29 11:29:58 +00:00
|
|
|
|
setLock();
|
|
|
|
|
// int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
|
|
|
|
|
rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
|
|
|
|
|
clearLock();
|
|
|
|
|
}
|
|
|
|
|
if (rst == 1) {
|
|
|
|
|
// LOG_I("set value success.");
|
2023-08-03 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-30 02:45:32 +00:00
|
|
|
|
LOG_E("set %s value fault.",k);
|
2023-08-03 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int set_cfgs(const char *k, const char * v)
|
|
|
|
|
{
|
2023-08-30 02:45:32 +00:00
|
|
|
|
int rst=0;
|
2023-08-03 03:04:50 +00:00
|
|
|
|
|
2023-08-08 06:31:16 +00:00
|
|
|
|
if (strcmp(v,"NULL") == 0) {//delete key
|
2023-08-03 03:04:50 +00:00
|
|
|
|
v = NULL;
|
2023-06-01 02:23:08 +00:00
|
|
|
|
}
|
2023-08-30 02:45:32 +00:00
|
|
|
|
|
2023-09-11 11:08:16 +00:00
|
|
|
|
char tmp[128];
|
2023-08-08 06:31:16 +00:00
|
|
|
|
get_cfgs(k,tmp);
|
2023-08-30 02:45:32 +00:00
|
|
|
|
// LOG_D("v=%s-----%s",v,tmp);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
if (strcmp(v,tmp) == 0) {
|
2023-08-30 02:45:32 +00:00
|
|
|
|
// LOG_D("nothing needs to change.");
|
|
|
|
|
rst = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setLock();
|
|
|
|
|
rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
|
|
|
|
|
clearLock();
|
2023-08-08 06:31:16 +00:00
|
|
|
|
}
|
2023-08-03 03:04:50 +00:00
|
|
|
|
// int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
|
2023-05-30 08:53:31 +00:00
|
|
|
|
if (rst == 1) {
|
2023-08-30 02:45:32 +00:00
|
|
|
|
// LOG_I("set value success.");
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-30 02:45:32 +00:00
|
|
|
|
LOG_E("set %s value fault.",k);
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
|
return rst;
|
|
|
|
|
}
|
2023-08-04 06:09:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* 返回指定键的值
|
|
|
|
|
* @param k
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-05-30 08:53:31 +00:00
|
|
|
|
int get_cfg(const char *k)
|
|
|
|
|
{
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// setLock();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
// char buf[MAX_KEY_LEN];
|
|
|
|
|
// int rst = ini_gets("config",k,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
|
|
|
|
|
// if(strcmp(buf, "000000") == 0) {
|
|
|
|
|
// // 采用默认值
|
2023-09-01 03:38:33 +00:00
|
|
|
|
int rst = ini_getl("config", k, -3.14, LJW_CFG_FILE_NAME);
|
|
|
|
|
if (rst == -3.14) {
|
2023-05-30 08:53:31 +00:00
|
|
|
|
LOG_W("no such KEY:%s",k);
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-09-01 03:38:33 +00:00
|
|
|
|
// return -RT_ERROR;
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-06-01 09:10:00 +00:00
|
|
|
|
// LOG_I("%s = %s",k,buf);
|
2023-06-19 07:56:45 +00:00
|
|
|
|
// LOG_I("%s = %d",k,rst);
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-05-30 08:53:31 +00:00
|
|
|
|
return rst;
|
|
|
|
|
}
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
2023-08-08 06:31:16 +00:00
|
|
|
|
int get_cfgs(const char *k, char *str)
|
2023-08-03 03:04:50 +00:00
|
|
|
|
{
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// setLock();
|
2023-08-03 03:04:50 +00:00
|
|
|
|
char buf[MAX_KEY_LEN];
|
|
|
|
|
int rst = ini_gets("config",k,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
|
|
|
|
|
if(strcmp(buf, "000000") == 0) {
|
|
|
|
|
// // 采用默认值
|
|
|
|
|
// int rst = ini_getl("config", k, -1, LJW_CFG_FILE_NAME);
|
|
|
|
|
// if (rst == -1) {
|
|
|
|
|
LOG_W("no such KEY:%s",k);
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-08-03 03:04:50 +00:00
|
|
|
|
return -RT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// LOG_I("%s = %s",k,buf);
|
|
|
|
|
// LOG_I("%s = %d",k,rst);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
strcpy(str,buf);
|
2023-08-03 03:04:50 +00:00
|
|
|
|
}
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-08-03 03:04:50 +00:00
|
|
|
|
return rst;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
static void get_cfg_all(void)
|
2023-05-30 08:53:31 +00:00
|
|
|
|
{
|
2023-06-01 09:10:00 +00:00
|
|
|
|
char buf[MAX_KEY_LEN];
|
|
|
|
|
char kstr[MAX_KEY_LEN];
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
|
|
|
|
LOG_I("%23s","---CONFIG---");
|
2023-06-01 09:10:00 +00:00
|
|
|
|
for (size_t k = 0; ini_getkey("config", k, kstr, MAX_KEY_LEN, LJW_CFG_FILE_NAME) > 0; k++) {
|
|
|
|
|
int rst = ini_gets("config",kstr,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
|
2023-06-01 02:23:08 +00:00
|
|
|
|
LOG_I("%16s = %s",kstr,buf);
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
|
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
static void cfg(int argc, char ** argv)
|
2023-05-30 08:53:31 +00:00
|
|
|
|
{
|
|
|
|
|
if (argc == 1) {//无键无值,遍历
|
2023-06-01 02:23:08 +00:00
|
|
|
|
get_cfg_all();
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
if (argc == 2) {//有键无值,查询
|
|
|
|
|
get_cfg(argv[1]);
|
|
|
|
|
}
|
|
|
|
|
if (argc == 3) {//有键有值,设置
|
2023-08-04 06:09:39 +00:00
|
|
|
|
set_cfgs(argv[1], argv[2]);
|
2023-05-30 08:53:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 02:23:08 +00:00
|
|
|
|
static void get_sta_all(void)
|
|
|
|
|
{
|
2023-06-01 09:10:00 +00:00
|
|
|
|
char buf[MAX_KEY_LEN];
|
|
|
|
|
char kstr[MAX_KEY_LEN];
|
2023-06-01 02:23:08 +00:00
|
|
|
|
LOG_I("%23s","---STATS---");
|
2023-06-01 09:10:00 +00:00
|
|
|
|
for (size_t k = 0; ini_getkey("stats", k, kstr, MAX_KEY_LEN, LJW_CFG_FILE_NAME) > 0; k++) {
|
|
|
|
|
int rst = ini_gets("stats",kstr,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
|
2023-06-01 02:23:08 +00:00
|
|
|
|
LOG_I("%16s = %s",kstr,buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-30 10:00:42 +00:00
|
|
|
|
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
|
|
|
|
//以下针对stats
|
|
|
|
|
/**
|
2023-07-10 02:42:26 +00:00
|
|
|
|
* 读取stats节信息
|
2023-06-01 02:23:08 +00:00
|
|
|
|
* @param k
|
|
|
|
|
* return 成功返回值,错误返回RT_ERROR
|
|
|
|
|
*/
|
2023-06-02 02:23:26 +00:00
|
|
|
|
long get_val(const char *k)
|
2023-06-01 02:23:08 +00:00
|
|
|
|
{
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// setLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
long v= ini_getl("stats", k, -1, LJW_CFG_FILE_NAME);
|
|
|
|
|
if( v == -1)
|
|
|
|
|
{
|
|
|
|
|
LOG_W("no such KEY:%s",k);
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
return -RT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-27 04:31:54 +00:00
|
|
|
|
// clearLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 02:23:26 +00:00
|
|
|
|
int set_val(const char *k, long v)
|
2023-06-01 02:23:08 +00:00
|
|
|
|
{
|
2023-07-29 08:08:15 +00:00
|
|
|
|
setLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
if(!ini_putl("stats",k,v,LJW_CFG_FILE_NAME))
|
|
|
|
|
{
|
|
|
|
|
LOG_E("write %s error.",k);
|
2023-07-29 08:08:15 +00:00
|
|
|
|
clearLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
return -RT_ERROR;
|
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
clearLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
return RT_EOK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新统计值,每次自加1
|
|
|
|
|
* @param k
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int add_val(const char *k)
|
|
|
|
|
{
|
2023-07-29 08:08:15 +00:00
|
|
|
|
// setLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
long ori = get_val(k);
|
2023-06-19 07:56:45 +00:00
|
|
|
|
rt_thread_mdelay(100);
|
2023-06-01 02:23:08 +00:00
|
|
|
|
if (ori != -1) {
|
2023-09-01 08:59:49 +00:00
|
|
|
|
setLock();
|
2023-06-20 10:09:07 +00:00
|
|
|
|
int ret = set_val(k, ori+1);
|
2023-09-01 08:59:49 +00:00
|
|
|
|
clearLock();
|
2023-06-20 10:09:07 +00:00
|
|
|
|
rt_thread_mdelay(100);
|
|
|
|
|
return ret;
|
2023-06-01 02:23:08 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ori;
|
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
// clearLock();
|
2023-06-01 02:23:08 +00:00
|
|
|
|
}
|
|
|
|
|
static void get_sta(const char *k)
|
|
|
|
|
{
|
|
|
|
|
long v = get_val(k);
|
|
|
|
|
if (!v) {
|
|
|
|
|
LOG_I("%s = %d",k,v);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-30 08:53:31 +00:00
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
static void sta(int argc, char ** argv)
|
2023-06-01 02:23:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (argc == 1)
|
|
|
|
|
{ //无键无值,遍历
|
|
|
|
|
get_sta_all();
|
|
|
|
|
}
|
|
|
|
|
if (argc == 2)
|
|
|
|
|
{ //有键无值,查询
|
|
|
|
|
get_sta(argv[1]);
|
|
|
|
|
}
|
|
|
|
|
if (argc == 3)
|
|
|
|
|
{
|
|
|
|
|
LOG_W("READ ONLY.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 10:00:42 +00:00
|
|
|
|
|
2023-06-01 02:23:08 +00:00
|
|
|
|
|
|
|
|
|
static void clear_sta(void)
|
|
|
|
|
{
|
|
|
|
|
char buf[16];
|
|
|
|
|
char kstr[16];
|
|
|
|
|
for (size_t k = 0; ini_getkey("stats", k, kstr, 16, LJW_CFG_FILE_NAME) > 0; k++) {
|
|
|
|
|
if (rt_strcmp("swCnt",kstr) != 0) {
|
|
|
|
|
set_val(kstr, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-05 00:36:41 +00:00
|
|
|
|
MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, reset sta info)
|
2023-05-30 08:53:31 +00:00
|
|
|
|
|
2023-08-25 08:36:00 +00:00
|
|
|
|
volatile size_t nislock=0;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
static void nsetLock()
|
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
|
2023-09-06 03:18:11 +00:00
|
|
|
|
// LOG_W("------file locked------");
|
2023-09-06 01:51:08 +00:00
|
|
|
|
return;
|
2023-08-25 08:36:00 +00:00
|
|
|
|
// LOG_D("--%d--",nislock);
|
|
|
|
|
size_t cnt=10;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
while(nislock)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_mdelay(1000);
|
2023-08-25 08:36:00 +00:00
|
|
|
|
LOG_W("file is locked.");
|
|
|
|
|
cnt += 1;
|
|
|
|
|
if (cnt>10) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
nislock=1;
|
|
|
|
|
}
|
|
|
|
|
static void nclearLock()
|
|
|
|
|
{
|
2023-09-06 01:51:08 +00:00
|
|
|
|
rt_mutex_release(isTosendOk);
|
2023-09-06 03:18:11 +00:00
|
|
|
|
// LOG_W("=====file unlocked=====");
|
2023-09-06 01:51:08 +00:00
|
|
|
|
return;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
nislock=0;
|
2023-08-25 08:36:00 +00:00
|
|
|
|
LOG_W("file is unlocked.");
|
2023-07-29 08:08:15 +00:00
|
|
|
|
}
|
2023-08-24 03:06:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int setFileToSend_thread_entry(void *parameter)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-08-24 03:06:44 +00:00
|
|
|
|
FILE_INFO *msg;
|
|
|
|
|
msg=(FILE_INFO * )parameter;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
nsetLock();
|
|
|
|
|
|
2023-08-24 03:06:44 +00:00
|
|
|
|
int rst = ini_putl(SECTION_TO_SEND, msg->fname, msg->index, FILE_TO_SEND);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
nclearLock();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
if (!rst) {
|
|
|
|
|
LOG_E("add file to send error.");
|
|
|
|
|
}
|
2023-08-24 03:06:44 +00:00
|
|
|
|
LOG_D("add %s-%d to list.",msg->fname,msg->index);
|
|
|
|
|
fileIsReady();
|
|
|
|
|
|
|
|
|
|
// list_thread();
|
|
|
|
|
// return RT_EOK;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
2023-09-14 09:30:01 +00:00
|
|
|
|
void manualAaddlst(char *f)
|
|
|
|
|
{
|
|
|
|
|
nsetLock();
|
|
|
|
|
int rst = ini_putl(SECTION_TO_SEND, f, 0, FILE_TO_SEND);
|
|
|
|
|
nclearLock();
|
|
|
|
|
if (!rst) {
|
|
|
|
|
LOG_E("manual add file to send error.");
|
|
|
|
|
}
|
|
|
|
|
LOG_D("add %s-0 to list.",f);
|
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
/**
|
2023-08-24 03:06:44 +00:00
|
|
|
|
* 添加待发文件到列表
|
|
|
|
|
* @param fin
|
|
|
|
|
* @param index
|
|
|
|
|
*/
|
|
|
|
|
void postFileInfo(const char *fin, uint8_t index)
|
|
|
|
|
{
|
|
|
|
|
static FILE_INFO msg;
|
|
|
|
|
strcpy(msg.fname,fin);
|
|
|
|
|
msg.index=index;
|
|
|
|
|
/* 创建 serial 线程 */
|
2023-08-25 08:36:00 +00:00
|
|
|
|
rt_thread_t thread = rt_thread_create("filelist", setFileToSend_thread_entry, (void *)&msg, 1024*5, 30-2, 10);
|
2023-08-24 03:06:44 +00:00
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG_E("thread 'updatelist' create failure.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取待发送文件列表,未减小内存占用,暂每次只读取5个
|
2023-08-01 08:27:21 +00:00
|
|
|
|
* @param kstr 待发包文件名,二维数组
|
|
|
|
|
* @param v 对应包文件的索引,默认为0即全发
|
|
|
|
|
* @return 待发文件个数
|
2023-06-01 09:10:00 +00:00
|
|
|
|
*/
|
2023-08-08 06:31:16 +00:00
|
|
|
|
size_t getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
|
|
|
|
// char buf[MAX_KEY_LEN];
|
|
|
|
|
// char kstr[MAX_KEY_LEN];
|
2023-08-25 08:36:00 +00:00
|
|
|
|
// nsetLock();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
size_t len=0;
|
2023-07-29 08:08:15 +00:00
|
|
|
|
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);
|
2023-06-01 09:10:00 +00:00
|
|
|
|
len +=1;
|
2023-08-08 06:31:16 +00:00
|
|
|
|
if (len>5) {
|
2023-09-06 03:18:11 +00:00
|
|
|
|
// break;
|
2023-08-08 06:31:16 +00:00
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
2023-08-25 08:36:00 +00:00
|
|
|
|
// nclearLock();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
return len;
|
|
|
|
|
}
|
2023-09-06 03:18:11 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取待发文件个数
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
size_t getCntOfFileToSend(void)
|
|
|
|
|
{
|
|
|
|
|
size_t len=0;
|
|
|
|
|
char tmp[100];
|
|
|
|
|
for (size_t k = 0; ini_getkey(SECTION_TO_SEND, k, tmp, sizeof(tmp), FILE_TO_SEND) > 0; k++) {
|
|
|
|
|
len = k + 1;
|
|
|
|
|
}
|
|
|
|
|
// LOG_D("cnt=%d",len);
|
|
|
|
|
return len;
|
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* 清空待发送文件记录
|
|
|
|
|
*/
|
|
|
|
|
int clearFileToSend(const char *k)
|
|
|
|
|
{
|
2023-07-29 08:08:15 +00:00
|
|
|
|
nsetLock();
|
|
|
|
|
int rst = ini_puts(SECTION_TO_SEND, k, NULL, FILE_TO_SEND);
|
|
|
|
|
if (!rst)
|
|
|
|
|
{
|
|
|
|
|
LOG_E("clear file to send error.");
|
|
|
|
|
}
|
|
|
|
|
nclearLock();
|
|
|
|
|
return rst;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 09:39:28 +00:00
|
|
|
|
static void gf()
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2023-09-06 03:18:11 +00:00
|
|
|
|
size_t cnt = getCntOfFileToSend();
|
|
|
|
|
|
|
|
|
|
// return;
|
2023-06-01 09:10:00 +00:00
|
|
|
|
int v[MAX_KEY_LEN];
|
2023-09-06 03:18:11 +00:00
|
|
|
|
char kstr[cnt][MAX_KEY_LEN];
|
2023-08-08 06:31:16 +00:00
|
|
|
|
if (!cnt) {
|
|
|
|
|
LOG_D("no files waiting to be sent");
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-07-29 08:08:15 +00:00
|
|
|
|
{
|
2023-09-06 03:18:11 +00:00
|
|
|
|
getFilesToSend(kstr, v);
|
2023-08-08 06:31:16 +00:00
|
|
|
|
for (size_t var = 0; var < cnt; var++)
|
|
|
|
|
{
|
|
|
|
|
LOG_I("%s -- %d", kstr[var], v[var]);
|
|
|
|
|
}
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-08 06:31:16 +00:00
|
|
|
|
|
2023-07-29 09:39:28 +00:00
|
|
|
|
static void add(int argc, char **argv)
|
2023-06-01 09:10:00 +00:00
|
|
|
|
{
|
2024-01-05 00:36:41 +00:00
|
|
|
|
if (argc == 3) {
|
|
|
|
|
postFileInfo(argv[1],atoi(argv[2]));
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 03:18:11 +00:00
|
|
|
|
// gf();
|
2023-08-24 03:06:44 +00:00
|
|
|
|
// clearFileToSend(argv[1]);
|
|
|
|
|
// gf();
|
2023-06-01 09:10:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
2023-08-24 03:06:44 +00:00
|
|
|
|
|
|
|
|
|
|
2023-07-29 08:08:15 +00:00
|
|
|
|
|
2023-08-23 03:02:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新最后缓存的文件
|
|
|
|
|
* @param k
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2023-09-02 07:23:32 +00:00
|
|
|
|
int setLstFile(const char *fin)
|
2023-07-29 09:39:28 +00:00
|
|
|
|
{
|
|
|
|
|
nsetLock();
|
|
|
|
|
|
|
|
|
|
int rst = ini_puts(SECTION_LST_FILE, "lst", fin, FILE_TO_SEND);
|
2023-08-25 08:36:00 +00:00
|
|
|
|
nclearLock();
|
2023-07-29 09:39:28 +00:00
|
|
|
|
if (!rst) {
|
2023-09-02 07:23:32 +00:00
|
|
|
|
LOG_E("set lst file error.");
|
2023-07-29 09:39:28 +00:00
|
|
|
|
return RT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return RT_EOK;
|
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
|
2023-07-29 09:39:28 +00:00
|
|
|
|
/**
|
2023-08-23 03:02:26 +00:00
|
|
|
|
* 获取最后缓存的文件
|
2023-07-29 09:39:28 +00:00
|
|
|
|
* @param k
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
int getLstFile(const char *k)
|
|
|
|
|
{
|
2023-08-25 08:36:00 +00:00
|
|
|
|
// nsetLock();
|
2023-07-29 09:39:28 +00:00
|
|
|
|
char tmp[60];
|
|
|
|
|
int rst = ini_gets(SECTION_LST_FILE, "lst", "000",tmp,60, FILE_TO_SEND);
|
2023-08-31 08:12:44 +00:00
|
|
|
|
if (strcmp(tmp,"000") == 0) {
|
2023-07-29 09:39:28 +00:00
|
|
|
|
rst=0;
|
|
|
|
|
}
|
|
|
|
|
strcpy(k,tmp);
|
2023-08-25 08:36:00 +00:00
|
|
|
|
// nclearLock();
|
2023-07-29 09:39:28 +00:00
|
|
|
|
return rst;
|
|
|
|
|
}
|
2023-07-29 08:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
2023-06-01 09:10:00 +00:00
|
|
|
|
MSH_CMD_EXPORT(gf, 查看待发送文件列表)
|
2024-01-05 00:36:41 +00:00
|
|
|
|
MSH_CMD_EXPORT_ALIAS(add, cf,add file to list)
|
|
|
|
|
MSH_CMD_EXPORT(sta, check sta info)
|
|
|
|
|
MSH_CMD_EXPORT(cfg, 配置系统参数,支持参数)
|
2023-06-01 02:23:08 +00:00
|
|
|
|
//set_if()
|
2023-05-29 12:49:30 +00:00
|
|
|
|
#endif
|