diff --git a/main/gatts_demo.c b/main/gatts_demo.c index 96a7bca..55298c1 100644 --- a/main/gatts_demo.c +++ b/main/gatts_demo.c @@ -194,6 +194,29 @@ static prepare_type_env_t b_prepare_write_env; void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param); void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param); +/*********************************************************************************************************************** + * ****************************************************user_define**************************************************** * + ***********************************************************************************************************************/ +//实际只让接收profile_b_buffer_size-1个 +#define profile_b_buffer_size 100 +char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; +uint8_t bluetooth_rx_buffer_len = 0; +bool bluetooth_rx_buffer_processing = false; + +bool flag = true; +uint32_t total = 0; +#define timer_interval_num 100 +#define timer_interval_s (uint32_t)1000000 +#define timer_interval_ms (uint32_t)1000 +#define timer_interval_us (uint32_t)1 + +/*********************************************************************************************************************** + * **********************************************user_function_statement********************************************** * + ***********************************************************************************************************************/ +void buffer_all_init(); +void bluetooth_gatts_try_process_data(); +void timer_set_pause_and_counter_zero(int group, int timer); + static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { switch (event) @@ -402,46 +425,6 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i } case ESP_GATTS_WRITE_EVT: { - // ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d", param->write.conn_id, param->write.trans_id, param->write.handle); - // if (!param->write.is_prep){ - // ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, value len %d, value :", param->write.len); - // esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len); - // if (gl_profile_tab[PROFILE_A_APP_ID].descr_handle == param->write.handle && param->write.len == 2){ - // uint16_t descr_value = param->write.value[1]<<8 | param->write.value[0]; - // if (descr_value == 0x0001){ - // if (a_property & ESP_GATT_CHAR_PROP_BIT_NOTIFY){ - // ESP_LOGI(GATTS_TAG, "notify enable"); - // uint8_t notify_data[15]; - // for (int i = 0; i < sizeof(notify_data); ++i) - // { - // notify_data[i] = i%0xff; - // } - // //the size of notify_data[] need less than MTU size - // esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle, - // sizeof(notify_data), notify_data, false); - // } - // }else if (descr_value == 0x0002){ - // if (a_property & ESP_GATT_CHAR_PROP_BIT_INDICATE){ - // ESP_LOGI(GATTS_TAG, "indicate enable"); - // uint8_t indicate_data[15]; - // for (int i = 0; i < sizeof(indicate_data); ++i) - // { - // indicate_data[i] = i%0xff; - // } - // //the size of indicate_data[] need less than MTU size - // esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle, - // sizeof(indicate_data), indicate_data, true); - // } - // } - // else if (descr_value == 0x0000){ - // ESP_LOGI(GATTS_TAG, "notify/indicate disable "); - // }else{ - // ESP_LOGE(GATTS_TAG, "unknown descr value"); - // esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len); - // } - - // } - // } // example_write_event_env(gatts_if, &a_prepare_write_env, param); break; } @@ -557,33 +540,6 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i } } -//实际只让接收profile_b_buffer_size-1个 -#define profile_b_buffer_size 100 -char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; -uint8_t bluetooth_rx_buffer_len = 0; -bool bluetooth_rx_buffer_processing = false; - -bool flag = true; -uint32_t total = 0; -#define timer_interval_num 100 -#define timer_interval_s (uint32_t)1000000 -#define timer_interval_ms (uint32_t)1000 -#define timer_interval_us (uint32_t)1 - -void bluetooth_gatts_try_process_data(); - -void buffer_all_init() -{ - bluetooth_rx_buffer_len = 0; - memset(bluetooth_rx_buffer, 0, profile_b_buffer_size); -} - -void timer_set_pause_and_counter_zero(int group, int timer) -{ - timer_pause(group, timer); - timer_set_counter_value(group, timer, 0); -} - static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) { switch (event) @@ -765,6 +721,9 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ } while (0); } +/*********************************************************************************************************************** + * *******************************************************timer******************************************************* * + ***********************************************************************************************************************/ static bool IRAM_ATTR timer_group_isr_callback(void *args) { // timer_pause(TIMER_GROUP_0, TIMER_0); @@ -810,6 +769,9 @@ static void timer_group_init(int group, int timer, bool auto_reload, int timer_i timer_set_counter_value(group, timer, 0); } +/*********************************************************************************************************************** + * *******************************************************main******************************************************** * + ***********************************************************************************************************************/ void app_main(void) { esp_err_t ret; @@ -899,6 +861,21 @@ void app_main(void) return; } +/*********************************************************************************************************************** + * *************************************************user_funtion_def************************************************** * + ***********************************************************************************************************************/ +void buffer_all_init() +{ + bluetooth_rx_buffer_len = 0; + memset(bluetooth_rx_buffer, 0, profile_b_buffer_size); +} + +void timer_set_pause_and_counter_zero(int group, int timer) +{ + timer_pause(group, timer); + timer_set_counter_value(group, timer, 0); +} + void bluetooth_gatts_try_process_data() { cJSON *json_tmp;