gate: replace json with nanopb #8

Closed
opened 2026-06-18 20:00:38 +00:00 by joaj · 1 comment
Owner
No description provided.
Author
Owner

Implementation decisions (protocol migration JSON -> nanopb)

  • Wire format: single GateMessage proto with a oneof over trigger, heartbeat, log, log_start, log_line, log_end, ack, cmd. Timestamps stay uint64 Unix epoch microseconds; temperature-quirk fields (e.g. "yes" strings) become real proto types (bool/scalars). Normalization (heartbeat->keepalive, trigger->timekeeping) stays in the server marshalling layer, output dict shape unchanged.
  • Firmware: nanopb via nanopb/Nanopb PlatformIO lib (extra_script auto-generates .pb.c/.pb.h); copy of gate.proto in src/, canonical copy in libs/timekeeping_protocol/. Hand-rolled snprintf/strstr code in main.cpp, heartbeat.cpp, log.cpp, network.cpp replaced with pb_encode/pb_decode.
  • Framing: binary protobuf breaks newline framing (payloads can contain 0x0A), so both directions switch to 2-byte little-endian length prefix + payload. Affects firmware network_send/network_loop, server tcp_server.py read loop (-> readexactly(2) + readexactly(n)), and dump_runtime.py command writes.
  • Python decoding: betterproto - runtime dependency is betterproto (dataclass-style messages); generation uses protoc + the betterproto plugin (betterproto[compiler]). Generated module committed under libs/timekeeping_protocol/.
  • Compatibility: clean break, no version byte or dual-parse - gates and server are flashed/deployed together.
  • Sim & tests: testing_sim/backend.py ports to betterproto + framing; test_marshalling.py rewritten for the new pack/unpack; dispatch-level tests (dict-shaped) largely unchanged. Docs updated (README "TCP Protocol", MANUAL.md).
  • Verification: repo-root make check + pio run for the firmware envs.
**Implementation decisions (protocol migration JSON -> nanopb)** - **Wire format**: single `GateMessage` proto with a `oneof` over `trigger`, `heartbeat`, `log`, `log_start`, `log_line`, `log_end`, `ack`, `cmd`. Timestamps stay uint64 Unix epoch microseconds; temperature-quirk fields (e.g. "yes" strings) become real proto types (`bool`/scalars). Normalization (`heartbeat`->`keepalive`, `trigger`->`timekeeping`) stays in the server marshalling layer, output dict shape unchanged. - **Firmware**: nanopb via `nanopb/Nanopb` PlatformIO lib (extra_script auto-generates `.pb.c/.pb.h`); copy of `gate.proto` in `src/`, canonical copy in `libs/timekeeping_protocol/`. Hand-rolled `snprintf`/`strstr` code in `main.cpp`, `heartbeat.cpp`, `log.cpp`, `network.cpp` replaced with `pb_encode`/`pb_decode`. - **Framing**: binary protobuf breaks newline framing (payloads can contain `0x0A`), so both directions switch to **2-byte little-endian length prefix + payload**. Affects firmware `network_send`/`network_loop`, server `tcp_server.py` read loop (-> `readexactly(2)` + `readexactly(n)`), and `dump_runtime.py` command writes. - **Python decoding**: **betterproto** - runtime dependency is `betterproto` (dataclass-style messages); generation uses protoc + the betterproto plugin (`betterproto[compiler]`). Generated module committed under `libs/timekeeping_protocol/`. - **Compatibility**: clean break, no version byte or dual-parse - gates and server are flashed/deployed together. - **Sim & tests**: `testing_sim/backend.py` ports to betterproto + framing; `test_marshalling.py` rewritten for the new pack/unpack; dispatch-level tests (dict-shaped) largely unchanged. Docs updated (README "TCP Protocol", MANUAL.md). - Verification: repo-root `make check` + `pio run` for the firmware envs.
joaj closed this issue 2026-09-27 10:52:54 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fspt/timekeeping#8
No description provided.