]> granicus.if.org Git - esp-idf/commitdiff
component bt:added the button profile event & process method to the project
authoryulong <yulong@yulong-mac.(none)>
Tue, 18 Oct 2016 09:22:36 +0000 (05:22 -0400)
committeryulong <yulong@yulong-mac.(none)>
Tue, 18 Oct 2016 09:22:36 +0000 (05:22 -0400)
14 files changed:
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_main.c
components/bt/bluedroid/profiles/esp/ble_button/button_pro.c
components/bt/bluedroid/profiles/esp/include/button_pro.h
components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h
components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c
components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c
components/bt/bluedroid/profiles/std/include/prf_defs.h
components/bt/bluedroid/stack/btm/btm_ble_privacy.c
examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c [new file with mode: 0644]
examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c
examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c
examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h [new file with mode: 0644]
examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h

index 116641ebb8c0cbe505d010d5ad5285417d5b21b4..c7546404e3a5ce66d566480a636efe61f3100422 100755 (executable)
@@ -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
index 7885fa685800de0ca9e2962657e9b73fb99485a2..bb45445a4f58a63bb0e4cad9cc9cbb77ea9b1be3 100755 (executable)
@@ -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;
index 9fa1c9aeda9600b43de7044a4f42e9d0a72df17f..b11e30e7a36a97d99fdcee2237a85d54944535a9 100644 (file)
@@ -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;
index d9028830b2d0c7f8cc6cb34b86423048ae2a2d83..023e248af037d2e2903b8e8210d0052d2160b966 100644 (file)
@@ -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;
index 1883b839c0c5d7cd3d36540f94ad7711192770c8..8323ae8b813e8aa8da3114599a18ffa776823f00 100644 (file)
@@ -50,7 +50,7 @@ typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data)
         WX_IDX_AIRSYNC_READ_VAL,\r
         WX_IDX_AIRSYNC_NTF_CFG,\r
  \r
-        KEY_IDX_NB,\r
+        WX_IDX_NB,\r
  };\r
  \r
  typedef struct\r
index 821195d4444993098ed095b5c7305907ec6ea391..dc1e557b99536eecad4110dbf54a07c3b9b48b6c 100644 (file)
@@ -184,7 +184,7 @@ void AirSync_CreateService(void)
 {\r
        tBTA_GATTS_IF server_if ;\r
        tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}};\r
-       UINT16 num_handle = KEY_IDX_NB;\r
+       UINT16 num_handle = WX_IDX_NB;\r
        UINT8 inst = 0x00;\r
        server_if = airsync_cb_env.gatt_if;\r
        airsync_cb_env.inst_id = inst;\r
index 61037ae5ef650800dce6d7e073a9b2cdd02218be..4b225132b10aca1e162899bfdc144ee98217d0d4 100644 (file)
@@ -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;
index 790bfe2c08b87f288258adb3df2c3a3f8f688243..921477d02dd4a4d4c1da43f495c7144e33d2ea16 100644 (file)
@@ -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
 
 /*
index c7362a7b9f2b24f88d31260fe481157bc322b4c0..e0bbcf89d36c8262ca0355fb47ad8716c3591be5 100755 (executable)
@@ -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 (file)
index 0000000..687c5da
--- /dev/null
@@ -0,0 +1,19 @@
+/**\r
+ ****************************************************************************************\r
+ *\r
+ * @file bt_app_api.c\r
+ *\r
+ * @brief Application entry point\r
+ *\r
+ * Copyright (C) Espressif 2016\r
+ * Created by Yulong at 2016/10/17\r
+ *\r
+ *\r
+ ****************************************************************************************\r
+ */\r
+\r
+#include "bt_app_api.h"\r
+\r
+\r
\r
+\r
index 38f5f950ea9c9959a49612b400d3e8fdfaf69881..825a5647ab8811020e4dd5671f3d4c8ebb61bae2 100644 (file)
@@ -15,7 +15,6 @@
 *******************************************************************************
 *********
 */
-#if 0
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
 
 #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;
index d5c0264bee3c872ac15d539718b562f61e54df6e..b9cac08a7118cebe0d0e88f045d0a3ba9f763a87 100644 (file)
@@ -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 (file)
index 0000000..5bfb430
--- /dev/null
@@ -0,0 +1,117 @@
+/**\r
\r
+*******************************************************************************\r
+*********\r
+*\r
+* @file app_button_int.h\r
+*\r
+* @brief button Service Application entry point\r
+*\r
+* Copyright (C) ESPRESSSIF 2016\r
+* Created by Yulong at 2016/10/17\r
+* \r
+*******************************************************************************\r
+**********/\r
+\r
+#include "prf_defs.h"\r
+#include "bt_prf_sys.h"\r
+#include "bt_types.h"\r
+\r
+#if (BUT_PROFILE_CFG)\r
+\r
+/// Messages for Device Information Service Server\r
+enum\r
+{\r
+    ///Add a BUTTON instance into the database\r
+    BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE),\r
+    ///Send key value confirm to APP so stable values can be erased\r
+    ///if correctly sent.\r
+    BLE_BUT_VAL_SEND_CFM_EVT,\r
+    ///Set the value of an attribute\r
+    BLE_BUT_SET_CHAR_VAL_REQ_EVT,\r
+       \r
+    ///Start the button notify Service Task - at connection\r
+    BLE_BUT_ENABLE_REQ_EVT,\r
+\r
+    /// Inform the application that the profile service role task has been disabled after a disconnection\r
+       BLE_BUT_DISABLE_IND_EVT,\r
+       /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client\r
+       BLE_BUT_CHAR_WRITE_IND_EVT,\r
+    ///Error indication to Host\r
+    BLE_BUT_ERROR_IND_EVT,\r
+};\r
+\r
+/// Parameters of the @ref KEY_CREATE_DB_REQ message\r
+typedef struct\r
+{\r
+    ///Database configuration\r
+    uint16_t features;\r
+}tBUT_CRT_DB_REQ;\r
+\r
+/// Parameters of the @ref     KEY_CREATE_DB_CFM message\r
+typedef struct\r
+{\r
+    ///Status\r
+    uint8_t status;\r
+}tBUT_CRT_DB_CFM;\r
+\r
+///Parameters of the @ref key_CFG_INDNTF_IND message\r
+typedef struct\r
+{\r
+    ///Connection handle\r
+    uint16_t conhdl;\r
+    ///Stop/notify/indicate value to configure into the peer characteristic\r
+    uint16_t cfg_val;\r
+    /// characteristics\r
+    uint8_t char_code;\r
+}tBUT_CFG_NTF_IND;\r
+\r
+\r
+/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated\r
+typedef struct \r
+{\r
+    /// Characteristic Code\r
+    //uint8_t char_code;\r
+       uint8_t conhdl;\r
+    uint8_t key_val_len;\r
+    uint8_t key_val[2];\r
+}tBUT_SND_CHAR_VAL_REQ;\r
+\r
+/// Parameters of the @ref KEY_ENABLE_REQ message\r
+typedef struct\r
+{\r
+    ///Connection handle\r
+    uint16_t conhdl;\r
+    /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together\r
+    uint8_t sec_lvl;\r
+    ///Type of connection\r
+    uint8_t con_type;\r
+}tBUT_ENABLE_REQ;\r
+\r
+///Parameters of the @ref KEY_VAL_SEND_CFM message\r
+typedef struct\r
+{\r
+    ///Connection handle\r
+    uint16_t conhdl;\r
+    ///Status\r
+    uint8_t status;\r
+}tBUT_VAL_SND_CFM;\r
+\r
+\r
+/// Parameters of the @ref KEY_DISABLE_IND message\r
+typedef struct \r
+{\r
+    ///Connection handle\r
+    uint16_t conhdl;\r
+}tBUT_DISABLE_IND;\r
+\r
+\r
+\r
+BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data);\r
+\r
+\r
+\r
+#endif ///BUT_PROFILE_CFG\r
+\r
+\r
+\r
index 5de417debafdfaa360226b56c8cad957bd7a1e67..3b048c3f1e146cc38d5a4692831c16a6dbaea031 100644 (file)
@@ -2,7 +2,7 @@
 #define __APP_WECHAT_UTIL_H__\r
 \r
 #include "prf_defs.h"\r
-if (WX_AIRSYNC_CFG)\r
+#if (WX_AIRSYNC_CFG)\r
 #include <stdint.h>\r
 #include <string.h>\r
 \r