Unify command recognition for PhysicalDevice and DebugPort#73
Open
Unify command recognition for PhysicalDevice and DebugPort#73
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DebugPortbugs (endpoint indexing, reentrant locking) and add multi-endpoint supportTableDrivenDebugPortfor declarative mock device creation driven by Command objectsmatches(),extractParams(),formatResponse()toCommand/TextCommand/DataCommandso the same objects define both client send protocol and debug port recognitionBinaryCommandEntry/TextCommandEntrydataclasses — replaced by a single polymorphic loop over Command objects(?P<name>...)regex groups forTextCommand,requestFields/responseFieldsforDataCommand— params become dicts instead of positional tuplescommandsdicts toSutterDeviceandIntellidriveDeviceusing named parameters throughoutIntellidriveDevice(9 tests exercising init, home, move, orientation, status flags)Test plan
testCommandRecognition.py): matches, extractParams, formatResponse for positional and named parameterstestTableDrivenDebugPort.pytests pass with rewritten fixtures🤖 Generated with Claude Code