commpnent bt:Added the stop advertising to the bt project

This commit is contained in:
Yulong 2016-11-04 05:36:32 -04:00
parent 1544965b21
commit b83b0ed06a
3 changed files with 33 additions and 22 deletions

View File

@ -37,21 +37,6 @@
button_env_cb_t button_cb_env;
tBLE_BD_ADDR p_peer_bda = {
.type = API_PUBLIC_ADDR,
.bda = {0}
};
esp_ble_adv_params_all_t adv_params =
{
.adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100,
.adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100,
.adv_type = API_NON_DISCOVERABLE,
.addr_type_own = API_PUBLIC_ADDR,
.channel_map = ESP_BLE_ADV_CHNL_MAP,
.adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY,
.p_dir_bda = &p_peer_bda
};
@ -190,9 +175,11 @@ static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
///Start advertising
LOG_ERROR("\n*******Start sent the ADV.*************\n");
//esp_ble_start_advertising (&adv_params);
BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL);
//BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL);
break;
case ESP_GATTS_CONNECT_EVT:
LOG_ERROR("############BUTTON CONNCET EVT################\n");
//esp_ble_stop_advertising();
//set the connection flag to true
button_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda);
break;
@ -202,7 +189,7 @@ static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
break;
case ESP_GATTS_OPEN_EVT:
///stop the advertising after connected
esp_ble_stop_advertising();
break;
case ESP_GATTS_CLOSE_EVT:
if(button_cb_env.clcb.connected && (button_cb_env.clcb.conn_id == p_data->conn.conn_id))

View File

@ -169,7 +169,7 @@ void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb)
*******************************************************************************/
void esp_ble_stop_advertising (void)
{
bool stop_adv = true;
bool stop_adv = false;
BTA_DmBleBroadcast(stop_adv);
}

View File

@ -81,6 +81,24 @@ tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufactur
tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu};
tBLE_BD_ADDR p_peer_bda = {
.type = API_PUBLIC_ADDR,
.bda = {0}
};
esp_ble_adv_params_all_t adv_params =
{
.adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100,
.adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100,
.adv_type = API_NON_DISCOVERABLE,
.addr_type_own = API_PUBLIC_ADDR,
.channel_map = ESP_BLE_ADV_CHNL_MAP,
.adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY,
.p_dir_bda = &p_peer_bda
};
BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55};
@ -244,9 +262,9 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status)
DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT;
DIS_SrInit(dis_attr_mask);
*/
ble_but_create_svc();
//ble_but_create_svc();
/*instantiate a battery service*/
//bas_register();
bas_register();
/*instantiate the driver for button profile*/
//app_button_init();
#if (BUT_PROFILE_CFG)
@ -262,7 +280,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status)
#if (WX_AIRSYNC_CFG)
AirSync_Init(NULL);
#endif ///WX_AIRSYNC_CFG
esp_ble_start_advertising(&adv_params);
//API_Ble_AppStartAdvertising(&adv_params);
/*start advetising*/
// BTA_GATTS_Listen(server_if, true, NULL);
@ -290,6 +308,8 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data)
/*connect callback*/
case BTA_GATTS_CONNECT_EVT:
{
///Stop the advertising when the connection is establish
esp_ble_stop_advertising();
LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if,
p_data->conn.reason, p_data->conn.conn_id);
@ -298,7 +318,11 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data)
LOG_ERROR("is_connected=%d\n",is_connected);
}
break;
case BTA_GATTS_DISCONNECT_EVT:
///start the advertising again when lose the connection
esp_ble_start_advertising(&adv_params);
break;
default:
LOG_ERROR("unsettled event: %d\n", event);
}