mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/btdm_stop_adv_scan_event_rebase' into 'master'
bt component: Add stop adv/scan completed event - Add advertising stop completed event - Add scan stop completed event See merge request !657
This commit is contained in:
commit
d7ceea0608
@ -48,6 +48,8 @@ typedef enum {
|
|||||||
ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */
|
ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */
|
||||||
ESP_GAP_BLE_ADV_START_COMPLETE_EVT, /*!< When start advertising complete, the event comes */
|
ESP_GAP_BLE_ADV_START_COMPLETE_EVT, /*!< When start advertising complete, the event comes */
|
||||||
ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, /*!< When start scan complete, the event comes */
|
ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, /*!< When start scan complete, the event comes */
|
||||||
|
ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, /*!< When stop adv complete, the event comes */
|
||||||
|
ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, /*!< When stop scan complete, the event comes */
|
||||||
} esp_gap_ble_cb_event_t;
|
} esp_gap_ble_cb_event_t;
|
||||||
|
|
||||||
/// Advertising data maximum length
|
/// Advertising data maximum length
|
||||||
@ -300,6 +302,18 @@ typedef union {
|
|||||||
struct ble_scan_start_cmpl_evt_param {
|
struct ble_scan_start_cmpl_evt_param {
|
||||||
esp_bt_status_t status; /*!< Indicate scan start operation success status */
|
esp_bt_status_t status; /*!< Indicate scan start operation success status */
|
||||||
} scan_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_START_COMPLETE_EVT */
|
} scan_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_START_COMPLETE_EVT */
|
||||||
|
/**
|
||||||
|
* @brief ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT
|
||||||
|
*/
|
||||||
|
struct ble_scan_stop_cmpl_evt_param {
|
||||||
|
esp_bt_status_t status; /*!< Indicate scan stop operation success status */
|
||||||
|
} scan_stop_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT */
|
||||||
|
/**
|
||||||
|
* @brief ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT
|
||||||
|
*/
|
||||||
|
struct ble_adv_stop_cmpl_evt_param {
|
||||||
|
esp_bt_status_t status; /*!< Indicate adv stop operation success status */
|
||||||
|
} adv_stop_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
|
||||||
} esp_ble_gap_cb_param_t;
|
} esp_ble_gap_cb_param_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4533,17 +4533,28 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data)
|
|||||||
if (p_data->ble_observe.start) {
|
if (p_data->ble_observe.start) {
|
||||||
/*Save the callback to be called when a scan results are available */
|
/*Save the callback to be called when a scan results are available */
|
||||||
bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback;
|
bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback;
|
||||||
|
|
||||||
if ((status = BTM_BleObserve(TRUE, p_data->ble_observe.duration,
|
if ((status = BTM_BleObserve(TRUE, p_data->ble_observe.duration,
|
||||||
bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb)) != BTM_CMD_STARTED) {
|
bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb)) != BTM_CMD_STARTED) {
|
||||||
APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d\n", __FUNCTION__, status);
|
APPL_TRACE_WARNING(" %s start observe failed. status=0x%x\n", __FUNCTION__, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_data->ble_observe.p_start_scan_cback) {
|
if (p_data->ble_observe.p_start_scan_cback) {
|
||||||
status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE);
|
status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE);
|
||||||
p_data->ble_observe.p_start_scan_cback(status);
|
p_data->ble_observe.p_start_scan_cback(status);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bta_dm_search_cb.p_scan_cback = NULL;
|
bta_dm_search_cb.p_scan_cback = NULL;
|
||||||
BTM_BleObserve(FALSE, 0, NULL, NULL );
|
status = BTM_BleObserve(FALSE, 0, NULL, NULL);
|
||||||
|
|
||||||
|
if (status != BTM_CMD_STARTED){
|
||||||
|
APPL_TRACE_WARNING(" %s stop observe failed, status=0x%x\n", __FUNCTION__, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_data->ble_observe.p_stop_scan_cback) {
|
||||||
|
status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE);
|
||||||
|
p_data->ble_observe.p_stop_scan_cback(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -4714,7 +4725,20 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data)
|
void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data)
|
||||||
{
|
{
|
||||||
BTM_BleBroadcast(p_data->ble_observe.start);
|
tBTM_STATUS status = 0;
|
||||||
|
BOOLEAN start = p_data->ble_observe.start;
|
||||||
|
|
||||||
|
status = BTM_BleBroadcast(start);
|
||||||
|
|
||||||
|
if (p_data->ble_observe.p_stop_adv_cback){
|
||||||
|
if (status != BTM_SUCCESS){
|
||||||
|
APPL_TRACE_WARNING("%s, %s, status=0x%x\n", __func__,\
|
||||||
|
(start == TRUE) ? "start adv failed" : "stop adv failed", status);
|
||||||
|
}
|
||||||
|
status = (status == BTM_SUCCESS ? BTA_SUCCESS : BTA_FAILURE);
|
||||||
|
p_data->ble_observe.p_stop_adv_cback(status);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -1333,7 +1333,7 @@ extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
|
|||||||
** Returns None
|
** Returns None
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern void BTA_DmBleBroadcast (BOOLEAN start)
|
extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb)
|
||||||
{
|
{
|
||||||
tBTA_DM_API_BLE_OBSERVE *p_msg;
|
tBTA_DM_API_BLE_OBSERVE *p_msg;
|
||||||
|
|
||||||
@ -1344,6 +1344,9 @@ extern void BTA_DmBleBroadcast (BOOLEAN start)
|
|||||||
|
|
||||||
p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
|
p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
|
||||||
p_msg->start = start;
|
p_msg->start = start;
|
||||||
|
if (start == FALSE){
|
||||||
|
p_msg->p_stop_adv_cback= p_start_stop_adv_cb;
|
||||||
|
}
|
||||||
|
|
||||||
bta_sys_sendmsg(p_msg);
|
bta_sys_sendmsg(p_msg);
|
||||||
}
|
}
|
||||||
@ -2129,7 +2132,7 @@ void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transpor
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
||||||
tBTA_DM_SEARCH_CBACK *p_results_cb,
|
tBTA_DM_SEARCH_CBACK *p_results_cb,
|
||||||
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cb)
|
tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb)
|
||||||
{
|
{
|
||||||
tBTA_DM_API_BLE_OBSERVE *p_msg;
|
tBTA_DM_API_BLE_OBSERVE *p_msg;
|
||||||
|
|
||||||
@ -2142,7 +2145,12 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
|||||||
p_msg->start = start;
|
p_msg->start = start;
|
||||||
p_msg->duration = duration;
|
p_msg->duration = duration;
|
||||||
p_msg->p_cback = p_results_cb;
|
p_msg->p_cback = p_results_cb;
|
||||||
p_msg->p_start_scan_cback = p_start_scan_cb;
|
if (start){
|
||||||
|
p_msg->p_start_scan_cback = p_start_stop_scan_cb;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_msg->p_stop_scan_cback = p_start_stop_scan_cb;
|
||||||
|
}
|
||||||
|
|
||||||
bta_sys_sendmsg(p_msg);
|
bta_sys_sendmsg(p_msg);
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,9 @@ typedef struct {
|
|||||||
BOOLEAN start;
|
BOOLEAN start;
|
||||||
UINT16 duration;
|
UINT16 duration;
|
||||||
tBTA_DM_SEARCH_CBACK *p_cback;
|
tBTA_DM_SEARCH_CBACK *p_cback;
|
||||||
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cback;
|
tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_scan_cback;
|
||||||
|
tBTA_START_STOP_SCAN_CMPL_CBACK *p_stop_scan_cback;
|
||||||
|
tBTA_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback;
|
||||||
} tBTA_DM_API_BLE_OBSERVE;
|
} tBTA_DM_API_BLE_OBSERVE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1099,7 +1099,9 @@ typedef void (tBTA_BLE_SCAN_SETUP_CBACK) (tBTA_BLE_BATCH_SCAN_EVT evt,
|
|||||||
tBTA_DM_BLE_REF_VALUE ref_value,
|
tBTA_DM_BLE_REF_VALUE ref_value,
|
||||||
tBTA_STATUS status);
|
tBTA_STATUS status);
|
||||||
|
|
||||||
typedef void (tBTA_START_SCAN_CMPL_CBACK) (tBTA_STATUS status);
|
typedef void (tBTA_START_STOP_SCAN_CMPL_CBACK) (tBTA_STATUS status);
|
||||||
|
|
||||||
|
typedef void (tBTA_START_STOP_ADV_CMPL_CBACK) (tBTA_STATUS status);
|
||||||
|
|
||||||
typedef void (tBTA_BLE_TRACK_ADV_CMPL_CBACK)(int action, tBTA_STATUS status,
|
typedef void (tBTA_BLE_TRACK_ADV_CMPL_CBACK)(int action, tBTA_STATUS status,
|
||||||
tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
|
tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
|
||||||
@ -2004,7 +2006,7 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport,
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
|
||||||
tBTA_DM_SEARCH_CBACK *p_results_cb,
|
tBTA_DM_SEARCH_CBACK *p_results_cb,
|
||||||
tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cb);
|
tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb);
|
||||||
|
|
||||||
extern void BTA_DmBleStopAdvertising(void);
|
extern void BTA_DmBleStopAdvertising(void);
|
||||||
|
|
||||||
@ -2111,11 +2113,12 @@ extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_l
|
|||||||
** Description This function starts or stops LE broadcasting.
|
** Description This function starts or stops LE broadcasting.
|
||||||
**
|
**
|
||||||
** Parameters start: start or stop broadcast.
|
** Parameters start: start or stop broadcast.
|
||||||
|
** p_start_stop_adv_cb: stop broadcast completed event
|
||||||
**
|
**
|
||||||
** Returns None
|
** Returns None
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern void BTA_DmBleBroadcast (BOOLEAN start);
|
extern void BTA_DmBleBroadcast (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb);
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -386,6 +386,25 @@ static void btc_start_adv_callback(tBTA_STATUS status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void btc_stop_adv_callback(tBTA_STATUS status)
|
||||||
|
{
|
||||||
|
esp_ble_gap_cb_param_t param;
|
||||||
|
bt_status_t ret;
|
||||||
|
btc_msg_t msg;
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CB;
|
||||||
|
msg.pid = BTC_PID_GAP_BLE;
|
||||||
|
msg.act = ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT;
|
||||||
|
param.adv_stop_cmpl.status = status;
|
||||||
|
|
||||||
|
ret = btc_transfer_context(&msg, ¶m,
|
||||||
|
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||||
|
|
||||||
|
if (ret != BT_STATUS_SUCCESS) {
|
||||||
|
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBTA_START_ADV_CMPL_CBACK start_adv_cback)
|
static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBTA_START_ADV_CMPL_CBACK start_adv_cback)
|
||||||
{
|
{
|
||||||
tBLE_BD_ADDR peer_addr;
|
tBLE_BD_ADDR peer_addr;
|
||||||
@ -520,6 +539,24 @@ static void btc_start_scan_callback(tBTA_STATUS status)
|
|||||||
msg.act = ESP_GAP_BLE_SCAN_START_COMPLETE_EVT;
|
msg.act = ESP_GAP_BLE_SCAN_START_COMPLETE_EVT;
|
||||||
param.scan_start_cmpl.status = status;
|
param.scan_start_cmpl.status = status;
|
||||||
|
|
||||||
|
ret = btc_transfer_context(&msg, ¶m,
|
||||||
|
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||||
|
|
||||||
|
if (ret != BT_STATUS_SUCCESS) {
|
||||||
|
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btc_stop_scan_callback(tBTA_STATUS status)
|
||||||
|
{
|
||||||
|
esp_ble_gap_cb_param_t param;
|
||||||
|
bt_status_t ret;
|
||||||
|
btc_msg_t msg;
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CB;
|
||||||
|
msg.pid = BTC_PID_GAP_BLE;
|
||||||
|
msg.act = ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT;
|
||||||
|
param.scan_stop_cmpl.status = status;
|
||||||
|
|
||||||
ret = btc_transfer_context(&msg, ¶m,
|
ret = btc_transfer_context(&msg, ¶m,
|
||||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||||
@ -531,7 +568,7 @@ static void btc_start_scan_callback(tBTA_STATUS status)
|
|||||||
|
|
||||||
static void btc_ble_start_scanning(uint8_t duration,
|
static void btc_ble_start_scanning(uint8_t duration,
|
||||||
tBTA_DM_SEARCH_CBACK *results_cb,
|
tBTA_DM_SEARCH_CBACK *results_cb,
|
||||||
tBTA_START_SCAN_CMPL_CBACK *start_scan_cb)
|
tBTA_START_STOP_SCAN_CMPL_CBACK *start_scan_cb)
|
||||||
{
|
{
|
||||||
if ((results_cb != NULL) && (start_scan_cb != NULL)) {
|
if ((results_cb != NULL) && (start_scan_cb != NULL)) {
|
||||||
///Start scan the device
|
///Start scan the device
|
||||||
@ -541,18 +578,18 @@ static void btc_ble_start_scanning(uint8_t duration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btc_ble_stop_scanning(void)
|
static void btc_ble_stop_scanning(tBTA_START_STOP_SCAN_CMPL_CBACK *stop_scan_cb)
|
||||||
{
|
{
|
||||||
uint8_t duration = 0;
|
uint8_t duration = 0;
|
||||||
BTA_DmBleObserve(false, duration, NULL, NULL);
|
BTA_DmBleObserve(false, duration, NULL, stop_scan_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void btc_ble_stop_advertising(void)
|
static void btc_ble_stop_advertising(tBTA_START_STOP_ADV_CMPL_CBACK *stop_adv_cb)
|
||||||
{
|
{
|
||||||
bool stop_adv = false;
|
bool stop_adv = false;
|
||||||
|
|
||||||
BTA_DmBleBroadcast(stop_adv);
|
BTA_DmBleBroadcast(stop_adv, stop_adv_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int,
|
static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int,
|
||||||
@ -625,6 +662,12 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
|
|||||||
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
||||||
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, param);
|
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, param);
|
||||||
break;
|
break;
|
||||||
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
|
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT, param);
|
||||||
|
break;
|
||||||
|
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
|
||||||
|
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT, param);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -747,13 +790,13 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
|||||||
btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback, btc_start_scan_callback);
|
btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback, btc_start_scan_callback);
|
||||||
break;
|
break;
|
||||||
case BTC_GAP_BLE_ACT_STOP_SCAN:
|
case BTC_GAP_BLE_ACT_STOP_SCAN:
|
||||||
btc_ble_stop_scanning();
|
btc_ble_stop_scanning(btc_stop_scan_callback);
|
||||||
break;
|
break;
|
||||||
case BTC_GAP_BLE_ACT_START_ADV:
|
case BTC_GAP_BLE_ACT_START_ADV:
|
||||||
btc_ble_start_advertising(&arg->start_adv.adv_params, btc_start_adv_callback);
|
btc_ble_start_advertising(&arg->start_adv.adv_params, btc_start_adv_callback);
|
||||||
break;
|
break;
|
||||||
case BTC_GAP_BLE_ACT_STOP_ADV:
|
case BTC_GAP_BLE_ACT_STOP_ADV:
|
||||||
btc_ble_stop_advertising();
|
btc_ble_stop_advertising(btc_stop_adv_callback);
|
||||||
break;
|
break;
|
||||||
case BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM:
|
case BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM:
|
||||||
btc_ble_update_conn_params(arg->conn_update_params.conn_params.bda,
|
btc_ble_update_conn_params(arg->conn_update_params.conn_params.bda,
|
||||||
|
@ -110,16 +110,16 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ESP_GATTC_REG_EVT:
|
case ESP_GATTC_REG_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "REG_EVT\n");
|
ESP_LOGI(GATTC_TAG, "REG_EVT");
|
||||||
esp_ble_gap_set_scan_params(&ble_scan_params);
|
esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_OPEN_EVT:
|
case ESP_GATTC_OPEN_EVT:
|
||||||
conn_id = p_data->open.conn_id;
|
conn_id = p_data->open.conn_id;
|
||||||
|
|
||||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d\n", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||||
|
|
||||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x\n",
|
ESP_LOGI(GATTC_TAG, "REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[1],
|
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[1],
|
||||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[3],
|
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[3],
|
||||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[5]
|
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[5]
|
||||||
@ -130,37 +130,37 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||||
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
||||||
conn_id = p_data->search_res.conn_id;
|
conn_id = p_data->search_res.conn_id;
|
||||||
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x\n", conn_id);
|
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x", conn_id);
|
||||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "UUID16: %x", srvc_id->id.uuid.uuid.uuid16);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32);
|
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0],
|
ESP_LOGI(GATTC_TAG, "UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x", srvc_id->id.uuid.uuid.uuid128[0],
|
||||||
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
||||||
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
||||||
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
||||||
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
||||||
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d\n", srvc_id->id.uuid.len);
|
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||||
conn_id = p_data->search_cmpl.conn_id;
|
conn_id = p_data->search_cmpl.conn_id;
|
||||||
ESP_LOGI(GATTC_TAG, "SEARCH_CMPL: conn_id = %x, status %d\n", conn_id, p_data->search_cmpl.status);
|
ESP_LOGI(GATTC_TAG, "SEARCH_CMPL: conn_id = %x, status %d", conn_id, p_data->search_cmpl.status);
|
||||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_GET_CHAR_EVT:
|
case ESP_GATTC_GET_CHAR_EVT:
|
||||||
if (p_data->get_char.status != ESP_GATT_OK) {
|
if (p_data->get_char.status != ESP_GATT_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ESP_LOGI(GATTC_TAG, "GET CHAR: conn_id = %x, status %d\n", p_data->get_char.conn_id, p_data->get_char.status);
|
ESP_LOGI(GATTC_TAG, "GET CHAR: conn_id = %x, status %d", p_data->get_char.conn_id, p_data->get_char.status);
|
||||||
ESP_LOGI(GATTC_TAG, "GET CHAR: srvc_id = %04x, char_id = %04x\n", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "GET CHAR: srvc_id = %04x, char_id = %04x", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
||||||
|
|
||||||
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
||||||
ESP_LOGI(GATTC_TAG, "register notify\n");
|
ESP_LOGI(GATTC_TAG, "register notify");
|
||||||
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
break;
|
break;
|
||||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||||
uint16_t notify_en = 1;
|
uint16_t notify_en = 1;
|
||||||
ESP_LOGI(GATTC_TAG, "REG FOR NOTIFY: status %d\n", p_data->reg_for_notify.status);
|
ESP_LOGI(GATTC_TAG, "REG FOR NOTIFY: status %d", p_data->reg_for_notify.status);
|
||||||
ESP_LOGI(GATTC_TAG, "REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x\n", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
||||||
|
|
||||||
esp_ble_gattc_write_char_descr(
|
esp_ble_gattc_write_char_descr(
|
||||||
gattc_if,
|
gattc_if,
|
||||||
@ -184,10 +184,10 @@ static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_NOTIFY_EVT:
|
case ESP_GATTC_NOTIFY_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "NOTIFY: len %d, value %08x\n", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
ESP_LOGI(GATTC_TAG, "NOTIFY: len %d, value %08x", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "WRITE: status %d\n", p_data->write.status);
|
ESP_LOGI(GATTC_TAG, "WRITE: status %d", p_data->write.status);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -201,15 +201,15 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ESP_GATTC_REG_EVT:
|
case ESP_GATTC_REG_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "REG_EVT\n");
|
ESP_LOGI(GATTC_TAG, "REG_EVT");
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_OPEN_EVT:
|
case ESP_GATTC_OPEN_EVT:
|
||||||
conn_id = p_data->open.conn_id;
|
conn_id = p_data->open.conn_id;
|
||||||
|
|
||||||
memcpy(gl_profile_tab[PROFILE_B_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
memcpy(gl_profile_tab[PROFILE_B_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||||
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d\n", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
ESP_LOGI(GATTC_TAG, "ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||||
|
|
||||||
ESP_LOGI(GATTC_TAG, "REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x\n",
|
ESP_LOGI(GATTC_TAG, "REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[1],
|
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[1],
|
||||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[3],
|
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[3],
|
||||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[5]
|
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[5]
|
||||||
@ -220,37 +220,37 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||||
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
||||||
conn_id = p_data->search_res.conn_id;
|
conn_id = p_data->search_res.conn_id;
|
||||||
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x\n", conn_id);
|
ESP_LOGI(GATTC_TAG, "SEARCH RES: conn_id = %x", conn_id);
|
||||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "UUID16: %x", srvc_id->id.uuid.uuid.uuid16);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32);
|
ESP_LOGI(GATTC_TAG, "UUID32: %x", srvc_id->id.uuid.uuid.uuid32);
|
||||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||||
ESP_LOGI(GATTC_TAG, "UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0],
|
ESP_LOGI(GATTC_TAG, "UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x", srvc_id->id.uuid.uuid.uuid128[0],
|
||||||
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
||||||
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
||||||
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
||||||
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
||||||
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d\n", srvc_id->id.uuid.len);
|
ESP_LOGE(GATTC_TAG, "UNKNOWN LEN %d", srvc_id->id.uuid.len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||||
conn_id = p_data->search_cmpl.conn_id;
|
conn_id = p_data->search_cmpl.conn_id;
|
||||||
ESP_LOGI(GATTC_TAG, "SEARCH_CMPL: conn_id = %x, status %d\n", conn_id, p_data->search_cmpl.status);
|
ESP_LOGI(GATTC_TAG, "SEARCH_CMPL: conn_id = %x, status %d", conn_id, p_data->search_cmpl.status);
|
||||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_GET_CHAR_EVT:
|
case ESP_GATTC_GET_CHAR_EVT:
|
||||||
if (p_data->get_char.status != ESP_GATT_OK) {
|
if (p_data->get_char.status != ESP_GATT_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ESP_LOGI(GATTC_TAG, "GET CHAR: conn_id = %x, status %d\n", p_data->get_char.conn_id, p_data->get_char.status);
|
ESP_LOGI(GATTC_TAG, "GET CHAR: conn_id = %x, status %d", p_data->get_char.conn_id, p_data->get_char.status);
|
||||||
ESP_LOGI(GATTC_TAG, "GET CHAR: srvc_id = %04x, char_id = %04x\n", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "GET CHAR: srvc_id = %04x, char_id = %04x", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
||||||
|
|
||||||
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
||||||
ESP_LOGI(GATTC_TAG, "register notify\n");
|
ESP_LOGI(GATTC_TAG, "register notify");
|
||||||
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +258,8 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
break;
|
break;
|
||||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||||
uint16_t notify_en = 1;
|
uint16_t notify_en = 1;
|
||||||
ESP_LOGI(GATTC_TAG, "REG FOR NOTIFY: status %d\n", p_data->reg_for_notify.status);
|
ESP_LOGI(GATTC_TAG, "REG FOR NOTIFY: status %d", p_data->reg_for_notify.status);
|
||||||
ESP_LOGI(GATTC_TAG, "REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x\n", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
ESP_LOGI(GATTC_TAG, "REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
||||||
|
|
||||||
esp_ble_gattc_write_char_descr(
|
esp_ble_gattc_write_char_descr(
|
||||||
gattc_if,
|
gattc_if,
|
||||||
@ -274,10 +274,10 @@ static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTC_NOTIFY_EVT:
|
case ESP_GATTC_NOTIFY_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "NOTIFY: len %d, value %08x\n", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
ESP_LOGI(GATTC_TAG, "NOTIFY: len %d, value %08x", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
||||||
break;
|
break;
|
||||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||||
ESP_LOGI(GATTC_TAG, "WRITE: status %d\n", p_data->write.status);
|
ESP_LOGI(GATTC_TAG, "WRITE: status %d", p_data->write.status);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -298,7 +298,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
|||||||
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
|
||||||
//scan start complete event to indicate scan start successfully or failed
|
//scan start complete event to indicate scan start successfully or failed
|
||||||
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
ESP_LOGE(GATTC_TAG, "Scan start failed\n");
|
ESP_LOGE(GATTC_TAG, "Scan start failed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
|
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
|
||||||
@ -312,17 +312,17 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
|||||||
ESP_LOGI(GATTC_TAG, "\n");
|
ESP_LOGI(GATTC_TAG, "\n");
|
||||||
adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
|
adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
|
||||||
ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
|
ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
|
||||||
ESP_LOGI(GATTC_TAG, "Searched Device Name Len %d\n", adv_name_len);
|
ESP_LOGI(GATTC_TAG, "Searched Device Name Len %d", adv_name_len);
|
||||||
for (int j = 0; j < adv_name_len; j++) {
|
for (int j = 0; j < adv_name_len; j++) {
|
||||||
ESP_LOGI(GATTC_TAG, "%c", adv_name[j]);
|
ESP_LOGI(GATTC_TAG, "%c", adv_name[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adv_name != NULL) {
|
if (adv_name != NULL) {
|
||||||
if (strcmp((char *)adv_name, device_name) == 0) {
|
if (strcmp((char *)adv_name, device_name) == 0) {
|
||||||
ESP_LOGI(GATTC_TAG, "Searched device %s\n", device_name);
|
ESP_LOGI(GATTC_TAG, "Searched device %s", device_name);
|
||||||
if (connect == false) {
|
if (connect == false) {
|
||||||
connect = true;
|
connect = true;
|
||||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device.\n");
|
ESP_LOGI(GATTC_TAG, "Connect to the remote device.");
|
||||||
esp_ble_gap_stop_scanning();
|
esp_ble_gap_stop_scanning();
|
||||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
||||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
||||||
@ -337,6 +337,25 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
|
||||||
|
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||||
|
ESP_LOGE(GATTC_TAG, "Scan stop failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTC_TAG, "Stop scan successfully");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
|
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
|
||||||
|
ESP_LOGE(GATTC_TAG, "Adv stop failed");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTC_TAG, "Stop adv successfully");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -344,14 +363,14 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
|||||||
|
|
||||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
||||||
{
|
{
|
||||||
ESP_LOGI(GATTC_TAG, "EVT %d, gattc if %d\n", event, gattc_if);
|
ESP_LOGI(GATTC_TAG, "EVT %d, gattc if %d", event, gattc_if);
|
||||||
|
|
||||||
/* If event is register event, store the gattc_if for each profile */
|
/* If event is register event, store the gattc_if for each profile */
|
||||||
if (event == ESP_GATTC_REG_EVT) {
|
if (event == ESP_GATTC_REG_EVT) {
|
||||||
if (param->reg.status == ESP_GATT_OK) {
|
if (param->reg.status == ESP_GATT_OK) {
|
||||||
gl_profile_tab[param->reg.app_id].gattc_if = gattc_if;
|
gl_profile_tab[param->reg.app_id].gattc_if = gattc_if;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(GATTC_TAG, "Reg app failed, app_id %04x, status %d\n",
|
ESP_LOGI(GATTC_TAG, "Reg app failed, app_id %04x, status %d",
|
||||||
param->reg.app_id,
|
param->reg.app_id,
|
||||||
param->reg.status);
|
param->reg.status);
|
||||||
return;
|
return;
|
||||||
@ -377,17 +396,17 @@ void ble_client_appRegister(void)
|
|||||||
{
|
{
|
||||||
esp_err_t status;
|
esp_err_t status;
|
||||||
|
|
||||||
ESP_LOGI(GATTC_TAG, "register callback\n");
|
ESP_LOGI(GATTC_TAG, "register callback");
|
||||||
|
|
||||||
//register the scan callback function to the gap moudule
|
//register the scan callback function to the gap moudule
|
||||||
if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
|
if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
|
||||||
ESP_LOGE(GATTC_TAG, "gap register error, error code = %x\n", status);
|
ESP_LOGE(GATTC_TAG, "gap register error, error code = %x", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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_cb)) != ESP_OK) {
|
if ((status = esp_ble_gattc_register_callback(esp_gattc_cb)) != ESP_OK) {
|
||||||
ESP_LOGE(GATTC_TAG, "gattc register error, error code = %x\n", status);
|
ESP_LOGE(GATTC_TAG, "gattc register error, error code = %x", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_ble_gattc_app_register(PROFILE_A_APP_ID);
|
esp_ble_gattc_app_register(PROFILE_A_APP_ID);
|
||||||
|
@ -156,6 +156,13 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
|||||||
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
ESP_LOGE(GATTS_TAG, "Advertising start failed\n");
|
ESP_LOGE(GATTS_TAG, "Advertising start failed\n");
|
||||||
}
|
}
|
||||||
|
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||||
|
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||||
|
ESP_LOGE(GATTS_TAG, "Advertising stop failed\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGI(GATTS_TAG, "Stop adv successfully\n");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user