Skip to content

fix(host): robust connect handshake + correct DTR reset sequence - #10

Merged
CameronBrooks11 merged 1 commit into
mainfrom
feat/connect-handshake
Jun 26, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
feat/connect-handshake

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Hardens the two hardware-boundary surfaces (the only parts of the MVP not yet hardware-validated), grounded in the Marlin 2.1.x source and printrun/OctoPrint conventions (research in working/serial-reset.md). Toward #4.

MarlinHost.connect()

Replaces "drain until quiet, then always report ready" with a real handshake:

  • Wait for Marlin's unconditional start boot line (MarlinCore.cpp:1223) as the positive ready signal, then drain the banner until quiet.
  • ok/temperature/position line → ready outright.
  • wait/busy keepalive → sign of life: ready if the banner was already seen, else break to the probe. (This is the fix for the review-found hang below.)
  • Active probe: if nothing decisive, send a framed M110 N0 up to connect_probes times and accept the ok — which also syncs line numbering on an already-running board.
  • Fail loud: raise HostError if the controller never responds, instead of silently reporting ready on a dead port.
  • Detects a fatal/halt line during boot.

SerialTransport.reset()

  • Printrun sequence — assert DTR, hold assert_hold, release — so the line is never left asserted (the previous code ended with dtr=True).
  • Stops flushing the input buffer, so connect() can match start.
  • Exposes dtr/rts/assert_hold knobs; RTS untouched by default.

Review gate

Independent adversarial review (verdict NEEDS-WORK → fixed) caught a real bug: an idle board emitting wait keepalives (NO_TIMEOUTS) every ~1s would spin Phase 1 forever (it only exited on silence) and never reach the probe — the exact already-running case the probe exists for. Fixed by treating keepalives as a sign of life, plus two regression tests (wait→probe, banner+wait→ready). Reviewer verified line-numbering, reset polarity, and halt handling correct.

Hardware

All logic is tested hardware-free (88 tests; FakeTransport / mocked pyserial). The board-specific timings remain knobs; the hardware-verification checklist is tracked in #4.

just check clean (ruff + pyright 0 errors) · just test 88 passed.

Harden the two surfaces that drive a real controller, grounded in the
Marlin 2.1.x source and printrun/OctoPrint conventions (research in
working/serial-reset.md):

connect():
- Wait for Marlin's unconditional `start` boot line as the positive
  ready signal, then drain the banner until quiet.
- Fall back to an active framed `M110 N0` probe (accepting the `ok`,
  which also syncs line numbering) for an already-running board, one
  that ignored a DTR reset, or a missed `start`.
- Raise HostError when the controller never responds, instead of the
  old "drain until quiet" silently reporting ready on a dead port.
- Detect a fatal/halt line during boot.

SerialTransport.reset():
- Use the printrun sequence (assert DTR, hold, release) so the line is
  never left asserted (the previous toggle ended with dtr=True).
- Stop flushing the input buffer so connect() can match `start`.
- Expose dtr/rts/assert_hold knobs; RTS untouched by default.

All logic is tested hardware-free via FakeTransport / mocked pyserial.
The board-specific timings remain knobs; hardware verification is
tracked in #4.
@CameronBrooks11
CameronBrooks11 merged commit c0cd52e into main Jun 26, 2026
5 checks passed
@CameronBrooks11
CameronBrooks11 deleted the feat/connect-handshake branch June 26, 2026 14:07
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