启用 BLE 5.0 2M PHY 图传加速 + 移除未使用的 BluFi 组件 + BLE 断连内存泄漏修复
1、dzbj_ble.c 新增 BLE 5.0 2M PHY 请求(连接时自动协商,不支持则回退 1M); 2、dzbj_ble.c 新增 PHY 更新事件日志(tx_phy/rx_phy: 1=1M, 2=2M, 3=Coded); 3、dzbj_ble.c 断连时清理未完成的图片传输状态,释放 img_data/filepath/file_img 防止内存泄漏; 4、移除未使用的 BluFi 组件依赖(Kconfig select、编译检查、sdkconfig),解除与 BLE 5.0 的兼容冲突; 5、sdkconfig.defaults 及生产环境配置统一启用 BLE 5.0 + 保留 BLE 4.2 legacy advertising 兼容;
This commit is contained in:
parent
dbdd304905
commit
ba9f5b9aeb
@ -354,10 +354,9 @@ menu "蓝牙配网 (Bluetooth Provisioning)"
|
|||||||
default y
|
default y
|
||||||
select BT_ENABLED
|
select BT_ENABLED
|
||||||
select BLUEDROID_ENABLED
|
select BLUEDROID_ENABLED
|
||||||
select BT_BLUFI_ENABLE
|
|
||||||
help
|
help
|
||||||
启用蓝牙配网功能,允许通过蓝牙BLE连接配置WiFi网络。
|
启用蓝牙配网功能,允许通过蓝牙BLE连接配置WiFi网络。
|
||||||
需要ESP-IDF的蓝牙和BLUFI组件支持。
|
使用自定义 GATT Server 实现,不依赖 BluFi 组件。
|
||||||
|
|
||||||
config BLUETOOTH_PROVISIONING_SECURITY
|
config BLUETOOTH_PROVISIONING_SECURITY
|
||||||
bool "启用安全模式"
|
bool "启用安全模式"
|
||||||
|
|||||||
@ -196,9 +196,7 @@ extern "C" {
|
|||||||
#warning "蓝牙配网需要启用CONFIG_BLUEDROID_ENABLED"
|
#warning "蓝牙配网需要启用CONFIG_BLUEDROID_ENABLED"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_BT_BLUFI_ENABLE
|
// BluFi 组件未使用 — 配网采用自定义 GATT Server 实现
|
||||||
#warning "蓝牙配网需要启用CONFIG_BT_BLUFI_ENABLE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_ESP32_WIFI_ENABLED
|
#ifndef CONFIG_ESP32_WIFI_ENABLED
|
||||||
#warning "蓝牙配网需要启用WiFi功能"
|
#warning "蓝牙配网需要启用WiFi功能"
|
||||||
|
|||||||
@ -267,6 +267,13 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
|||||||
param->update_conn_params.latency,
|
param->update_conn_params.latency,
|
||||||
param->update_conn_params.timeout);
|
param->update_conn_params.timeout);
|
||||||
break;
|
break;
|
||||||
|
case ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT:
|
||||||
|
ESP_LOGI(CONN_TAG, "PHY update, status %d, tx_phy %d, rx_phy %d",
|
||||||
|
param->phy_update.status,
|
||||||
|
param->phy_update.tx_phy,
|
||||||
|
param->phy_update.rx_phy);
|
||||||
|
// tx_phy/rx_phy: 1=1M, 2=2M, 3=Coded
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -397,11 +404,27 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_
|
|||||||
ESP_LOGI(CONN_TAG, "Connected, conn_id %u, remote "ESP_BD_ADDR_STR"",
|
ESP_LOGI(CONN_TAG, "Connected, conn_id %u, remote "ESP_BD_ADDR_STR"",
|
||||||
param->connect.conn_id, ESP_BD_ADDR_HEX(param->connect.remote_bda));
|
param->connect.conn_id, ESP_BD_ADDR_HEX(param->connect.remote_bda));
|
||||||
esp_ble_gap_update_conn_params(&conn_params);
|
esp_ble_gap_update_conn_params(&conn_params);
|
||||||
|
// 请求 2M PHY 提升传输速度(对端不支持时自动回退 1M,不影响兼容性)
|
||||||
|
esp_ble_gap_set_preferred_phy(param->connect.remote_bda,
|
||||||
|
ESP_BLE_GAP_NO_PREFER_TRANSMIT_PHY | ESP_BLE_GAP_NO_PREFER_RECEIVE_PHY,
|
||||||
|
ESP_BLE_GAP_PHY_2M_PREF_MASK,
|
||||||
|
ESP_BLE_GAP_PHY_2M_PREF_MASK,
|
||||||
|
ESP_BLE_GAP_PHY_OPTIONS_NO_PREF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_GATTS_DISCONNECT_EVT:
|
case ESP_GATTS_DISCONNECT_EVT:
|
||||||
ESP_LOGI(CONN_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
ESP_LOGI(CONN_TAG, "Disconnected, remote "ESP_BD_ADDR_STR", reason 0x%02x",
|
||||||
ESP_BD_ADDR_HEX(param->disconnect.remote_bda), param->disconnect.reason);
|
ESP_BD_ADDR_HEX(param->disconnect.remote_bda), param->disconnect.reason);
|
||||||
|
// 清理未完成的传输,防止内存泄漏
|
||||||
|
if (SendStatus.isSend) {
|
||||||
|
ESP_LOGW(CONN_TAG, "传输中断,已接收 %d/%d 字节",
|
||||||
|
(int)SendStatus.port, (int)firstMeg.len);
|
||||||
|
SendStatus.isSend = false;
|
||||||
|
SendStatus.port = 0;
|
||||||
|
if (img_data) { free(img_data); img_data = NULL; }
|
||||||
|
if (filepath) { free(filepath); filepath = NULL; }
|
||||||
|
if (file_img) { fclose(file_img); file_img = NULL; }
|
||||||
|
}
|
||||||
esp_ble_gap_start_advertising(&adv_params);
|
esp_ble_gap_start_advertising(&adv_params);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -829,7 +829,7 @@ CONFIG_BT_BLUEDROID_ESP_COEX_VSC=y
|
|||||||
CONFIG_BT_BLE_ENABLED=y
|
CONFIG_BT_BLE_ENABLED=y
|
||||||
CONFIG_BT_GATTS_ENABLE=y
|
CONFIG_BT_GATTS_ENABLE=y
|
||||||
# CONFIG_BT_GATTS_PPCP_CHAR_GAP is not set
|
# CONFIG_BT_GATTS_PPCP_CHAR_GAP is not set
|
||||||
CONFIG_BT_BLE_BLUFI_ENABLE=y
|
# CONFIG_BT_BLE_BLUFI_ENABLE is not set
|
||||||
CONFIG_BT_GATT_MAX_SR_PROFILES=8
|
CONFIG_BT_GATT_MAX_SR_PROFILES=8
|
||||||
CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100
|
CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100
|
||||||
# CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
|
# CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
|
||||||
@ -1032,7 +1032,12 @@ CONFIG_BT_SMP_MAX_BONDS=15
|
|||||||
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
|
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
|
||||||
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
|
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
|
||||||
CONFIG_BT_BLE_RPA_TIMEOUT=900
|
CONFIG_BT_BLE_RPA_TIMEOUT=900
|
||||||
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
|
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
|
||||||
|
CONFIG_BT_BLE_50_EXTEND_ADV_EN=y
|
||||||
|
CONFIG_BT_BLE_50_PERIODIC_ADV_EN=y
|
||||||
|
CONFIG_BT_BLE_50_EXTEND_SCAN_EN=y
|
||||||
|
CONFIG_BT_BLE_50_EXTEND_SYNC_EN=y
|
||||||
|
CONFIG_BT_BLE_50_DTM_TEST_EN=y
|
||||||
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||||
CONFIG_BT_BLE_42_DTM_TEST_EN=y
|
CONFIG_BT_BLE_42_DTM_TEST_EN=y
|
||||||
CONFIG_BT_BLE_42_ADV_EN=y
|
CONFIG_BT_BLE_42_ADV_EN=y
|
||||||
|
|||||||
@ -163,12 +163,13 @@ CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=n
|
|||||||
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
|
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
|
||||||
CONFIG_BT_RESERVE_DRAM=0x10000
|
CONFIG_BT_RESERVE_DRAM=0x10000
|
||||||
|
|
||||||
# BluFi Configuration
|
# BluFi 未被代码使用(两种模式均用自定义 GATT Server),关闭以兼容 BLE 5.0
|
||||||
CONFIG_BT_BLUFI_ENABLED=y
|
CONFIG_BT_BLUFI_ENABLED=n
|
||||||
CONFIG_BT_BLE_BLUFI_ENABLE=y
|
CONFIG_BT_BLE_BLUFI_ENABLE=n
|
||||||
# Disable BLE 5.0 features for BluFi compatibility
|
# BLE 5.0 启用 2M PHY 支持(图传速度翻倍)
|
||||||
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
|
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
|
||||||
CONFIG_BT_BLUFI_MAX_CONN=1
|
# 同时保留 BLE 4.2 legacy advertising(两种模式的广播和 GATT 都依赖)
|
||||||
|
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||||
|
|
||||||
# Bluetooth and WiFi Coexistence
|
# Bluetooth and WiFi Coexistence
|
||||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
|
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
|
||||||
|
|||||||
@ -151,12 +151,13 @@ CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=n
|
|||||||
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
|
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
|
||||||
CONFIG_BT_RESERVE_DRAM=0x10000
|
CONFIG_BT_RESERVE_DRAM=0x10000
|
||||||
|
|
||||||
# BluFi Configuration
|
# BluFi 未被代码使用(两种模式均用自定义 GATT Server),关闭以兼容 BLE 5.0
|
||||||
CONFIG_BT_BLUFI_ENABLED=y
|
CONFIG_BT_BLUFI_ENABLED=n
|
||||||
CONFIG_BT_BLE_BLUFI_ENABLE=y
|
CONFIG_BT_BLE_BLUFI_ENABLE=n
|
||||||
# Disable BLE 5.0 features for BluFi compatibility
|
# BLE 5.0 启用 2M PHY 支持(图传速度翻倍)
|
||||||
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
|
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=y
|
||||||
CONFIG_BT_BLUFI_MAX_CONN=1
|
# 同时保留 BLE 4.2 legacy advertising(两种模式的广播和 GATT 都依赖)
|
||||||
|
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
|
||||||
|
|
||||||
# Bluetooth and WiFi Coexistence
|
# Bluetooth and WiFi Coexistence
|
||||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
|
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user