feat: surface console printf; unify console + sensor command transports - #97
feat: surface console printf; unify console + sensor command transports#97boringethan wants to merge 4 commits into
Conversation
The console firmware can now mirror printf() to its USB CDC link as unsolicited OW_DATA/OW_CMD_ECHO (id=0) packets (DEBUG_FLAG_USB_PRINTF). Those packets share the link with command responses, so the host must demux them or the synchronous console reader would mistake a log packet for a response. - Add omotion/framing.py: shared frame extraction (extract_frame) and log-packet demux (is_log_packet / emit_log_packet) — the one place both transports parse the wire protocol and surface firmware printf lines. - Rework MotionUart.read_packet to reassemble frames and skip/surface log packets, keeping a persistent RX buffer so fragments and trailing bytes aren't lost; clear_buffer drops it too. - Refactor CommInterface._process_responses onto the shared helpers (behavior-preserving; removes the duplicated demux and dead constants). - Add MotionConsole.set_debug_flags / get_debug_flags / enable_usb_printf, mirroring MotionSensor. - Add pure-software tests for framing and the console printf demux. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The console's serial link (MotionUart) was synchronous — it only read the port while a command was in flight. That can't tolerate the unsolicited firmware printf packets this branch added: they collided with command responses, got purged by clear_buffer, and (with the telemetry poller as a second caller) raced into 20s lock-holding stalls. Extract the sensor's proven async engine into a shared PacketTransport base (reader thread + frame dispatch via omotion.framing + id-matched send, with prompt transport-down cancellation). CommInterface (USB bulk) and MotionUart (serial VCP) now both subclass it; the console gains a continuous reader, so printf packets are surfaced by the dispatcher and never collide with responses. Net -228 lines, and the framing/demux logic lives in one place. Console-only: pace commands >=15ms apart. The console firmware re-arms its CDC OUT reception only after sending each response, so a command arriving in the ~10ms window before that is silently dropped; the old slow synchronous reader paced this implicitly. Pacing (vs retrying) avoids re-applying non-idempotent commands. (The sensor's bulk endpoint has no such window.) Verified on hardware: console printf surfaces to the host with no stalls, console comms + telemetry healthy, both sensors ping/echo OK. Pure-software suite green (CommInterface transport-down contract preserved). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-only Both transports run the async PacketTransport engine, so the synchronous send path (and the async_mode flag) was dead in production: MotionComposite always built CommInterface async. Remove the flag, the sync send branch, and receive(); simplify PacketTransport (always one response queue + dispatch thread) and update MotionComposite and the transport-down test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…p front The console firmware (openmotion-console-fw) now snapshots the received frame and re-arms CDC reception before processing, so it no longer drops rapid back-to-back commands. The ~15 ms host pacing workaround is no longer needed: remove MotionUart's throttle and the PacketTransport _pace_before_send / _mark_send_done hooks. NOTE: this SDK now assumes console firmware with the CDC RX re-arm fix; against older firmware, rapid back-to-back console commands could be dropped. Verified on hardware: 40 rapid pings, 0 failures, no pacing; printf mirroring and both sensors healthy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Heads-up before this rebases — this branch would silently re-land a bug that is being fixed on
Fix landing on If a later revision of this branch moves the raw write into Separately and independently of the above: this branch reverts |
Refs #122.
What
Host-side support for console firmware printf-over-USB, plus a transport cleanup: the console and sensor command links now share one async engine.
Commits
omotion/framing.py(shared frame extraction + log-packet demux);MotionConsole.set_debug_flags/get_debug_flags/enable_usb_printf; firmwareprintfpackets (OW_DATA/OW_CMD_ECHO/id=0) are demuxed from responses and surfaced via the logger.omotion/packet_transport.py::PacketTransport(reader thread + frame dispatch + id-matched send + transport-down cancellation).CommInterface(USB bulk) andMotionUart(serial VCP) both subclass it; the console gains a continuous reader so printf packets never collide with responses. Net −228 lines.Compatibility
This SDK assumes console firmware with the CDC-RX re-arm fix (OpenwaterHealth/openmotion-console-fw#39). Against older console firmware, rapid back-to-back console commands could be dropped.
Testing
CommInterfacetransport-down contract preserved.🤖 Generated with Claude Code