Move headers and add string name to discovery response
This commit is contained in:
+15
-8
@@ -1,4 +1,4 @@
|
||||
#include "bbnow_driver.hpp"
|
||||
#include "bbnow/driver.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_now.h"
|
||||
@@ -25,17 +25,17 @@ struct ReceivedPacket {
|
||||
QueueHandle_t pub_queue = nullptr;
|
||||
QueueHandle_t priv_queue = nullptr;
|
||||
|
||||
constexpr BBNowDriver::MacAddress BROADCAST_MAC =
|
||||
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
|
||||
constexpr bool is_broadcast(const BBNowDriver::MacAddress &mac) {
|
||||
return mac == BBNowDriver::MacAddress{0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
return mac == BROADCAST_MAC;
|
||||
}
|
||||
|
||||
constexpr bool is_zero(const BBNowDriver::MacAddress &mac) {
|
||||
return mac == BBNowDriver::MacAddress{};
|
||||
}
|
||||
|
||||
constexpr BBNowDriver::MacAddress BROADCAST_MAC = {0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff};
|
||||
|
||||
bool is_broadcast(const uint8_t *mac) {
|
||||
return mac != nullptr &&
|
||||
std::memcmp(mac, BROADCAST_MAC.data(), BROADCAST_MAC.size()) == 0;
|
||||
@@ -286,8 +286,11 @@ size_t BBNowDriver::send_discovery(BlkBoxExpantion type) {
|
||||
return send_pub(packet) == ESP_OK ? size : 0;
|
||||
}
|
||||
|
||||
esp_err_t BBNowDriver::pair_expander(BlkBoxExpantion type,
|
||||
const MacAddress &mac) {
|
||||
esp_err_t BBNowDriver::pair_expander(
|
||||
BlkBoxExpantion type,
|
||||
const MacAddress &mac,
|
||||
std::string name
|
||||
) {
|
||||
if (!initialized_) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
@@ -298,6 +301,10 @@ esp_err_t BBNowDriver::pair_expander(BlkBoxExpantion type,
|
||||
for (auto &expander : paired_expanders) {
|
||||
if (expander.mac == mac) {
|
||||
expander.type = type;
|
||||
// Preserve a stored name when re-pairing with an empty one.
|
||||
if (!name.empty()) {
|
||||
expander.name = std::move(name);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
}
|
||||
@@ -315,7 +322,7 @@ esp_err_t BBNowDriver::pair_expander(BlkBoxExpantion type,
|
||||
|
||||
paired_expanders.push_back(PairedExpander{
|
||||
.mac = mac,
|
||||
.name = {},
|
||||
.name = std::move(name),
|
||||
.type = type,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user