Move headers and add string name to discovery response

This commit is contained in:
2026-09-18 14:07:18 -05:00
parent f85dee5d7a
commit 4fc4eb99ea
8 changed files with 74 additions and 33 deletions
+28 -1
View File
@@ -1,6 +1,8 @@
#include "bbnow_priv.hpp"
#include "bbnow/priv.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <esp_log.h>
const static char TAG[] = "bbnow_priv";
@@ -105,6 +107,22 @@ size_t BBNowPrivPacket::serialize_into(
buf.push_back((expantion_type >> 8) & 0xFF);
buf.push_back((expantion_type >> 0) & 0xFF);
// Push the device name, NUL-padded to the fixed field width.
// Longer names are truncated to `EXPANDER_DEVICE_NAME_MAX_LEN`.
const size_t name_len = std::min(
data.name.size(),
static_cast<size_t>(EXPANDER_DEVICE_NAME_MAX_LEN)
);
buf.insert(
buf.end(), data.name.begin(), data.name.begin() + name_len
);
buf.insert(
buf.end(),
EXPANDER_DEVICE_NAME_MAX_LEN - name_len,
'\0'
);
break;
}
@@ -248,6 +266,15 @@ BBNowPrivPacket::deserialize(
return std::nullopt;
}
// Read the NUL-padded device name.
data.name.assign(
bytes.begin() + 6,
bytes.begin() + 6 + EXPANDER_DEVICE_NAME_MAX_LEN
);
data.name.resize(
strnlen(data.name.data(), EXPANDER_DEVICE_NAME_MAX_LEN)
);
packet.packet_data = std::move(data);
break;
}