Move headers and add string name to discovery response
This commit is contained in:
+28
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user