diff --git a/main/gatts_demo.c b/main/gatts_demo.c index 2088279..0a5bef1 100644 --- a/main/gatts_demo.c +++ b/main/gatts_demo.c @@ -219,6 +219,7 @@ void bluetooth_gatts_try_process_data(); void timer_set_pause_and_counter_zero(int group, int timer); void port_timer_delay_ms(uint64_t delay); void start_receive_data_to_buffer(uint16_t length, uint8_t *value); +bool parse_rxbuffer_and_validation_data(cJSON **json_tmp); static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { @@ -882,19 +883,12 @@ void bluetooth_gatts_try_process_data() //打印输出 ESP_LOGI(GATTS_TAG, "%s", &bluetooth_rx_buffer[0]); - //解析数据 - json_tmp = cJSON_Parse(&bluetooth_rx_buffer[0]); - //验证解析数据是否正确 - if (json_tmp == NULL) + if (!parse_rxbuffer_and_validation_data(&json_tmp)) { - ESP_LOGE("ERROR", "json_tmp null"); - cJSON_Delete(json_tmp); - buffer_all_init(); - bluetooth_rx_buffer_start_receving = false; - bluetooth_rx_buffer_processing = false; return; } + ch = json_tmp->child; while (ch != NULL) @@ -965,4 +959,19 @@ void start_receive_data_to_buffer(uint16_t length, uint8_t *value) bluetooth_rx_buffer[bluetooth_rx_buffer_len++] = value[i]; } } +} + +bool parse_rxbuffer_and_validation_data(cJSON **json_tmp) +{ + *json_tmp = cJSON_Parse(&bluetooth_rx_buffer[0]); + if (*json_tmp == NULL) + { + ESP_LOGE("ERROR", "json_tmp null"); + cJSON_Delete(*json_tmp); + buffer_all_init(); + bluetooth_rx_buffer_start_receving = false; + bluetooth_rx_buffer_processing = false; + return false; + } + return true; } \ No newline at end of file