From c78f71985baa7612a28e846e4d67815f3af815c3 Mon Sep 17 00:00:00 2001 From: zwsd Date: Fri, 15 Jul 2022 16:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=8A=A8=E4=B8=8A=E6=8A=A5=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/ble_gatts_table.c | 11 ++++++++++- main/ble_gatts_table.h | 2 +- main/gatts_table_creat_demo.c | 33 +++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/main/ble_gatts_table.c b/main/ble_gatts_table.c index a15a095..32eb62f 100644 --- a/main/ble_gatts_table.c +++ b/main/ble_gatts_table.c @@ -1,6 +1,8 @@ #include "ble_gatts_table.h" static uint16_t *hid_conn_id; +static esp_gatt_if_t *hid_gatts_if; +static uint16_t *hid_handle; static uint8_t adv_config_done = 0; @@ -354,6 +356,10 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ { ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret); } + else + { + *hid_gatts_if = gatts_if; + } } break; case ESP_GATTS_READ_EVT: @@ -441,6 +447,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ // start sent the update connection parameters to the peer device. esp_ble_gap_update_conn_params(&conn_params); *hid_conn_id = param->connect.conn_id; + *hid_handle = heart_rate_handle_table[IDX_CHAR_VAL_A]; // *hid_conn_id = 100; break; case ESP_GATTS_DISCONNECT_EVT: @@ -515,11 +522,13 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ } while (0); } -void ble_init(uint16_t *conn_id_ble) +void ble_init(uint16_t *conn_id_ble, esp_gatt_if_t *gatts_if_ble, uint16_t *handle_ble) { esp_err_t ret; hid_conn_id = conn_id_ble; + hid_gatts_if = gatts_if_ble; + hid_handle = handle_ble; /* Initialize NVS. */ ret = nvs_flash_init(); diff --git a/main/ble_gatts_table.h b/main/ble_gatts_table.h index 26b8958..2656a7a 100644 --- a/main/ble_gatts_table.h +++ b/main/ble_gatts_table.h @@ -54,4 +54,4 @@ struct gatts_profile_inst esp_bt_uuid_t descr_uuid; }; -void ble_init(uint16_t *conn_id_ble); \ No newline at end of file +void ble_init(uint16_t *conn_id_ble, esp_gatt_if_t *gatts_if_ble, uint16_t *handle_ble); \ No newline at end of file diff --git a/main/gatts_table_creat_demo.c b/main/gatts_table_creat_demo.c index 2454026..d95bfe7 100644 --- a/main/gatts_table_creat_demo.c +++ b/main/gatts_table_creat_demo.c @@ -7,22 +7,31 @@ */ /**************************************************************************** -* -* This demo showcases creating a GATT database using a predefined attribute table. -* It acts as a GATT server and can send adv data, be connected by client. -* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo. -* Client demo will enable GATT server's notify after connection. The two devices will then exchange -* data. -* -****************************************************************************/ + * + * This demo showcases creating a GATT database using a predefined attribute table. + * It acts as a GATT server and can send adv data, be connected by client. + * Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo. + * Client demo will enable GATT server's notify after connection. The two devices will then exchange + * data. + * + ****************************************************************************/ #include "ble_gatts_table.h" uint16_t table_conn_id_m; +esp_gatt_if_t table_gatts_if_m; +uint16_t table_handle_m; -void app_main(void){ - ble_init(&table_conn_id_m); +void app_main(void) +{ + uint8_t temp[5] = {68, 69, 70, 71, 72}; + ble_init(&table_conn_id_m, &table_gatts_if_m, &table_handle_m); - while(true){ - ESP_LOGI("test","%d",table_conn_id_m); + while (true) + { + // ESP_LOGI("test", "%d,%d,%d", table_conn_id_m, table_gatts_if_m, table_handle_m); + if (table_handle_m != 0) + { + esp_ble_gatts_send_indicate(table_gatts_if_m, table_conn_id_m, table_handle_m, 5, temp, false); + } } }