第一次提交
This commit is contained in:
54
Bsp/get_json.c
Normal file
54
Bsp/get_json.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user