Skip to content

Unify command recognition for PhysicalDevice and DebugPort#73

Open
dccote wants to merge 9 commits intomasterfrom
table-driven-debug-port
Open

Unify command recognition for PhysicalDevice and DebugPort#73
dccote wants to merge 9 commits intomasterfrom
table-driven-debug-port

Conversation

@dccote
Copy link
Copy Markdown
Collaborator

@dccote dccote commented Mar 1, 2026

Summary

  • Fix DebugPort bugs (endpoint indexing, reentrant locking) and add multi-endpoint support
  • Add TableDrivenDebugPort for declarative mock device creation driven by Command objects
  • Add matches(), extractParams(), formatResponse() to Command/TextCommand/DataCommand so the same objects define both client send protocol and debug port recognition
  • Remove BinaryCommandEntry/TextCommandEntry dataclasses — replaced by a single polymorphic loop over Command objects
  • Support named parameters: (?P<name>...) regex groups for TextCommand, requestFields/responseFields for DataCommand — params become dicts instead of positional tuples
  • Add class-level commands dicts to SutterDevice and IntellidriveDevice using named parameters throughout
  • Add debug-mode tests for IntellidriveDevice (9 tests exercising init, home, move, orientation, status flags)

Test plan

  • 31 unit tests for command recognition (testCommandRecognition.py): matches, extractParams, formatResponse for positional and named parameters
  • 12 testTableDrivenDebugPort.py tests pass with rewritten fixtures
  • 7 Sutter debug serial port tests pass
  • 7 Sutter device tests pass
  • 9 new Intellidrive debug device tests pass
  • Full test suite: 253 passed, 248 skipped, 0 failures

🤖 Generated with Claude Code

dccote and others added 3 commits March 1, 2026 16:15
Fix flush() writing to nonexistent attribute, fix endPointIndex unbound
when endPoint is not None, add numberOfEndPoints parameter for USB
devices, add defaultTimeout attribute, remove broken DebugDataCommand.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace manual if/elif byte-parsing in debug ports with a table-driven
approach: declare command entries (binary or text) and implement only
device logic in process_command(). Migrate Sutter's DebugSerialPort,
create Intellidrive's missing DebugSerialPort, and add 12 new tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ck sides

Add matches(), extractParams(), formatResponse() to Command/TextCommand/DataCommand
so the same objects define both the client protocol and debug port recognition.
Remove BinaryCommandEntry/TextCommandEntry dataclasses from debugport.py, replacing
them with a single polymorphic loop over Command objects in TableDrivenDebugPort.
Update SutterDevice and IntellidriveDevice to use class-level commands dicts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dccote dccote changed the title Add TableDrivenDebugPort for declarative mock devices Unify command recognition for PhysicalDevice and DebugPort Mar 1, 2026
dccote and others added 6 commits March 1, 2026 17:37
Add TestIntellidriveDebugDevice with 9 tests exercising init, home, move,
orientation, register setup, and status flags without hardware connected.
Set terminator to b'\r' on DebugSerialPort so readString stops correctly
on carriage-return-terminated responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TextCommand.extractParams() now returns a dict when the matchPattern uses
named groups (?P<name>...), and formatResponse() accepts dicts for named
template parameters. Anonymous groups and positional tuples still work.

Add class and method docstrings to TableDrivenDebugPort with examples
showing named parameters for self-documenting command definitions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use (?P<register>...), (?P<value>...), (?P<mode>...) in matchPatterns
and {register}, {value}, {mode} in text/responseTemplate fields.
process_command now uses params["register"] instead of params[0].

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add requestFields and responseFields to DataCommand, mapping struct
fields to names so extractParams returns a dict and formatResponse
accepts a dict. Sutter process_command now uses params['x'], params['y'],
params['z'] and returns {'header': ..., 'x': ..., 'y': ..., 'z': ...,
'terminator': ...}.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document the module, all four classes (Command, TextCommand,
MultilineTextCommand, DataCommand), and their key methods. Covers
both the send side and recognition side roles, with parameter
descriptions and examples.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Every PhysicalDevice defines a commands dict that serves both sides:
sending commands to real hardware and creating mock debug ports that
receive those same commands and reply in the correct format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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