From 2182b69b3d776775fb3040d974807b0c8514ae79 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 18 Oct 2016 05:22:36 -0400 Subject: [PATCH] component bt:added the button profile event & process method to the project --- .../bt/bluedroid/bta/gatt/bta_gattc_act.c | 1 + .../bt/bluedroid/bta/gatt/bta_gattc_main.c | 4 +- .../profiles/esp/ble_button/button_pro.c | 21 ++-- .../profiles/esp/include/button_pro.h | 2 + .../profiles/esp/include/wx_airsync_prf.h | 2 +- .../esp/wechat_AirSync/wx_airsync_prf.c | 2 +- .../profiles/std/hid_le/hid_le_prf.c | 2 +- .../bluedroid/profiles/std/include/prf_defs.h | 4 +- .../bt/bluedroid/stack/btm/btm_ble_privacy.c | 14 +-- .../bluedroid_demos/app_core/bt_app_api.c | 19 +++ .../app_sample_button/app_button.c | 47 ++++++- .../app_project/SampleServerProject.c | 2 +- .../bluedroid_demos/include/app_button_int.h | 117 ++++++++++++++++++ .../bluedroid_demos/include/app_wechat_util.h | 2 +- 14 files changed, 210 insertions(+), 29 deletions(-) create mode 100644 examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c create mode 100644 examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 116641ebb..c7546404e 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -271,6 +271,7 @@ void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",p_msg->int_start_if.client_if ); } } + /******************************************************************************* ** ** Function bta_gattc_deregister diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c index 7885fa685..bb45445a4 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c @@ -364,7 +364,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) tBTA_GATTC_RCB *p_clreg; BOOLEAN rt = TRUE; #if BTA_GATT_DEBUG == TRUE - APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event)); + APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]\n", gattc_evt_code(p_msg->event)); #endif switch (p_msg->event) { @@ -424,7 +424,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) } else { - APPL_TRACE_DEBUG("Ignore unknown conn ID: %d", p_msg->layer_specific); + APPL_TRACE_DEBUG("Ignore unknown conn ID: %d\n", p_msg->layer_specific); } break; diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 9fa1c9aed..b11e30e7a 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -284,32 +284,23 @@ UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) ** Returns True the deallocation is successful ** *******************************************************************************/ -/* + BOOLEAN button_env_clcb_dealloc(UINT16 conn_id) { UINT8 i_clcb = 0; tBUT_CLCB *p_clcb = NULL; - for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < BUTT_MAX_APPS; i_clcb++, p_clcb++) + for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < 1; i_clcb++, p_clcb++) { if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id)) { - unsigned j; - for(j = 0; j < ARRAY_SIZE(p_clcb->button_value.data_string);j++) - { - if(p_clcb->button_value.data_string[j]) - { - GKI_freebuf(p_clcb->button_value.data_string[j]); - } - } memset(p_clcb, 0, sizeof(tBUT_CLCB)); return TRUE; } } return FALSE; -}*/ - +} /******************************************************************************* ** @@ -348,6 +339,12 @@ tGATT_STATUS button_init (tBU_CBACK *call_back) return GATT_SUCCESS; } +void button_disable(UINT16 connid) +{ + button_env_clcb_dealloc(connid); +} + + void button_msg_notify(UINT8 len, UINT8 *button_msg) { BOOLEAN conn_status = button_cb_env.clcb.connected; diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index d9028830b..023e248af 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -115,6 +115,8 @@ BOOLEAN button_env_clcb_dealloc(UINT16 conn_id); tGATT_STATUS button_init(tBU_CBACK *call_back); +void button_disable(UINT16 connid); + void button_msg_notify(UINT8 len, UINT8 *button_msg); extern tBUTTON_CB_ENV button_cb_env; diff --git a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h index 1883b839c..8323ae8b8 100644 --- a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h +++ b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h @@ -50,7 +50,7 @@ typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data) WX_IDX_AIRSYNC_READ_VAL, WX_IDX_AIRSYNC_NTF_CFG, - KEY_IDX_NB, + WX_IDX_NB, }; typedef struct diff --git a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c index 821195d44..dc1e557b9 100644 --- a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c +++ b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c @@ -184,7 +184,7 @@ void AirSync_CreateService(void) { tBTA_GATTS_IF server_if ; tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; - UINT16 num_handle = KEY_IDX_NB; + UINT16 num_handle = WX_IDX_NB; UINT8 inst = 0x00; server_if = airsync_cb_env.gatt_if; airsync_cb_env.inst_id = inst; diff --git a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c index 61037ae5e..4b225132b 100644 --- a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c +++ b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c @@ -458,7 +458,7 @@ void hidd_le_CreateService(BOOLEAN is_primary) tBTA_GATTS_IF server_if ; tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}}; //the number of the hid device attributes in the hid service. - UINT16 num_handle = HIDD_LE_IDX_NB+5; + UINT16 num_handle = HIDD_LE_IDX_NB; UINT8 inst = 0x00; server_if = hidd_le_env.gatt_if; hidd_le_env.inst_id = inst; diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 790bfe2c0..921477d02 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -26,8 +26,8 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 0 +#define WX_AIRSYNC_CFG 1 +#define BUT_PROFILE_CFG 1 #define HIDD_LE_PROFILE_CFG 1 /* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c index c7362a7b9..e0bbcf89d 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c @@ -760,14 +760,14 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) BOOLEAN rt = FALSE; UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state; - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n", __func__, btm_cb.ble_ctr_cb.privacy_mode); /* if controller does not support RPA offloading or privacy 1.2, skip */ if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) return FALSE; - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n", __func__, btm_cb.ble_ctr_cb.privacy_mode); /* only add RPA enabled device into resolving list */ @@ -801,7 +801,7 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type; } - BTM_TRACE_DEBUG("%s:adding device to controller resolving list", __func__); + BTM_TRACE_DEBUG("%s:adding device to controller resolving list\n", __func__); // use identical IRK for now rt = btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr, peer_irk, local_irk); @@ -837,13 +837,13 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) } else { - BTM_TRACE_ERROR("Device already in Resolving list"); + BTM_TRACE_ERROR("Device already in Resolving list\n"); rt = TRUE; } } else { - BTM_TRACE_DEBUG("Device not a RPA enabled device"); + BTM_TRACE_DEBUG("Device not a RPA enabled device\n"); } return rt; } @@ -863,7 +863,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) { UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state; - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); if (rl_mask) { if (!btm_ble_disable_resolving_list (rl_mask, FALSE)) @@ -879,7 +879,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) } else { - BTM_TRACE_DEBUG("Device not in resolving list"); + BTM_TRACE_DEBUG("Device not in resolving list\n"); } /* if resolving list has been turned on, re-enable it */ diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c new file mode 100644 index 000000000..687c5dae4 --- /dev/null +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -0,0 +1,19 @@ +/** + **************************************************************************************** + * + * @file bt_app_api.c + * + * @brief Application entry point + * + * Copyright (C) Espressif 2016 + * Created by Yulong at 2016/10/17 + * + * + **************************************************************************************** + */ + +#include "bt_app_api.h" + + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index 38f5f950e..825a5647a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -15,7 +15,6 @@ ******************************************************************************* ********* */ -#if 0 #include #include #include @@ -33,6 +32,52 @@ #include "allocator.h" #include "button_pro.h" +#include "app_button_int.h" + + +/******************************************************************************* +** +** Function ble_but_prf_hdl_event +** +** Description button profile main event handling function. +** +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data) +{ + UINT16 connid = 0; + switch(msg_data->event) + { + case BLE_BUT_CREATE_DB_REQ_EVT: + Button_CreateService(); + break; + case BLE_BUT_VAL_SEND_CFM_EVT: + break; + case BLE_BUT_SET_CHAR_VAL_REQ_EVT: + button_msg_notify(msg_data->len,msg_data->data); + break; + case BLE_BUT_ENABLE_REQ_EVT: + button_init(NULL); + break; + case BLE_BUT_DISABLE_IND_EVT: + button_disable(connid); + break; + case BLE_BUT_CHAR_WRITE_IND_EVT: + + break; + case BLE_BUT_ERROR_IND_EVT: + break; + default: + break; + } +} + + + +#if 0 + #define GPIO_INUM 8 #define TABLE_ELEMENT_CNT(table) ((sizeof(table))/(sizeof(table[0]))); app_key_env key_press; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index d5c0264be..b9cac08a7 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -238,7 +238,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) DIS_SrInit(dis_attr_mask); */ /*instantiate a battery service*/ - //bas_register(); + bas_register(); /*instantiate the driver for button profile*/ //app_button_init(); #if (BUT_PROFILE_CFG) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h new file mode 100644 index 000000000..5bfb430fd --- /dev/null +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -0,0 +1,117 @@ +/** + +******************************************************************************* +********* +* +* @file app_button_int.h +* +* @brief button Service Application entry point +* +* Copyright (C) ESPRESSSIF 2016 +* Created by Yulong at 2016/10/17 +* +******************************************************************************* +**********/ + +#include "prf_defs.h" +#include "bt_prf_sys.h" +#include "bt_types.h" + +#if (BUT_PROFILE_CFG) + +/// Messages for Device Information Service Server +enum +{ + ///Add a BUTTON instance into the database + BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE), + ///Send key value confirm to APP so stable values can be erased + ///if correctly sent. + BLE_BUT_VAL_SEND_CFM_EVT, + ///Set the value of an attribute + BLE_BUT_SET_CHAR_VAL_REQ_EVT, + + ///Start the button notify Service Task - at connection + BLE_BUT_ENABLE_REQ_EVT, + + /// Inform the application that the profile service role task has been disabled after a disconnection + BLE_BUT_DISABLE_IND_EVT, + /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client + BLE_BUT_CHAR_WRITE_IND_EVT, + ///Error indication to Host + BLE_BUT_ERROR_IND_EVT, +}; + +/// Parameters of the @ref KEY_CREATE_DB_REQ message +typedef struct +{ + ///Database configuration + uint16_t features; +}tBUT_CRT_DB_REQ; + +/// Parameters of the @ref KEY_CREATE_DB_CFM message +typedef struct +{ + ///Status + uint8_t status; +}tBUT_CRT_DB_CFM; + +///Parameters of the @ref key_CFG_INDNTF_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; + /// characteristics + uint8_t char_code; +}tBUT_CFG_NTF_IND; + + +/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated +typedef struct +{ + /// Characteristic Code + //uint8_t char_code; + uint8_t conhdl; + uint8_t key_val_len; + uint8_t key_val[2]; +}tBUT_SND_CHAR_VAL_REQ; + +/// Parameters of the @ref KEY_ENABLE_REQ message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together + uint8_t sec_lvl; + ///Type of connection + uint8_t con_type; +}tBUT_ENABLE_REQ; + +///Parameters of the @ref KEY_VAL_SEND_CFM message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Status + uint8_t status; +}tBUT_VAL_SND_CFM; + + +/// Parameters of the @ref KEY_DISABLE_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; +}tBUT_DISABLE_IND; + + + +BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data); + + + +#endif ///BUT_PROFILE_CFG + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h index 5de417deb..3b048c3f1 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h @@ -2,7 +2,7 @@ #define __APP_WECHAT_UTIL_H__ #include "prf_defs.h" -if (WX_AIRSYNC_CFG) +#if (WX_AIRSYNC_CFG) #include #include