引入mqtt 引入cjson

This commit is contained in:
2584532475@qq.com committed 2023-11-30 08:10:01 +08:00
1 parent a69c1a58d6
commit f8591b8b99
86 files changed
+12141 -2157

No files matched your search

+123
View File
@@ -0,0 +1,123 @@
#include "main.h"
#include "os-app.h"
#include <stdio.h>
#include <rtthread.h>
#include "usart-board.h"
#include "data.h"
#include "easyflash.h"
#include <string.h>
ALIGN (RT_ALIGN_SIZE)
static char thread_stack[1024];
static struct rt_thread thread;
void cfg_rx_done (void)
{
rt_event_send (gUartEvents, EVENT_UART_CONFIG_RX);
}
extern void shell_recover (void);
static char tx_buff[1024];
static void thread_entry (void * argument)
{
int tx_size ;
g_DebugDrv.rxdone = cfg_rx_done;
rt_kprintf ("%s was start!\r\n", __FILE__);
rt_kprintf ("config input\r\n");
g_ifconfig = 1;
char * p;
char key[32], value[32];
while (1)
{
if (RT_EOK == rt_event_recv (gUartEvents, EVENT_UART_CONFIG_RX, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 0, RT_NULL))
{
if (rt_memcmp ("config=envs\r\n", g_DebugDrv.rx_buffer, g_DebugDrv.rx_size) == 0) // 读取配置
{
MX_UART_PutBuffer (&g_DebugDrv, "config:\r\n", rt_strlen ("config:\r\n"));
ef_print_env();
}
if (rt_memcmp ("config=exit\r\n", g_DebugDrv.rx_buffer, g_DebugDrv.rx_size) == 0)
{
break;
}
if (rt_memcmp ("config=fact\r\n", g_DebugDrv.rx_buffer, g_DebugDrv.rx_size) == 0)
{
ef_env_set_default();
printf ("config fact\r\n");
}
if (rt_memcmp ("\r\nconfig\r\n", g_DebugDrv.rx_buffer, g_DebugDrv.rx_size) == 0)
{
MX_UART_PutBuffer (&g_DebugDrv, "config input\r\n", rt_strlen ("config input\r\n"));
}
if (rt_memcmp ("config=set\r\n", g_DebugDrv.rx_buffer, rt_strlen ("config=set\r\n")) == 0)
{
p = g_DebugDrv.rx_buffer;
p = strtok (p, "\r\n");
while (1)
{
if (p)
{
rt_memset (key, 0, 32);
rt_memset (value, 0, 32);
for (int i = 0; i < rt_strlen (p); i++)
{
if (p[i] == '=')
{
rt_sprintf (key, "%*.s", i, p);
rt_sprintf (value, "%*.s", rt_strlen (p) - i - 1, &p[i + 1]);
}
}
if (ef_get_env (key) != NULL)
{
ef_set_env (key, value);
}
p = strtok (NULL, "\r\n");
}
else
{
break;
}
}
//ef_save_env();
printf ("config succ\r\n");
}
if (rt_memcmp ("\r\nreboot\r\n", g_DebugDrv.rx_buffer, g_DebugDrv.rx_size) == 0)
{
HAL_NVIC_SystemReset();
}
MX_UART_Clear (&g_DebugDrv);
}
rt_thread_delay (10);
}
shell_recover();
g_ifconfig = 0;
rt_kprintf ("config exit\r\n");
}
//char * WriteEasyFlash(char *p)
//{
// if ()
//}
void CFGThreadStart (void)
{
/* 创建线程1,名称是thread1,入口是thread1_entry*/
rt_thread_init (&thread, "cfgthread",
thread_entry, RT_NULL,
&thread_stack[0],
sizeof (thread_stack),
CFG_THREAD_PRIORITY, CFG_THREAD_TIMESLICE);
rt_thread_startup (&thread);
return ;
}