component bt:Add stop scan API to the esp_gap_ble API module

This commit is contained in:
Yulong 2016-11-19 09:56:36 -05:00
parent a76b65ed95
commit 1561c02ba9
6 changed files with 35 additions and 6 deletions

View 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;

View 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);
/*******************************************************************************
**

View 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);
}

View 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);

View 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)

View 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: