21 const uint8_t *
data()
const {
return this->
buf_.data(); }
26 this->
add_(0x01, &flags, 1);
29 if (appearance == 0 || this->
left_() <= 3)
37 if (this->
left_() <= 2)
39 const size_t fit = std::min(
len, this->
left_() - 2);
40 this->
add_(fit <
len ? 0x08 : 0x09,
reinterpret_cast<const uint8_t *
>(name), fit);
44 if (!
data.empty() && this->left_() > 2)
45 this->
add_(0xFF, data.data(), std::min(
data.size(), this->left_() - 2));
48 if (this->
left_() > 2)
49 this->
add_(0x0A,
reinterpret_cast<const uint8_t *
>(&dbm), 1);
55 if (this->
left_() < 18)
57 for (
const auto &uuid : uuids) {
58 if (uuid != skip &&
uuid_size(uuid) == 16) {
59 this->
add_(0x07, uuid.uuid128(), 16);
66 if (!
data.empty() && this->left_() >=
data.size() + 2)
67 this->
add_(0x16, data.data(),
data.size());
72 static constexpr uint8_t BASE[12] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00};
75 short_value = uuid.
uuid16();
77 short_value = uuid.
uuid32();
80 if (memcmp(
raw, BASE,
sizeof(BASE)) != 0)
86 return short_value <= 0xFFFF ? 2 : 4;
99 std::count_if(uuids.begin(), uuids.end(), [&](
const auto &u) { return u != skip && uuid_size(u) == size; });
102 size_t fit = std::min(
count, (this->
left_() - 2) / size);
104 this->
buf_[this->
len_++] = fit <
count ? partial_type : partial_type + 1;
105 for (
const auto &uuid : uuids) {
121 std::array<uint8_t, MAX_LEN>
buf_{};
A 31 byte advertising or scan response payload, packed in the order and with the fit rules of Bluedro...
std::array< uint8_t, MAX_LEN > buf_
void add_(uint8_t type, const uint8_t *value, size_t len)
static size_t uuid_size(const ESPBTUUID &uuid, uint32_t *value=nullptr)
Bluedroid's width for uuid: 2 or 4 (and its value) when it has a 16 or 32-bit form,...
void add_uuids(std::span< const ESPBTUUID > uuids, const ESPBTUUID &skip={})
16 and 32-bit lists (partial when they do not all fit), then the first 128-bit UUID; skip is left out...
static constexpr size_t MAX_LEN
void add_manufacturer_data(std::span< const uint8_t > data)
Truncated to what fits.
void add_tx_power(int8_t dbm)
void add_flags(uint8_t flags)
void add_appearance(uint16_t appearance)
void add_short_uuids_(std::span< const ESPBTUUID > uuids, const ESPBTUUID &skip, size_t size, uint8_t partial_type)
const uint8_t * data() const
void add_name(const char *name, size_t len)
Complete name, or the shortened name type with what fits.
void add_service_data(std::span< const uint8_t > data)
Raw service data element (its first bytes are the UUID); dropped whole when it does not fit.
bool is_set() const
True if a UUID has been configured (not default-constructed).
void build_adv_packets(const AdvContent &content, AdvPayload &adv, AdvPayload &rsp)
Split content between the advertising packet and the scan response.
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
constexpr uint8_t * put_le32(uint8_t *dst, uint32_t value)
constexpr uint8_t * put_le16(uint8_t *dst, uint16_t value)
What the services advertising carries. A set priority_uuid (also in uuids) gets the advertising packe...
std::span< const uint8_t > service_data
std::span< const uint8_t > manufacturer_data
std::span< const ESPBTUUID > uuids