Skip to content

Binary wire protocol (v1) as the default host stream - #2

Merged
ShivtejG236 merged 2 commits into
mainfrom
feat/binary-wire-protocol
Nov 14, 2026
Merged

ShivtejG236 merged 2 commits into
mainfrom
feat/binary-wire-protocol

Conversation

@ShivtejG236

@ShivtejG236 ShivtejG236 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Step 2 of the plan: the host stream becomes a binary protocol.

Why

One CSV row is about 177 bytes. At 500 Hz that is 88.5 kB/s on a link that carries 92.16 kB/s, so the UART was about 96 % full. A binary sample frame is at most 103 bytes (about 56 % of the link).

What changes

  • include/wire.h: protocol v1. COBS(type | body | crc16) 0x00, CRC-16/CCITT-FALSE, little-endian. Header-only with no Arduino dependencies, so the same code runs in host tests.
  • src/transport.cpp: all host output behind transport_*(). main.cpp no longer touches Serial.
  • Frames: HELLO (board, firmware version, git revision, rates, detected sensors; at boot and every 2 s), SAMPLE (98-byte struct with a sequence number), STATUS (ring-buffer drops and samples sent, every second), LOG (the old # ... messages).
  • esp32dev-csv environment keeps the original CSV stream for pio device monitor.
  • scripts/version.py stamps the build with the git revision.
  • docs/wire-protocol.md: the specification. README updated.

Testing

  • tools/host/test_wire.cpp (CRC check value, COBS round trips for every body length, no stray zero bytes, frame size) passes locally and runs in CI.
  • The golden stream from tools/host/wire_dump.cpp decodes correctly with an independent Python decoder; the data-pipeline PR tests against it.
  • Not tested on hardware. I cannot flash a board, so the firmware build in this PR's CI is the only check of the ESP32 side.

Needs you

Flash this and log one session with the data-pipeline PR's logger, then compare imu_hz with the 415 Hz in the README's sample metadata. That number decides what the README should claim.

Merge together with the data-pipeline PR: the old logger cannot read the binary stream.

One CSV row is about 177 bytes, which is 96% of the 921600-baud link at
500 Hz. Samples are now sent as COBS-framed, CRC-16 checked binary frames
of at most 103 bytes (about 56% of the link) with a sequence number.

- include/wire.h: protocol v1 framing, header-only and Arduino-free
- src/transport.cpp: host output behind a small interface; the CSV stream
  stays available as the esp32dev-csv environment
- HELLO frame (board, version, git revision, rates, sensors) at boot and
  every 2 s; STATUS frame every second
- tools/host: protocol tests run in CI, plus the golden stream generator
  used by the data-pipeline decoder tests
- docs/wire-protocol.md: specification
Boot ROM output would otherwise be glued onto the first frame and cost it.
@ShivtejG236
ShivtejG236 added this pull request to stack #5 November 14, 2026 01:41
@ShivtejG236
ShivtejG236 merged commit 51a20f7 into main Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant