Version 2 telemetry frames from the new radio modems
C++ · C++ · intermediate · modification
The new radio modems pad every datagram to a multiple of 16 bytes, so for their frames the payload no longer runs to the end of the datagram. Their firmware sends version 2 frames, whose header carries the payload length. `packet.hpp` documents the version 2 layout next to version 1. `packet.cpp` switches on the version byte to pick the header size and the payload length (version 1 keeps using the rest of the datagram, version 2 reads its length field and checks the padding) and then fills the `Packet` as before. `tests/packet_test.cpp` adds version 2 cases next to the existing version 1 ones.
Ground-station receiver for a drone fleet in C++20, standard library only, built with CMake (build files unchanged) by Apple clang 17 locally and GCC 13 in CI with `-Wall -Wextra -Wconversion` treated as errors. Single-threaded: one receive thread runs `Receiver::poll` (unchanged, not in the diff), which calls `recv` on the UDP socket into a member `std::array<std::byte, 512>` buffer reused for every datagram and passes `std::span(buffer.data(), n)` for the `n` bytes received; the modems' MTU is 256 bytes, so no datagram is truncated. An accepted `Packet` goes to the dispatcher, which relays telemetry payloads (`Packet::bytes()`) to the operators' dashboard and the flight log. Tests use the repo's existing helper `tests/check.hpp` (unchanged): `TEST(name)` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure without stopping, and `tests/check_main.cpp` runs every registered test and exits non-zero on any failure.
Requirements
- `telemetry::parse_packet` (existing) accepts version 2 datagrams from the new radio modems next to version 1 ones (the fleet mixes old and new drones). Version 2 layout: byte 0 is the version (2), byte 1 the message type, bytes 2-3 the sequence number and bytes 4-5 `payload_len`, both big-endian unsigned 16-bit, then `payload_len` payload bytes, then modem padding (0 to 15 bytes, so the datagram is a multiple of 16 bytes long) that is ignored.
- Version 1 is unchanged: a 4-byte header (version 1, type, big-endian sequence number) and the payload is every byte after it.
- A malformed datagram is rejected with `std::nullopt`, never partly parsed: one shorter than its version's header, an unknown version, a payload over `kMaxPayload` (240 bytes), a version 2 datagram that ends before the end of the payload its header declares, or a version 2 datagram whose length is not a multiple of 16 or that carries more than 15 bytes of padding.
- Datagrams are untrusted: the telemetry port accepts UDP from any host on the field network (this firmware generation has no link authentication), so every header field can hold any value.
- Unchanged: `Packet`, `kMaxPayload`, `Receiver::poll` and the dispatcher. The message type is passed through as is; the dispatcher drops types it does not know.
Files touched
- src/telemetry/packet.hpp
- src/telemetry/packet.cpp
- tests/packet_test.cpp