Commit 8ee9c7ab authored by 薛小虎's avatar 薛小虎

蓝牙连接测试

parent 6623f97f
......@@ -189,7 +189,7 @@ static uint8_t raw_adv_data[] = {
static uint8_t raw_scan_rsp_data[] = {
/* flags */
0x02, 0x01, 0x02,
0x02, 0x0a, 0xeb,
/* service uuid */
0x03, 0x03, 0x69, 0x67,
};
......@@ -237,12 +237,12 @@ static esp_ble_adv_data_t scan_rsp_data = {
#endif /* CONFIG_SET_RAW_ADV_DATA */
static esp_ble_adv_params_t adv_params = {
.adv_int_min = 0x20,
.adv_int_max = 0x40,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_RANDOM,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.adv_int_min = 0x060,
.adv_int_max = 0x060,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
struct gatts_profile_inst {
......@@ -260,6 +260,33 @@ struct gatts_profile_inst {
esp_bt_uuid_t descr_uuid;
};
static void ble_init_adv_data(const char *name)
{
int len = strlen(name);
uint8_t raw_adv_data1[len+5];
//flag
raw_adv_data1[0] = 2;
raw_adv_data1[1] = 1;
raw_adv_data1[2] = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT);
//adv name
raw_adv_data1[3] = len + 1;
raw_adv_data1[4] = ESP_BLE_AD_TYPE_NAME_CMPL;
for (int i = 0;i < len;i++)
{
raw_adv_data1[i+5] = *(name++);
}
//The length of adv data must be less than 31 bytes
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data1, sizeof(raw_adv_data1));
if (raw_adv_ret){
ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = 0x%x ", raw_adv_ret);
}
esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_adv_data1, sizeof(raw_adv_data1));
if (raw_scan_ret){
ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = 0x%x", raw_scan_ret);
}
}
static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
......@@ -546,18 +573,18 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
}
break;
#else
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
adv_config_done &= (~ADV_CONFIG_FLAG);
if (adv_config_done == 0){
esp_ble_gap_start_advertising(&adv_params);
}
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
if (adv_config_done == 0){
esp_ble_gap_start_advertising(&adv_params);
}
break;
// case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
// adv_config_done &= (~ADV_CONFIG_FLAG);
// if (adv_config_done == 0){
// esp_ble_gap_start_advertising(&adv_params);
// }
// break;
// case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
// adv_config_done &= (~SCAN_RSP_CONFIG_FLAG);
// if (adv_config_done == 0){
// esp_ble_gap_start_advertising(&adv_params);
// }
// break;
#endif
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
/* advertising start complete event to indicate advertising start successfully or failed */
......@@ -649,40 +676,45 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble
}
bool create_tab1 = false;
#define BLE_ADV_NAME "ESP_COEX_BLE_DEMO"
static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
switch (event) {
case ESP_GATTS_REG_EVT:{
esp_ble_gap_set_rand_addr(rand_addr);
// esp_ble_gap_set_rand_addr(rand_addr);
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name((const char *)BT_Device_Name);
if (set_dev_name_ret){
ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
}
#ifdef CONFIG_SET_RAW_ADV_DATA
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
if (raw_adv_ret){
ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = %x ", raw_adv_ret);
}
adv_config_done |= ADV_CONFIG_FLAG;
esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
if (raw_scan_ret){
ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = %x", raw_scan_ret);
}
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
esp_ble_gap_config_local_privacy(true);
ble_init_adv_data(BLE_ADV_NAME);
// esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
// if (raw_adv_ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config raw adv data failed, error code = %x ", raw_adv_ret);
// }
// adv_config_done |= ADV_CONFIG_FLAG;
// esp_err_t raw_scan_ret = esp_ble_gap_config_scan_rsp_data_raw(raw_scan_rsp_data, sizeof(raw_scan_rsp_data));
// if (raw_scan_ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config raw scan rsp data failed, error code = %x", raw_scan_ret);
// }
// adv_config_done |= SCAN_RSP_CONFIG_FLAG;
printf("adv configed\r\n");
#else
//config adv data
esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
if (ret){
ESP_LOGE(GATTS_TABLE_TAG, "config adv data failed, error code = %x", ret);
}
adv_config_done |= ADV_CONFIG_FLAG;
//config scan response data
ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
if (ret){
ESP_LOGE(GATTS_TABLE_TAG, "config scan response data failed, error code = %x", ret);
}
adv_config_done |= SCAN_RSP_CONFIG_FLAG;
// //config adv data
// esp_err_t ret = esp_ble_gap_config_adv_data(&adv_data);
// if (ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config adv data failed, error code = %x", ret);
// }
// adv_config_done |= ADV_CONFIG_FLAG;
// //config scan response data
// ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
// if (ret){
// ESP_LOGE(GATTS_TABLE_TAG, "config scan response data failed, error code = %x", ret);
// }
// adv_config_done |= SCAN_RSP_CONFIG_FLAG;
#endif
esp_err_t create_attr_ret = esp_ble_gatts_create_attr_tab(gatt_db, gatts_if, HRS_IDX_NB, SVC_INST_ID);
if (create_attr_ret){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment