-
Notifications
You must be signed in to change notification settings - Fork 223
Begin update to new protocol #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's Guide by SourceryThis PR updates the communication protocol to use a new header-based format for commands and responses. It introduces a new Sequence diagram for get_version with new protocolsequenceDiagram
participant SL as ScienceLab
participant C as Connection
SL->>C: get_version()
C->>C: exchange(COMMON + GET_VERSION)
C->>C: pack header (cmd, len(data))
C->>C: write(header + data)
C->>C: read(header.size)
C->>C: unpack header (status, response_size)
alt status != 0
C-->>SL: raise Exception(status)
else
C->>C: read(response_size)
C-->>SL: version
end
SL-->>SL: version.rstrip(b"\x00").decode("utf-8")
SL-->>SL: return version
Sequence diagram for get_firmware_version with new protocolsequenceDiagram
participant SL as ScienceLab
participant C as Connection
SL->>C: get_firmware_version()
C->>C: exchange(COMMON + GET_FW_VERSION)
C->>C: pack header (cmd, len(data))
C->>C: write(header + data)
C->>C: read(header.size)
C->>C: unpack header (status, response_size)
alt status != 0
C-->>SL: raise Exception(status)
else
C->>C: read(response_size)
C-->>SL: major, minor, patch
end
SL-->>SL: return FirmwareVersion(major, minor, patch)
Updated class diagram for ConnectionclassDiagram
class Connection {
+write(data: bytes) int
+exchange(cmd: bytes, data: bytes) bytes
+get_byte() int
+get_version() str
+get_firmware_version() FirmwareVersion
}
class FirmwareVersion {
+major: int
+minor: int
+patch: int
}
Connection -- FirmwareVersion: returns
Updated class diagram for ScienceLabclassDiagram
class ScienceLab {
-device: ConnectionHandler
+version: str
+logic_analyzer: LogicAnalyzer
+oscilloscope: Oscilloscope
+waveform_generator: WaveformGenerator
+datalogger: Datalogger
+multimeter: Multimeter
+power_source: PowerSource
+i2c: I2C
+spi: SPIMaster
+cap_meter: CapacitanceMeter
+res_meter: ResistanceMeter
+freq_counter: FrequencyCounter
+rgb_led(colors: List, output: str, order: str)
-_read_program_address(address: int)
}
ScienceLab -- ConnectionHandler: has a
ScienceLab -- LogicAnalyzer: has a
ScienceLab -- Oscilloscope: has a
ScienceLab -- WaveformGenerator: has a
ScienceLab -- Datalogger: has a
ScienceLab -- Multimeter: has a
ScienceLab -- PowerSource: has a
ScienceLab -- I2C: has a
ScienceLab -- SPIMaster: has a
ScienceLab -- CapacitanceMeter: has a
ScienceLab -- ResistanceMeter: has a
ScienceLab -- FrequencyCounter: has a
note for ScienceLab "version attribute added in constructor"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
I need this for FOSSASIA Summit workshop, so I'm merging it into a new 'develop' branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bessman - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a timeout to the
read
calls inexchange
to prevent indefinite blocking. - The removal of
send_byte
calls is good, but ensure all usages are replaced with the newexchange
method.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
||
Parameters | ||
---------- | ||
cmd : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Align cmd parameter type in docstring and implementation.
The docstring currently indicates that cmd is an int, whereas the implementation expects a bytes object (and unpacks it using CP.ShortInt.unpack). Consider updating the docstring so that it accurately reflects the required type.
cmd : int | |
cmd : bytes |
if status: | ||
raise Exception(status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Raise a more descriptive exception on status error.
Instead of raising a generic Exception with the status code, consider raising a custom exception or adding a more descriptive error message. This could aid in debugging and handling errors in client code.
This PR updates pslab-python to use the new protocol currently being worked on here: fossasia/pslab-firmware#180
The new protocol has two major changes from the old one:
This flowchart summarizes the new protocol:
Summary by Sourcery
Updates the communication protocol to use a new header-based format for commands and responses. This change involves modifying the structure of data transmission and reception, including the introduction of a header containing command codes, data sizes, and status codes. The update also includes changes to how version information is retrieved from the device.
New Features:
Enhancements: