mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(ble/bluedroid): Support setting connection params when creating connection
This commit is contained in:
@@ -565,12 +565,13 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
//esp_log_buffer_hex("bda", param->connect.remote_bda, 6);
|
||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, param->connect.remote_bda, 6);
|
||||
// create gattc virtual connection
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = BLE_ADDR_TYPE_RANDOM;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
break;
|
||||
|
||||
@@ -238,12 +238,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
ESP_LOGI(GATTC_TAG, "Scan stop successfully");
|
||||
if (is_connect == false) {
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device.");
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_rst.scan_rst.bda,ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_rst.scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
}
|
||||
|
||||
+15
-7
@@ -401,19 +401,27 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
#if(CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT && CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 34, 34, 0, 600);
|
||||
#else
|
||||
esp_ble_gap_set_prefer_conn_params(scan_result->scan_rst.bda, 32, 32, 0, 600);
|
||||
#endif
|
||||
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
|
||||
esp_ble_conn_params_t phy_1m_conn_params = {0};
|
||||
#if(CONFIG_EXAMPLE_GATTC_WRITE_THROUGHPUT && CONFIG_EXAMPLE_GATTS_NOTIFY_THROUGHPUT)
|
||||
phy_1m_conn_params.interval_max = 34;
|
||||
phy_1m_conn_params.interval_max = 34;
|
||||
#else
|
||||
phy_1m_conn_params.interval_max = 32;
|
||||
phy_1m_conn_params.interval_min = 32;
|
||||
#endif
|
||||
phy_1m_conn_params.latency = 0;
|
||||
phy_1m_conn_params.supervision_timeout = 600;
|
||||
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = ESP_BLE_PHY_1M_PREF_MASK;
|
||||
creat_conn_params.phy_1m_conn_params = &phy_1m_conn_params;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
}
|
||||
|
||||
@@ -368,12 +368,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
}
|
||||
|
||||
+8
-7
@@ -370,14 +370,15 @@ We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called eve
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "connect to the remote device.");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
|
||||
memcpy(&esp_ble_gatt_create_conn.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
esp_ble_gatt_create_conn.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
esp_ble_gatt_create_conn.is_direct = true;
|
||||
esp_ble_gatt_create_conn.is_aux = false;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&esp_ble_gatt_create_conn);
|
||||
&creat_conn_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -463,14 +463,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
connect = true;
|
||||
ESP_LOGI(GATTC_TAG, "Connect to the remote device");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
|
||||
memcpy(&esp_ble_gatt_create_conn.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
esp_ble_gatt_create_conn.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC;
|
||||
esp_ble_gatt_create_conn.is_direct = true;
|
||||
esp_ble_gatt_create_conn.is_aux = false;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&esp_ble_gatt_create_conn);
|
||||
&creat_conn_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,12 +817,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
conn_device_a = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[0]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
@@ -834,12 +835,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
conn_device_b = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[1]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
@@ -851,12 +853,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
conn_device_c = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[2]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
|
||||
+24
-21
@@ -160,14 +160,15 @@ The scan stop triggers an ``ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT`` event which is
|
||||
conn_device_a = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[0]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
|
||||
memcpy(&esp_ble_gatt_create_conn.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
esp_ble_gatt_create_conn.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
esp_ble_gatt_create_conn.is_direct = true;
|
||||
esp_ble_gatt_create_conn.is_aux = false;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&esp_ble_gatt_create_conn);
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
}
|
||||
break;
|
||||
@@ -177,14 +178,15 @@ The scan stop triggers an ``ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT`` event which is
|
||||
conn_device_b = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[1]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
|
||||
memcpy(&esp_ble_gatt_create_conn.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
esp_ble_gatt_create_conn.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
esp_ble_gatt_create_conn.is_direct = true;
|
||||
esp_ble_gatt_create_conn.is_aux = false;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&esp_ble_gatt_create_conn);
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
|
||||
}
|
||||
@@ -194,14 +196,15 @@ The scan stop triggers an ``ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT`` event which is
|
||||
conn_device_c = true;
|
||||
ESP_LOGI(GATTC_TAG, "Searched device %s", remote_device_name[2]);
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gatt_creat_conn_params_t esp_ble_gatt_create_conn;
|
||||
memcpy(&esp_ble_gatt_create_conn.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
esp_ble_gatt_create_conn.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
esp_ble_gatt_create_conn.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
esp_ble_gatt_create_conn.is_direct = true;
|
||||
esp_ble_gatt_create_conn.is_aux = false;
|
||||
esp_ble_gatt_creat_conn_params_t creat_conn_params = {0};
|
||||
memcpy(&creat_conn_params.remote_bda, scan_result->scan_rst.bda, ESP_BD_ADDR_LEN);
|
||||
creat_conn_params.remote_addr_type = scan_result->scan_rst.ble_addr_type;
|
||||
creat_conn_params.own_addr_type = BLE_ADDR_TYPE_PUBLIC;
|
||||
creat_conn_params.is_direct = true;
|
||||
creat_conn_params.is_aux = false;
|
||||
creat_conn_params.phy_mask = 0x0;
|
||||
esp_ble_gattc_enh_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if,
|
||||
&esp_ble_gatt_create_conn);
|
||||
&creat_conn_params);
|
||||
Isconnecting = true;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user