diff --git a/main/gatts_demo.c b/main/gatts_demo.c index 55298c1..a49c56f 100644 --- a/main/gatts_demo.c +++ b/main/gatts_demo.c @@ -876,11 +876,26 @@ void timer_set_pause_and_counter_zero(int group, int timer) timer_set_counter_value(group, timer, 0); } +bool validation_param(cJSON *object, char *param) +{ + cJSON *current_element = object->child; + + while (current_element->string != NULL) + { + if (current_element->string == param) + { + return true; + } + current_element = current_element->next; + } + return false; +} + void bluetooth_gatts_try_process_data() { cJSON *json_tmp; cJSON *ch; - uint8_t json_temp_size = 0; + uint8_t json_temp_size = 10; //接收完毕 if (bluetooth_rx_buffer_processing) { @@ -891,51 +906,39 @@ void bluetooth_gatts_try_process_data() //处理数据 json_tmp = cJSON_Parse(&bluetooth_rx_buffer[0]); - - //打印json_temp ch = json_tmp->child; - for (int i = 0; i < json_temp_size; i++) - { - ESP_LOGI("JSON", "type:%d", ch->type); - if (ch->type == cJSON_Invalid) - { - } - - if (ch->type == cJSON_False) - { - } - - if (ch->type == cJSON_True) - { - } - - if (ch->type == cJSON_NULL) - { - } - if (ch->type == cJSON_Number) - { - ESP_LOGI("JSON NUMBER", "name:%s ,value :%d", ch->string, ch->valueint); - } - - if (ch->type == cJSON_String) - { - ESP_LOGI("JSON STRING", "name:%s ,value :%s", ch->string, ch->valuestring); - } - - if (ch->type == cJSON_Array) - { - } - - if (ch->type == cJSON_Object) - { - } - - if (ch->type == cJSON_Raw) - { + while (ch != NULL) + { + ESP_LOGI(GATTS_TAG, "%s", ch->string); + if (strcmp(ch->string,"order") == 0){ + ESP_LOGI("!!!!!!!!","##############"); } ch = ch->next; } + + // if (validation_param(json_tmp, "order")) + // { + // ESP_LOGI("JSON", "order value:%s", cJSON_GetObjectItem(json_tmp, "order")->valuestring); + // } + // if (validation_param(json_tmp, "index")) + // { + // ESP_LOGI("JSON", "index value:%d", cJSON_GetObjectItem(json_tmp, "index")->valueint); + // } + // if (validation_param(json_tmp, "speedLevel")) + // { + // ESP_LOGI("JSON", "speedLevel value:%d", cJSON_GetObjectItem(json_tmp, "speedLevel")->valueint); + // } + // if (validation_param(json_tmp, "position")) + // { + // ESP_LOGI("JSON", "position value:%lf", cJSON_GetObjectItem(json_tmp, "position")->valuedouble); + // } + // if (validation_param(json_tmp, "direction")) + // { + // ESP_LOGI("JSON", "direction value:%d", cJSON_GetObjectItem(json_tmp, "direction")->valueint); + // } + + //释放空间 cJSON_Delete(json_tmp); // buffer置0 buffer_all_init();