diff --git a/components/bt/bluedroid/api/esp_gap_ble_api.c b/components/bt/bluedroid/api/esp_gap_ble_api.c index a0ec1e0362..dfba379856 100644 --- a/components/bt/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/bluedroid/api/esp_gap_ble_api.c @@ -76,6 +76,18 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration) return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } + +esp_err_t esp_ble_gap_stop_scanning(void) +{ + btc_msg_t msg; + esp_ble_gap_args_t arg; + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_STOP_SCAN; + return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params) { btc_msg_t msg; diff --git a/components/bt/bluedroid/api/include/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/esp_gap_ble_api.h index 578ac351ae..8b15122410 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -267,6 +267,16 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params); esp_err_t esp_ble_gap_start_scanning(uint32_t duration); +/******************************************************************************* +** +** @function esp_ble_gap_stop_scanning +** +** @brief This function call to stop the device scanning the peer device whith advertising on the air +** @param void +** @return ESP_OK - success, other - failed +** +*******************************************************************************/ +esp_err_t esp_ble_gap_stop_scanning(void); /******************************************************************************* ** diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index 3dd982a695..ffa20f5403 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -105,12 +105,6 @@ 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/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index e6971c6c03..2e1b5889b7 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -513,6 +513,12 @@ static void btc_ble_start_scanning(uint8_t duration, tBTA_DM_SEARCH_CBACK *resul } } +static void btc_ble_stop_scanning(void) +{ + uint8_t duration = 0; + BTA_DmBleObserve(false, duration, NULL); +} + static void btc_ble_stop_advertising(void) { @@ -608,6 +614,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) btc_ble_start_scanning(arg->duration, btc_search_callback); break; case BTC_GAP_BLE_ACT_STOP_SCAN: + btc_ble_stop_scanning(); break; case BTC_GAP_BLE_ACT_START_ADV: btc_ble_start_advertising(&arg->adv_params); 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 8be640c3f5..674416f849 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -54,6 +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; + LOG_ERROR("the gattc event = %x\n",event); ret = btc_transfer_context(&msg, p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data); if (ret) 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 46ba7c208c..1d1eec6a03 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 @@ -168,6 +168,7 @@ static void esp_scan_result_cb(uint32_t event, void *param) { connet = TRUE; LOG_ERROR("Connet to the remote device.\n"); + esp_ble_gap_stop_scanning(); esp_ble_gattc_open(client_if, scan_result->scan_rst.bda, TRUE); } } @@ -192,6 +193,7 @@ static void esp_scan_result_cb(uint32_t event, void *param) static void esp_gattc_result_cb(uint32_t event, void *gattc_param) { + uint16_t conidx = 0; 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) @@ -202,6 +204,9 @@ static void esp_gattc_result_cb(uint32_t event, void *gattc_param) LOG_ERROR("status = %x, client_if = %x\n", status, client_if); break; case ESP_GATTC_OPEN_EVT: + conidx = gattc_data->open.conn_id; + LOG_ERROR("conidx = %x, if = %x\n",conidx, gattc_data->open.gatt_if); + esp_ble_gattc_search_service(conidx, NULL); LOG_ERROR("ESP_GATTC_OPEN_EVT\n"); break; default: