From 20d33d636b3431a32ae0abb410aed1206875d033 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Tue, 25 Oct 2016 15:05:08 +0800 Subject: [PATCH] component/bt ; add notify --- .../bluedroid/profiles/esp/blufi/blufi_prf.c | 30 ++++++++++++++----- .../profiles/esp/include/blufi_prf.h | 4 +-- examples/07_blufi/main/demo_main.c | 5 ++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c b/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c index 0b1e795fa7..b3f4a8bb59 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c @@ -33,6 +33,9 @@ #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] +void blufi_config_success(void); +void blufi_config_failed(void); + UINT16 esp32_uuid = SVC_BLUFI_UUID; UINT8 esp32_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31}; tBTA_BLE_MANU p_esp32_manu = {sizeof(esp32_manu),esp32_manu}; /* manufacturer data */ @@ -180,21 +183,22 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //add the frist blufi characteristic --> write characteristic BTA_GATTS_AddCharacteristic(blufi_cb_env.clcb.cur_srvc_id, &uuid, (GATT_PERM_WRITE | GATT_PERM_READ), - (GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE)); + (GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE | GATT_CHAR_PROP_BIT_NOTIFY)); break; case BTA_GATTS_ADD_CHAR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == CHAR_BLUFI_UUID) { - uuid.uu.uuid16 = CHAR_BLUFI_UUID; //save the att handle to the env blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id; + + uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; + BTA_GATTS_AddCharDescriptor (blufi_cb_env.clcb.cur_srvc_id, + (GATT_PERM_WRITE|GATT_PERM_WRITE), + &uuid); } break; case BTA_GATTS_ADD_CHAR_DESCR_EVT: - if(p_data->add_result.char_uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) - { - blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id; - } + /* Nothing */ break; case BTA_GATTS_CONNECT_EVT: //set the connection flag to true @@ -361,7 +365,7 @@ tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back) return GATT_SUCCESS; } -void blufi_msg_notify(UINT8 len, UINT8 *blufi_msg) +void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len) { BOOLEAN conn_status = blufi_cb_env.clcb.connected; UINT16 conn_id = blufi_cb_env.clcb.conn_id; @@ -377,3 +381,15 @@ void blufi_msg_notify(UINT8 len, UINT8 *blufi_msg) BTA_GATTS_HandleValueIndication (conn_id, attr_id, len, blufi_msg, rsp); } + +void blufi_config_success(void) +{ + uint8_t *success_msg = "BLUFI_CONFIG_OK"; + blufi_msg_notify(success_msg, strlen(success_msg)); +} + +void blufi_config_failed(void) +{ + uint8_t *failed_msg = "BLUFI_CONFIG_FAILED"; + blufi_msg_notify(failed_msg, strlen(failed_msg)); +} diff --git a/components/bt/bluedroid/profiles/esp/include/blufi_prf.h b/components/bt/bluedroid/profiles/esp/include/blufi_prf.h index fc5c3ff942..9fb53e8768 100644 --- a/components/bt/bluedroid/profiles/esp/include/blufi_prf.h +++ b/components/bt/bluedroid/profiles/esp/include/blufi_prf.h @@ -7,7 +7,7 @@ //define the blufi Char uuid #define CHAR_BLUFI_UUID 0xFF01 -#define BLUFI_HDL_NUM 3 +#define BLUFI_HDL_NUM 4 #define BLUFI_VAL_MAX_LEN (20) @@ -72,5 +72,5 @@ BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id); tGATT_STATUS blufi_profile_init(tBLUFI_CBACK *call_back); -void blufi_msg_notify(UINT8 len, UINT8 *blufi_msg); +void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len); diff --git a/examples/07_blufi/main/demo_main.c b/examples/07_blufi/main/demo_main.c index 78c8d8935e..6475c3d466 100644 --- a/examples/07_blufi/main/demo_main.c +++ b/examples/07_blufi/main/demo_main.c @@ -46,6 +46,8 @@ void wifi_set_blue_config(char *ssid, char *passwd) printf("confirm true\n"); } +extern void blufi_config_failed(void); +extern void blufi_config_success(void); static esp_err_t event_handler(void *ctx, system_event_t *event) { switch(event->event_id) { @@ -54,6 +56,8 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); + blufi_config_success(); + BTA_DisableBluetooth(); break; case SYSTEM_EVENT_STA_DISCONNECTED: /* This is a workaround as ESP32 WiFi libs don't currently @@ -102,6 +106,7 @@ void wifiTestTask(void *pvParameters) ret = esp_wifi_connect(); if (ret != ESP_OK) { printf("esp_wifi connect failed\n"); + blufi_config_failed(); } } } -- 2.40.0