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-18 murmur the first version
|
|
|
|
*/
|
|
|
|
#include <rtthread.h>
|
|
|
|
#define LOG_TAG "cfg"
|
|
|
|
#define LOG_LVL LOG_LVL_DBG
|
|
|
|
#include <ulog.h>
|
|
|
|
#include <cJSON.h>
|
|
|
|
#include <dfs_file.h>
|
2023-05-30 08:53:31 +00:00
|
|
|
#include <cfg.h>
|
2023-05-29 12:49:30 +00:00
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
void getcfg(void)
|
|
|
|
{
|
|
|
|
extern struct rt_messagequeue update_cfg;
|
|
|
|
CFG_MSG msg;
|
|
|
|
while (1)
|
|
|
|
{
|
2023-05-29 12:49:30 +00:00
|
|
|
|
|
|
|
|
2023-05-30 08:53:31 +00:00
|
|
|
rt_memset(&msg, 0, sizeof(msg));
|
|
|
|
/* 从消息队列中读取消息*/
|
|
|
|
rt_err_t result = rt_mq_recv(&update_cfg, &msg, sizeof(msg), RT_WAITING_NO);
|
|
|
|
if (result == RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_I("updatecfg:%10s -->%s", msg.key, msg.value);
|
|
|
|
}
|
|
|
|
rt_thread_delay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void mpcfg()
|
|
|
|
{
|
|
|
|
/* 创建线程 */
|
|
|
|
rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 1, 20, 10);
|
|
|
|
/* 创建成功则启动线程 */
|
|
|
|
if (thread != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_thread_startup(thread);
|
|
|
|
// rt_kprintf("done");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("thread 'pmsg' create failure.");
|
|
|
|
return RT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 导出到自动初始化 */
|
|
|
|
//INIT_COMPONENT_EXPORT(mpcfg);
|
|
|
|
MSH_CMD_EXPORT(mpcfg, 线程消息接收测试);
|