Files

55 lines
1.2 KiB
C
Raw Permalink Normal View History

2026-04-09 10:14:20 +08:00
#include "get_json.h"
#include "cJSON.h"
#include "bsp_uart.h"
#include "string.h"
uint8_t uart_rx_buffer[1024];
json_data_struct json_data;
int get_Json_data(void)
{
int result = -1;
uint16_t uart_get_num = usart_rx_get_rx_data_count(USART_3_TR);
uint16_t arry_size = 0;
if(uart_get_num > 0)
{
usart_rx_recv(USART_3_TR, uart_rx_buffer, uart_get_num);
cJSON *cjson = NULL,*params = NULL,*params_math = NULL;
cjson = cJSON_Parse((const char*)uart_rx_buffer);
memset(uart_rx_buffer,0x00,sizeof(uart_rx_buffer));
if(cjson != NULL)
{
params = cJSON_GetObjectItem(cjson,"params");
params_math = cJSON_GetObjectItem(params,"math");
arry_size = cJSON_GetArraySize(params_math);
if(arry_size >= 2)
{
json_data.min_trigger_res_value = cJSON_GetArrayItem(params_math, 0)->valueint;
json_data.max_trigger_res_value = cJSON_GetArrayItem(params_math, 1)->valueint;
result = 1;
}
}
cJSON_Delete(cjson);
}
else
{
}
return result;
}
uint16_t get_json_min_trigger_res_value(void)
{
return json_data.min_trigger_res_value;
}
uint16_t get_json_max_trigger_res_value(void)
{
return json_data.max_trigger_res_value;
}