component bt:change the scan rsp callback & scan param setup

This commit is contained in:
Yulong 2016-11-16 06:50:44 -05:00
parent 8fed003ce5
commit a63383dd19
6 changed files with 75 additions and 34 deletions

View file

@ -14,6 +14,8 @@ typedef enum {
ESP_BT_STATUS_WRONG_MODE = 5,
} esp_bt_status_t;
#define ESP_DEFAULT_GATT_IF 0xff
#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))

View file

@ -71,6 +71,7 @@ typedef struct {
uint8_t *p_service_data;
uint16_t service_uuid_len;
uint8_t *p_service_uuid;
uint8_t flag;
} esp_ble_adv_data_t;
typedef enum {

View file

@ -110,7 +110,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
memset(bta_adv_data, 0, sizeof(tBTA_BLE_ADV_DATA));
mask = 0;
if (!p_adv_data->set_scan_rsp)
if (p_adv_data->flag != 0)
{
mask = BTM_BLE_AD_BIT_FLAGS;
}
@ -305,16 +305,6 @@ static void btc_adv_data_callback(tBTA_STATUS status)
}
}
static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{
tBTA_BLE_ADV_DATA bta_adv_data; //TODO:must be global, not stack
tBTA_BLE_AD_MASK data_mask = 0;
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
}
static void btc_scan_rsp_data_callback(tBTA_STATUS status)
{
esp_ble_gap_cb_param_t param;
@ -324,7 +314,7 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status)
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT;
param.scan_rsp_data_cmpl.status = status;
param.adv_data_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
@ -334,13 +324,53 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status)
}
}
static void btc_ble_set_scan_rsp_data(esp_ble_adv_data_t *scan_rsp_data,
tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback)
static void btc_set_scan_param_callback(tGATT_IF client_if, 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_PARAM_SET_COMPLETE_EVT;
param.adv_data_cmpl.status = status;
ret = btc_transfer_context(&msg, &param,
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_set_adv_data(esp_ble_adv_data_t *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
{
tBTA_BLE_ADV_DATA bta_adv_data; //TODO:must be global, not stack
tBTA_BLE_AD_MASK data_mask = 0;
btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask);
BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback);
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
if (!adv_data->set_scan_rsp){
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
}else{
BTA_DmBleSetScanRsp(data_mask, &gl_bta_adv_data, p_adv_data_cback);
}
}
static void btc_ble_set_scan_param(esp_ble_scan_params_t *ble_scan_params,
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
{
//tBTA_BLE_AD_MASK data_mask = 0;
BTA_DmSetBleScanParams (ESP_DEFAULT_GATT_IF,
ble_scan_params->scan_interval,
ble_scan_params->scan_window,
ble_scan_params->scan_type,
scan_param_setup_cback);
//btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask);
//BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback);
}
static void btc_ble_start_advertising(esp_ble_adv_params_t *ble_adv_params)
@ -544,10 +574,16 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA:
{
if(arg->adv_data.set_scan_rsp == false){
btc_ble_set_adv_data(&arg->adv_data, btc_adv_data_callback);
}else{
btc_ble_set_adv_data(&arg->adv_data, btc_scan_rsp_data_callback);
}
break;
}
case BTC_GAP_BLE_ACT_SET_SCAN_PARAM:
btc_ble_set_scan_rsp_data(&arg->adv_data, btc_adv_data_callback);
btc_ble_set_scan_param(&arg->scan_params, btc_set_scan_param_callback);
break;
case BTC_GAP_BLE_ACT_START_SCAN:
btc_ble_start_scanning(arg->duration, btc_search_callback);

View file

@ -373,7 +373,7 @@ void bt_app_stop_timer(TIMER_LIST_ENT *p_tle)
// Get the alarm for the timer list entry.
osi_alarm_t *alarm = hash_map_get(bt_app_general_alarm_hash_map, p_tle);
if (alarm == NULL) {
LOG_WARN("%s Unable to find expected alarm in hashmap", __func__);
LOG_WARN("%s Unable to find expected alarm in hashmap\n", __func__);
return;
}
osi_alarm_cancel(alarm);

View file

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/****************************************************************************
*
* This file is for gatt client. It can scan ble device, connect one device,