1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-15 01:32:19 +01:00
This commit is contained in:
J. Nick Koston
2025-06-11 13:03:50 -05:00
parent c6957c08bc
commit 55ee0b116d
3 changed files with 8 additions and 5 deletions

View File

@@ -338,11 +338,12 @@ void ESP32BLE::loop() {
gap_event == ESP_GAP_BLE_SCAN_START_COMPLETE_EVT ||
gap_event == ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT) {
// All three scan complete events have the same structure with just status
// Cast is safe because all three ESP-IDF event structures are identical with just status field
// The scan_complete struct already contains our copy of the status (copied in BLEEvent constructor)
// The scan_complete struct matches ESP-IDF's layout exactly, so this reinterpret_cast is safe
// The struct already contains our copy of the status (copied in BLEEvent constructor)
ESP_LOGV(TAG, "gap_event_handler - %d", gap_event);
for (auto *gap_handler : this->gap_event_handlers_) {
gap_handler->gap_event_handler(gap_event, (esp_ble_gap_cb_param_t *) &ble_event->event_.gap.scan_complete);
gap_handler->gap_event_handler(
gap_event, reinterpret_cast<esp_ble_gap_cb_param_t *>(&ble_event->event_.gap.scan_complete));
}
}
break;

View File

@@ -157,7 +157,9 @@ class BLEEvent {
esp_gap_ble_cb_event_t gap_event;
union {
BLEScanResult scan_result; // 73 bytes
struct {
// This struct matches ESP-IDF's scan complete event structures
// All three (scan_param_cmpl, scan_start_cmpl, scan_stop_cmpl) have identical layout
struct ble_scan_complete_evt_param {
esp_bt_status_t status;
} scan_complete; // 1 byte
};

View File

@@ -8,7 +8,7 @@ namespace esphome {
namespace esp32_ble {
// Structure for BLE scan results - only fields we actually use
struct BLEScanResult {
struct __attribute__((packed)) BLEScanResult {
esp_bd_addr_t bda;
uint8_t ble_addr_type;
int8_t rssi;