c83440e33a
基本完成参数更新功能,目前仅加载了部分参数
196 lines
4.3 KiB
C
196 lines
4.3 KiB
C
|
|
|
|
#include <rtthread.h>
|
|
#define LOG_TAG "tool"
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
#include <ulog.h>
|
|
//#include <cJSON.h>
|
|
#include <dfs_file.h>
|
|
#include <usrcfg.h>
|
|
|
|
rt_sem_t TTReady= RT_NULL;//天通具备发送状态后 rt_sem_release(TTReady);
|
|
rt_sem_t cfgUpdate = RT_NULL;
|
|
|
|
|
|
//typedef struct
|
|
//{
|
|
// int sendInterval;
|
|
// int maxTTWaitTime;
|
|
// int maxTTRetryCnt;
|
|
// int minTTPeriCnt;
|
|
// int minTTsinal;
|
|
//} SYS_CFG;
|
|
|
|
#define _CFGALL
|
|
#ifdef _CFGALL
|
|
|
|
SYS_CFG scfg={
|
|
.sendInterval =60,
|
|
.maxTTWaitTime = 4,
|
|
.maxTTRetryCnt = 3,
|
|
.minTTPeriCnt=5,
|
|
.minTTsinal=5,
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
* 更新全局参数
|
|
*/
|
|
void updatecfg(void)
|
|
{
|
|
//因为不知原因,采用事件集独立更新配置出错,无精力深查
|
|
//独立响应单个参数更新事件,程序上更复杂也没特别必要
|
|
//现采用事件通知、统一全部重新加载
|
|
while(1)
|
|
{
|
|
if(rt_sem_take(cfgUpdate, RT_WAITING_FOREVER) == RT_EOK)
|
|
{
|
|
scfg.maxTTWaitTime = get_cfg("maxTTWaitTime");
|
|
scfg.maxTTRetryCnt = get_cfg("maxTTRetryCnt");
|
|
scfg.minTTPeriCnt = get_cfg("minTTPeriCnt");
|
|
scfg.minTTsinal = get_cfg("minTTsinal");
|
|
}
|
|
LOG_D("cfg updated.");
|
|
}
|
|
}
|
|
|
|
//INIT_APP_EXPORT(updatecfg);
|
|
#endif
|
|
|
|
|
|
/**
|
|
* 以HEX显示文件内容
|
|
*/
|
|
void hexFile_thread_entry(void* parameter)
|
|
{
|
|
int fd_in = -1;
|
|
int block_size = 0;
|
|
char *fin = (char *)parameter;
|
|
fd_in = open(fin, O_RDONLY, 0);
|
|
if (fd_in < 0)
|
|
{
|
|
LOG_E("[hex] open the input file : %s error.", fin);
|
|
return RT_ERROR;
|
|
}
|
|
size_t file_size = lseek(fd_in, 0, SEEK_END);
|
|
lseek(fd_in, 0, SEEK_SET);
|
|
|
|
rt_uint8_t *buffer = RT_NULL;
|
|
#define READ_BUFFER_SIZE 512
|
|
buffer = (rt_uint8_t *) malloc(READ_BUFFER_SIZE);
|
|
rt_kprintf("------Start------\n");
|
|
for (size_t i = 0; i < file_size; i += READ_BUFFER_SIZE)
|
|
{
|
|
if ((file_size - i) < READ_BUFFER_SIZE)
|
|
{
|
|
block_size = file_size - i;
|
|
}
|
|
else
|
|
{
|
|
block_size = READ_BUFFER_SIZE;
|
|
}
|
|
|
|
memset(buffer, 0x00, READ_BUFFER_SIZE);
|
|
read(fd_in, buffer, block_size);
|
|
LOG_HEX("hex_file",27,buffer,block_size);
|
|
}
|
|
|
|
rt_free(buffer);
|
|
close(fd_in);
|
|
rt_kprintf("------Done.------\n");
|
|
}
|
|
|
|
void hexFile(int argc, char **argv)
|
|
{
|
|
|
|
if (argc == 2)
|
|
{
|
|
static char f[30];
|
|
rt_strcpy(f,argv[1]);
|
|
/* 创建线程 */
|
|
rt_thread_t thread = rt_thread_create("hex_file", hexFile_thread_entry, (void *) f, 1024 * 1, 25, 10);
|
|
/* 创建成功则启动线程 */
|
|
if (thread != RT_NULL)
|
|
{
|
|
rt_thread_startup(thread);
|
|
}
|
|
else
|
|
{
|
|
LOG_E("thread 'hex_file' create failure.");
|
|
return RT_ERROR;
|
|
}
|
|
}
|
|
}
|
|
MSH_CMD_EXPORT(hexFile,以HEX方式显示文件内容);
|
|
|
|
/**
|
|
* 将当前时间转为字符串
|
|
* @param str 字符串buffer
|
|
* @return 字符串长度
|
|
*/
|
|
int time2Str(char *str)
|
|
{
|
|
static time_t now;
|
|
static struct tm *tm, tm_tmp;
|
|
|
|
now = time(RT_NULL);
|
|
tm = localtime_r(&now, &tm_tmp);
|
|
|
|
/* show the time format MM-DD HH:MM:SS */
|
|
size_t len = rt_snprintf(str, 30, "%04d_%02d_%02d_%02d_%02d_%02d_%03d", 2000+tm->tm_year-100, tm->tm_mon+1,
|
|
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,tm->tm_sec);
|
|
str[len]='\0';
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tm2str(int argc, char **argv)
|
|
{
|
|
char s[30];
|
|
time2Str(s);
|
|
LOG_I("result is %s",s);
|
|
}
|
|
MSH_CMD_EXPORT(tm2str,时间转换为字符串)
|
|
|
|
void sDemo()
|
|
{
|
|
// extern struct rt_event sw_check;//软件条件
|
|
// rt_event_send(&sw_check, FILE_IS_OK);
|
|
void upSWflag(void);
|
|
upSWflag();
|
|
}
|
|
|
|
MSH_CMD_EXPORT(sDemo,喂文件数据);
|
|
|
|
/**
|
|
* 关闭网口,去初始化,释放内存
|
|
*/
|
|
RT_WEAK void rt_hw_stm32_eth_deinit()
|
|
{
|
|
|
|
}
|
|
MSH_CMD_EXPORT(rt_hw_stm32_eth_deinit, 去初始化网络。);
|
|
|
|
|
|
|
|
void TTisReady(void)
|
|
{
|
|
rt_sem_release(TTReady);
|
|
}
|
|
void sysInit()
|
|
{
|
|
|
|
// pwTT_thread_entry("1");//开机
|
|
TTReady = rt_sem_create("TTisReady", 0, RT_IPC_FLAG_PRIO);
|
|
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO);
|
|
rt_sem_release(cfgUpdate);//上电更新值
|
|
// rt_hw_stm32_eth_init();//激活网口
|
|
}
|
|
|
|
INIT_APP_EXPORT(sysInit);
|
|
INIT_APP_EXPORT(updatecfg);
|