[bthome] Fix compilation errors and enhance StaticVector

- Add StaticVector::clear() method for resetting container
- Add StaticVector::push_back(T&&) for move semantics support (unique_ptr)
- Use esp_bt_dev_get_address() instead of esp_read_mac for BLE MAC
- Include esp_bt_device.h for Bluetooth device functions

Fixes compilation errors with StaticVector clear() and unique_ptr push_back,
and uses correct API for retrieving Bluetooth MAC address.
This commit is contained in:
Claude
2025-11-18 01:08:37 +00:00
parent 26a4379c34
commit 85abff84c6
2 changed files with 12 additions and 3 deletions
+3 -3
View File
@@ -6,6 +6,7 @@
#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
#include <esp_bt.h>
#endif
#include <esp_bt_device.h>
#include <esp_bt_main.h>
#include <esp_gap_ble_api.h>
#include <freertos/FreeRTOS.h>
@@ -460,9 +461,8 @@ bool BTHome::encrypt_payload_(const uint8_t *plaintext, size_t plaintext_len, ui
return false;
}
// Get MAC address
uint8_t mac[6];
esp_read_mac(mac, ESP_MAC_BT);
// Get Bluetooth MAC address
const uint8_t *mac = esp_bt_dev_get_address();
// Build nonce according to BTHome spec:
// MAC (6 bytes) + UUID (2 bytes) + device info (1 byte) + counter (4 bytes) = 13 bytes
+9
View File
@@ -149,6 +149,13 @@ template<typename T, size_t N> class StaticVector {
}
}
// Move version for types like unique_ptr
void push_back(T &&value) {
if (count_ < N) {
data_[count_++] = std::move(value);
}
}
// Return reference to next element and increment count (with bounds checking)
T &emplace_next() {
if (count_ >= N) {
@@ -159,6 +166,8 @@ template<typename T, size_t N> class StaticVector {
return data_[count_++];
}
void clear() { count_ = 0; }
size_t size() const { return count_; }
bool empty() const { return count_ == 0; }