mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 07:06:20 +00:00
Merge branch 'esp32-proxy-hub-scanner-state' into esp32-tracker-parser-cleanup
This commit is contained in:
@@ -154,12 +154,9 @@ class ESPBLEiBeacon {
|
||||
};
|
||||
|
||||
/// Pack a controller-order (LSB-first) MAC into the uint64 the API speaks.
|
||||
///
|
||||
/// The result is the printable-order value esp32 has always sent
|
||||
/// (esp32_ble::ble_addr_to_uint64), so both proxy paths agree on the wire.
|
||||
/// This takes the raw controller order delivered by BLEHub's raw-advertisement
|
||||
/// callback; ESPBTDevice::address_uint64() is the equivalent for an already
|
||||
/// parsed device, whose address is stored MSB-first.
|
||||
/// Trackers with LSB-native SDKs call this at the emit site before filling
|
||||
/// RawAdvertisement::address; ESPBTDevice::address_uint64() is the equivalent
|
||||
/// for an already parsed device, whose address is stored MSB-first.
|
||||
inline uint64_t mac_lsb_first_to_uint64(const uint8_t *mac) {
|
||||
uint64_t addr = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "esphome/core/macros.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
@@ -90,7 +91,7 @@ void BluetoothProxy::on_raw_advertisement_(const ble_device_base::RawAdvertiseme
|
||||
|
||||
this->response_.advertisements_len++;
|
||||
|
||||
ESP_LOGV(TAG, "Queuing raw packet from %012llX, length %d. RSSI: %d dB", raw.address, length, raw.rssi);
|
||||
ESP_LOGV(TAG, "Queuing raw packet from %012" PRIX64 ", length %d. RSSI: %d dB", raw.address, length, raw.rssi);
|
||||
|
||||
// Flush if we have reached BLUETOOTH_PROXY_ADVERTISEMENT_BATCH_SIZE
|
||||
if (this->response_.advertisements_len >= BLUETOOTH_PROXY_ADVERTISEMENT_BATCH_SIZE) {
|
||||
@@ -460,13 +461,13 @@ void BluetoothProxy::bluetooth_set_connection_params(const api::BluetoothSetConn
|
||||
#ifdef USE_ESP32
|
||||
|
||||
void BluetoothProxy::bluetooth_scanner_set_mode(bool active) {
|
||||
if (this->parent_->get_scan_active() == active) {
|
||||
if (this->parent_()->get_scan_active() == active) {
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, "Setting scanner mode to %s", active ? "active" : "passive");
|
||||
this->parent_->set_scan_active(active);
|
||||
this->parent_->stop_scan();
|
||||
this->parent_->set_scan_continuous(
|
||||
this->parent_()->set_scan_active(active);
|
||||
this->parent_()->stop_scan();
|
||||
this->parent_()->set_scan_continuous(
|
||||
true); // Set this to true to automatically start scanning again when it has cleaned up.
|
||||
}
|
||||
|
||||
@@ -613,7 +614,7 @@ void BluetoothProxy::subscribe_api_connection(api::APIConnection *api_connection
|
||||
}
|
||||
this->api_connection_ = api_connection;
|
||||
#ifdef USE_ESP32
|
||||
this->send_bluetooth_scanner_state_(static_cast<ble_device_base::ScannerState>(this->parent_->get_scanner_state()));
|
||||
this->send_bluetooth_scanner_state_(static_cast<ble_device_base::ScannerState>(this->parent_()->get_scanner_state()));
|
||||
#else
|
||||
this->send_polled_scanner_state_();
|
||||
#endif
|
||||
|
||||
@@ -79,12 +79,9 @@ class BluetoothProxy final : public Component {
|
||||
public:
|
||||
BluetoothProxy();
|
||||
#ifdef USE_ESP32
|
||||
// Advertisements arrive through the hub's raw callback; the tracker is
|
||||
// still typed for the esp32-only scan-mode and scanner-state calls.
|
||||
void set_parent(esp32_ble_tracker::ESP32BLETracker *parent) {
|
||||
this->parent_ = parent;
|
||||
this->hub_ = parent;
|
||||
}
|
||||
// Advertisements arrive through the hub's raw callback; parent_() below
|
||||
// recovers the tracker type for the esp32-only scan-mode calls.
|
||||
void set_parent(esp32_ble_tracker::ESP32BLETracker *parent) { this->hub_ = parent; }
|
||||
#endif // USE_ESP32
|
||||
void dump_config() override;
|
||||
void setup() override;
|
||||
@@ -269,7 +266,11 @@ class BluetoothProxy final : public Component {
|
||||
#endif
|
||||
ble_device_base::BLEHub *hub_{nullptr};
|
||||
#ifdef USE_ESP32
|
||||
esp32_ble_tracker::ESP32BLETracker *parent_{nullptr};
|
||||
// set_parent() is the only writer of hub_ on esp32, so the downcast is
|
||||
// exact; ESP32BLETracker derives from BLEHub non-virtually.
|
||||
esp32_ble_tracker::ESP32BLETracker *parent_() {
|
||||
return static_cast<esp32_ble_tracker::ESP32BLETracker *>(this->hub_);
|
||||
}
|
||||
#endif
|
||||
|
||||
// BLE advertisement batching
|
||||
|
||||
@@ -46,7 +46,7 @@ struct CapturingSubscriber {
|
||||
}
|
||||
};
|
||||
|
||||
// Device AA:BB:CC:DD:EE:FF — controller order delivers FF first.
|
||||
// Device AA:BB:CC:DD:EE:FF, packed the way the API speaks it.
|
||||
constexpr uint64_t TEST_ADDRESS = 0xAABBCCDDEEFFULL;
|
||||
const uint8_t ADV_DATA[4] = {0x02, 0x01, 0x06, 0x00};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user