compnent bt:debug the btc_gattc received data error issues.

This commit is contained in:
Yulong 2016-11-19 08:00:08 -05:00
parent 3edcd29a83
commit a76b65ed95
7 changed files with 65 additions and 48 deletions

View File

@ -114,7 +114,7 @@ typedef enum {
ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */ ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */
} esp_gatt_char_prop_t; } esp_gatt_char_prop_t;
#define ESP_GATT_MAX_ATTR_LEN 600 #define ESP_GATT_MAX_ATTR_LEN 300
typedef struct { typedef struct {
uint8_t value[ESP_GATT_MAX_ATTR_LEN]; uint8_t value[ESP_GATT_MAX_ATTR_LEN];
uint16_t handle; uint16_t handle;

View File

@ -191,7 +191,7 @@ void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
tBTA_GATT_STATUS status = BTA_GATT_NO_RESOURCES; 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)); memset(&cb_data, 0, sizeof(cb_data));
cb_data.reg_oper.status = BTA_GATT_NO_RESOURCES; cb_data.reg_oper.status = BTA_GATT_NO_RESOURCES;
@ -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) 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; status = BTA_GATT_ERROR;
} }
else 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->hdr.event = BTA_GATTC_INT_START_IF_EVT;
p_buf->client_if = p_cb->cl_rcb[i].client_if; p_buf->client_if = p_cb->cl_rcb[i].client_if;
APPL_TRACE_DEBUG("GATTC getbuf sucess.\n");
bta_sys_sendmsg(p_buf); bta_sys_sendmsg(p_buf);
status = BTA_GATT_OK; 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_data->api_reg.p_cback)
{ {
if (p_app_uuid != NULL) 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; cb_data.reg_oper.status = status;
(*p_data->api_reg.p_cback)(BTA_GATTC_REG_EVT, (tBTA_GATTC *)&cb_data); (*p_data->api_reg.p_cback)(BTA_GATTC_REG_EVT, (tBTA_GATTC *)&cb_data);
} }

View File

@ -24,6 +24,8 @@
#include "btc_gattc.h" #include "btc_gattc.h"
#include "btc_gap_ble.h" #include "btc_gap_ble.h"
#include "btc_blufi_prf.h" #include "btc_blufi_prf.h"
#include "bta_gatt_api.h"
static xTaskHandle xBtcTaskHandle = NULL; static xTaskHandle xBtcTaskHandle = NULL;
static xQueueHandle xBtcQueue = 0; 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) 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; btc_msg_t lmsg;
tBTA_GATTC *temp = NULL, *temp2 = NULL;
if (msg == NULL) { if (msg == NULL) {
return BT_STATUS_PARM_INVALID; 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; return BT_STATUS_NOMEM;
} }
memcpy(lmsg.arg, arg, arg_len); 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) { if (copy_func) {
copy_func(&lmsg, lmsg.arg, arg); copy_func(&lmsg, lmsg.arg, arg);
} }

View File

@ -54,8 +54,7 @@ static void btc_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
msg.sig = BTC_SIG_API_CB; msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GATTC; msg.pid = BTC_PID_GATTC;
msg.act = (uint8_t) event; 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) if (ret)
LOG_ERROR("%s transfer failed\n", __func__); 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); btc_gattc_unreg_for_notify(arg);
break; break;
default: default:
LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, msg->act); LOG_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
break; break;
} }
@ -436,7 +435,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg); tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
esp_ble_gattc_cb_param_t param; esp_ble_gattc_cb_param_t param;
memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t)); memset(&param, 0, sizeof(esp_ble_gattc_cb_param_t));
switch (msg->act) { switch (msg->act) {
case BTA_GATTC_REG_EVT: { case BTA_GATTC_REG_EVT: {

View File

@ -2869,8 +2869,8 @@ void btm_ble_process_adv_pkt (UINT8 *p_data)
STREAM_TO_UINT8 (evt_type, p); STREAM_TO_UINT8 (evt_type, p);
STREAM_TO_UINT8 (addr_type, p); STREAM_TO_UINT8 (addr_type, p);
STREAM_TO_BDADDR (bda, p); STREAM_TO_BDADDR (bda, p);
BTM_TRACE_ERROR("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x\n", //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]); // bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
/* map address to security record */ /* map address to security record */
match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE); match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE);

View File

@ -1687,7 +1687,7 @@ static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
static void btu_ble_process_adv_pkt (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); btm_ble_process_adv_pkt(p);
} }

View File

@ -39,8 +39,12 @@
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #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] #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; BD_ADDR obj_addr;
uint16_t simpleClient_id = 0xEE;
char device_name[] = "Heart Rate";
static unsigned char BASE_UUID[16] = { static unsigned char BASE_UUID[16] = {
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 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("%c",adv_name[j]);
} }
LOG_ERROR("\n"); 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; break;
case ESP_GAP_SEARCH_INQ_CMPL_EVT: case ESP_GAP_SEARCH_INQ_CMPL_EVT:
break; 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) 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); 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 * * Function bta_scan_recult_callback
@ -313,7 +322,7 @@ static void bta_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p
} }
} }
#endif #endif ///if 0
/************************************************************************************ /************************************************************************************
* * Function bta_scan_param_setup_cback * * Function bta_scan_param_setup_cback
@ -414,6 +423,8 @@ void ble_client_appRegister(void)
//register the callback function to the gattc module //register the callback function to the gattc module
if ((status = esp_ble_gattc_register_callback(esp_gattc_result_cb)) != ESP_OK){ if ((status = esp_ble_gattc_register_callback(esp_gattc_result_cb)) != ESP_OK){
LOG_ERROR("gattc register error, error code = %x\n",status); LOG_ERROR("gattc register error, error code = %x\n",status);
}else{
esp_ble_gattc_app_register(simpleClient_id);
} }