g0b1vetx-board/Application/cfgthread.c
2584532475@qq.com 0f40dd8b17 网络自适应
2024-09-10 11:51:07 +08:00

126 lines
2.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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>
#include <elog.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");
elog_stop();
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();
elog_start();
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 ;
}