]> granicus.if.org Git - esp-idf/commitdiff
component bt:Add stop scan API to the esp_gap_ble API module
authorYulong <huangyulong@espressif.com>
Sat, 19 Nov 2016 14:56:36 +0000 (09:56 -0500)
committerYulong <huangyulong@espressif.com>
Sat, 19 Nov 2016 14:56:36 +0000 (09:56 -0500)
components/bt/bluedroid/api/esp_gap_ble_api.c
components/bt/bluedroid/api/include/esp_gap_ble_api.h
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
examples/09_arch_client/components/bluedroid_demos/app_project/Arch_SimpleClientProject.c

index a0ec1e03621a8c05ad8153e638c77ce2ddfe1434..dfba3798566280bcdd5c2faba7f2eeac8574be69 100644 (file)
@@ -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;
index 578ac351ae2476ddb000899750ef233f3af278b7..8b15122410c2bf6842d0b60edcef43d52e407ec0 100644 (file)
@@ -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);
 
 /*******************************************************************************
 **
index 3dd982a695a17c1541369f3e53f4ac21ed7a655c..ffa20f54034da3eab5988de9a3fe2fb2f4a2f590 100644 (file)
@@ -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);
                        }
index e6971c6c03580c7800ec03d853cb43258e5bde71..2e1b5889b7271203ae18d6d2f2cb6eeabedb9b1a 100644 (file)
@@ -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);
index 8be640c3f543414359cedc461bebcd7b042ee179..674416f8494f634268f31b555502f4e2838eb759 100644 (file)
@@ -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)
index 46ba7c208c1872a77fe66de5833d4f4c42873193..1d1eec6a032d27ab7c2a12a74521bf3c195148f1 100644 (file)
@@ -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: