From a76b65ed95e394576620329e259a3a01a1eb7758 Mon Sep 17 00:00:00 2001 From: Yulong Date: Sat, 19 Nov 2016 08:00:08 -0500 Subject: [PATCH] compnent bt:debug the btc_gattc received data error issues. --- .../bt/bluedroid/api/include/esp_gatt_defs.h | 2 +- .../bt/bluedroid/bta/gatt/bta_gattc_act.c | 11 ++- components/bt/bluedroid/btc/core/btc_task.c | 10 ++- .../btc/profile/std/gatt/btc_gattc.c | 7 +- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 4 +- components/bt/bluedroid/stack/btu/btu_hcif.c | 2 +- .../app_project/Arch_SimpleClientProject.c | 77 +++++++++++-------- 7 files changed, 65 insertions(+), 48 deletions(-) diff --git a/components/bt/bluedroid/api/include/esp_gatt_defs.h b/components/bt/bluedroid/api/include/esp_gatt_defs.h index 699ee66c51..13d4df4b4a 100644 --- a/components/bt/bluedroid/api/include/esp_gatt_defs.h +++ b/components/bt/bluedroid/api/include/esp_gatt_defs.h @@ -114,7 +114,7 @@ typedef enum { ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */ } esp_gatt_char_prop_t; -#define ESP_GATT_MAX_ATTR_LEN 600 +#define ESP_GATT_MAX_ATTR_LEN 300 typedef struct { uint8_t value[ESP_GATT_MAX_ATTR_LEN]; uint16_t handle; diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index c7546404e3..6c131197a3 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -191,10 +191,10 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) tBTA_GATT_STATUS status = BTA_GATT_NO_RESOURCES; - APPL_TRACE_DEBUG("bta_gattc_register state %d",p_cb->state); + APPL_TRACE_DEBUG("bta_gattc_register state %d\n",p_cb->state); memset(&cb_data, 0, sizeof(cb_data)); cb_data.reg_oper.status = BTA_GATT_NO_RESOURCES; - + /* check if GATTC module is already enabled . Else enable */ if (p_cb->state == BTA_GATTC_STATE_DISABLED) { @@ -207,7 +207,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) { if ((p_app_uuid == NULL) || (p_cb->cl_rcb[i].client_if = GATT_Register(p_app_uuid, &bta_gattc_cl_cback)) == 0) { - APPL_TRACE_ERROR("Register with GATT stack failed."); + APPL_TRACE_ERROR("Register with GATT stack failed.\n"); status = BTA_GATT_ERROR; } else @@ -223,7 +223,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) { p_buf->hdr.event = BTA_GATTC_INT_START_IF_EVT; p_buf->client_if = p_cb->cl_rcb[i].client_if; - + APPL_TRACE_DEBUG("GATTC getbuf sucess.\n"); bta_sys_sendmsg(p_buf); status = BTA_GATT_OK; } @@ -243,8 +243,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data) if (p_data->api_reg.p_cback) { if (p_app_uuid != NULL) - memcpy(&(cb_data.reg_oper.app_uuid),p_app_uuid,sizeof(tBT_UUID)); - + memcpy(&(cb_data.reg_oper.app_uuid),p_app_uuid,sizeof(tBT_UUID)); cb_data.reg_oper.status = status; (*p_data->api_reg.p_cback)(BTA_GATTC_REG_EVT, (tBTA_GATTC *)&cb_data); } diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index 64129d2724..3dd982a695 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -24,6 +24,8 @@ #include "btc_gattc.h" #include "btc_gap_ble.h" #include "btc_blufi_prf.h" +#include "bta_gatt_api.h" + static xTaskHandle xBtcTaskHandle = NULL; static xQueueHandle xBtcQueue = 0; @@ -89,7 +91,7 @@ static bt_status_t btc_task_post(btc_msg_t *msg) bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func) { btc_msg_t lmsg; - + tBTA_GATTC *temp = NULL, *temp2 = NULL; if (msg == NULL) { return BT_STATUS_PARM_INVALID; } @@ -103,6 +105,12 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg return BT_STATUS_NOMEM; } memcpy(lmsg.arg, arg, arg_len); + temp = (tBTA_GATTC *)lmsg.arg; + temp2 = (tBTA_GATTC *)arg; + LOG_ERROR("###the temp status = %x, if = %x\n####\n", + temp->reg_oper.status,temp->reg_oper.client_if); + LOG_ERROR("###the arg status = %x, if = %x\n####\n", + temp2->reg_oper.status, temp2->reg_oper.client_if); if (copy_func) { copy_func(&lmsg, lmsg.arg, arg); } diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c index c42659d6ed..8be640c3f5 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -54,8 +54,7 @@ static void btc_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GATTC; msg.act = (uint8_t) event; - - ret = btc_transfer_context(&msg, &p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data); + ret = btc_transfer_context(&msg, p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data); if (ret) LOG_ERROR("%s transfer failed\n", __func__); @@ -425,7 +424,7 @@ void btc_gattc_call_handler(btc_msg_t *msg) btc_gattc_unreg_for_notify(arg); break; default: - LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, msg->act); + LOG_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); break; } @@ -436,7 +435,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg) tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg); esp_ble_gattc_cb_param_t param; - memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t)); + memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t)); switch (msg->act) { case BTA_GATTC_REG_EVT: { diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 80a4b577b0..33785a296b 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -2869,8 +2869,8 @@ void btm_ble_process_adv_pkt (UINT8 *p_data) STREAM_TO_UINT8 (evt_type, p); STREAM_TO_UINT8 (addr_type, p); STREAM_TO_BDADDR (bda, p); - BTM_TRACE_ERROR("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x\n", - bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); + //BTM_TRACE_ERROR("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x\n", + // bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) /* map address to security record */ match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE); diff --git a/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index ebfd8c6ae5..3e4f75bbf2 100755 --- a/components/bt/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/bluedroid/stack/btu/btu_hcif.c @@ -1687,7 +1687,7 @@ static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p) static void btu_ble_process_adv_pkt (UINT8 *p) { - HCI_TRACE_ERROR("btu_ble_process_adv_pkt\n"); + HCI_TRACE_DEBUG("btu_ble_process_adv_pkt\n"); btm_ble_process_adv_pkt(p); } diff --git a/examples/09_arch_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c b/examples/09_arch_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c index 86e8e1eb4a..46ba7c208c 100644 --- a/examples/09_arch_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c +++ b/examples/09_arch_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c @@ -39,8 +39,12 @@ #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] -tBTA_GATTC_IF client_if; +esp_gatt_if_t client_if; +esp_gatt_status_t status = ESP_GATT_ERROR; +BOOLEAN connet = FALSE; BD_ADDR obj_addr; +uint16_t simpleClient_id = 0xEE; +char device_name[] = "Heart Rate"; static unsigned char BASE_UUID[16] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -149,8 +153,25 @@ static void esp_scan_result_cb(uint32_t event, void *param) LOG_ERROR("%c",adv_name[j]); } LOG_ERROR("\n"); + for(int j = 0; j < adv_name_len; j++) + { + LOG_ERROR("%c",device_name[j]); + } + LOG_ERROR("\n"); - //if(strcmp(scan_result->scan_rst.bda, )) + if (adv_name != NULL) + { + if(strcmp(adv_name, device_name) == 0) + { + LOG_ERROR("the name eque to Heart Rate.\n"); + if (status == ESP_GATT_OK && connet == FALSE) + { + connet = TRUE; + LOG_ERROR("Connet to the remote device.\n"); + esp_ble_gattc_open(client_if, scan_result->scan_rst.bda, TRUE); + } + } + } break; case ESP_GAP_SEARCH_INQ_CMPL_EVT: break; @@ -171,7 +192,21 @@ static void esp_scan_result_cb(uint32_t event, void *param) static void esp_gattc_result_cb(uint32_t event, void *gattc_param) { - + esp_ble_gattc_cb_param_t *gattc_data = (esp_ble_gattc_cb_param_t *)gattc_param; + LOG_ERROR("esp_gattc_result_cb, event = %x\n", event); + switch (event) + { + case ESP_GATTC_REG_EVT: + status = gattc_data->reg.status; + client_if = gattc_data->reg.gatt_if; + LOG_ERROR("status = %x, client_if = %x\n", status, client_if); + break; + case ESP_GATTC_OPEN_EVT: + LOG_ERROR("ESP_GATTC_OPEN_EVT\n"); + break; + default: + break; + } } @@ -219,33 +254,7 @@ void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output); } */ -/*get remote name*/ -static bool check_remote_name(tBTA_DM_INQ_RES* result, uint8_t* rmt_name, uint8_t* rmt_name_len) -{ - uint8_t *p_rmt_name = NULL; - uint8_t remote_name_len = 0; - - if (result->p_eir) { - p_rmt_name = BTM_CheckEirData(result->p_eir, - BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, - &remote_name_len); - if (!p_rmt_name) - p_rmt_name = BTM_CheckEirData(result->p_eir, - BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, - &remote_name_len); - if (p_rmt_name) { - if (remote_name_len > BD_NAME_LEN) - remote_name_len = BD_NAME_LEN; - if (rmt_name && rmt_name_len) { - memcpy(rmt_name, p_rmt_name, remote_name_len); - *(rmt_name + remote_name_len) = 0; - *rmt_name_len = remote_name_len; - } - return true; - } - } - return false; -} + /************************************************************************************ * * Function bta_scan_recult_callback @@ -312,9 +321,9 @@ static void bta_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p LOG_ERROR("%s : unknown event 0x%x", __FUNCTION__, event); } } - -#endif - + +#endif ///if 0 + /************************************************************************************ * * Function bta_scan_param_setup_cback * * @@ -414,6 +423,8 @@ void ble_client_appRegister(void) //register the callback function to the gattc module if ((status = esp_ble_gattc_register_callback(esp_gattc_result_cb)) != ESP_OK){ LOG_ERROR("gattc register error, error code = %x\n",status); + }else{ + esp_ble_gattc_app_register(simpleClient_id); }