10 const uint16_t head =
crc16be(frame, 8);
11 return crc16be(frame + HEADER_SIZE,
len - HEADER_SIZE, head);
26static constexpr uint16_t ONE_BYTE_IDS[] PROGMEM = {
27 0x0001, 0x0005, 0x000C, 0x000D, 0x000E, 0x0011, 0x0012, 0x0013, 0x0017, 0x001E, 0x0022, 0x0025, 0x0026, 0x0027,
28 0x002D, 0x0035, 0x005E, 0x0073, 0x0074, 0x00A4, 0x00C9, 0x00DF, 0x0148, 0x015E, 0x0173, 0x0224, 0x0225,
30static constexpr uint16_t FOUR_BYTE_IDS[] PROGMEM = {
31 0x0002, 0x0003, 0x003D, 0x0041, 0x0042, 0x005C, 0x0060, 0x0064, 0x0065,
32 0x0072, 0x0095, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x0221, 0x0222, 0x0227,
34static constexpr uint16_t COUNT_PREFIXED_IDS[]
PROGMEM = {0x0038, 0x0039};
35static constexpr uint16_t LENGTH_PREFIXED_IDS[]
PROGMEM = {0x00FA, 0x00FB, 0x0147, 0x0223};
37template<
size_t N>
static bool contains(
const uint16_t (&ids)[N], uint16_t
id) {
38 for (
const uint16_t &entry : ids) {
45static AttrKind attr_kind(uint16_t
id) {
46 if (contains(ONE_BYTE_IDS,
id))
48 if (contains(FOUR_BYTE_IDS,
id))
50 if (contains(COUNT_PREFIXED_IDS,
id))
52 if (contains(LENGTH_PREFIXED_IDS,
id))
60 const uint8_t *data = this->
data_;
62 size_t start = this->pos_ + 2;
73 if (start + 1 > this->
len_)
75 value_len = data[start++];
78 if (start + 2 > this->
len_)
88 if (start + value_len > this->
len_)
91 const uint8_t *v = data + start;
99 this->pos_ = start + value_len;
104 uint8_t class_2,
const uint8_t *body,
size_t len) {
105 const size_t total = HEADER_SIZE + 2 +
len;
106 out[0] = FRAME_START_1;
107 out[1] = FRAME_START_2;
113 out[LEN_POS] = total;
114 out[HEADER_SIZE] = class_1;
115 out[HEADER_SIZE + 1] = class_2;
117 std::memcpy(
out + HEADER_SIZE + 2, body,
len);
bool next()
Moves to the next attribute. Returns false at the end of the body or at an unknown ID.
std::vector< uint8_t > & out
const uint8_t STORE_YAML_DATA[] PROGMEM
The zstd YAML envelope generated by store_yaml, STORE_YAML_DATA_SIZE bytes in flash.
@ ATTR_KIND_LENGTH_PREFIXED
@ ATTR_KIND_COUNT_PREFIXED
size_t build_frame(uint8_t *out, uint8_t flags, uint8_t type, uint8_t seq, uint8_t ack, uint8_t class_1, uint8_t class_2, const uint8_t *body, size_t len)
Builds a frame into out, which must hold HEADER_SIZE + 2 + len bytes. Returns the frame length.
uint16_t frame_crc(const uint8_t *frame, size_t len)
CRC-16/XMODEM over a whole frame, skipping the two checksum bytes at offset 8.
uint16_t progmem_read_uint16(const uint16_t *addr)
uint16_t crc16be(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t poly, bool refin, bool refout)
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
constexpr uint8_t * put_be16(uint8_t *dst, uint16_t value)
Write the low 16, 24 or 32 bits of value to dst, most significant byte first (be) or least significan...
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.