Skip to content

Stabilization of frame communication layer. - #27

Merged
drebbe-intrepid merged 14 commits into
masterfrom
stabilize26-wip
Jan 26, 2026
Merged

Stabilization of frame communication layer.#27
drebbe-intrepid merged 14 commits into
masterfrom
stabilize26-wip

Conversation

@drebbe-intrepid

Copy link
Copy Markdown
Contributor

This update provides much needed fixes to the communication layer, especially around binary data transfers.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR stabilizes the serial framing/communication layer (with emphasis on mixed binary + framed traffic) by introducing a dedicated frame parsing state machine and expanding test coverage around frame boundary detection and file transfers.

Changes:

  • Replaced ad-hoc serial receive parsing in SerialPort with a new FrameParser state machine.
  • Extended framing helpers (ResponseFrame) with start/end-of-frame detection/validation and added corresponding tests.
  • Updated hardware/file-transfer tests and examples to use FreeWili as a context manager; added stress-style get_file test coverage and a binary fixture.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
freewili/serialport.py Switches RX handling to FrameParser; adds verbose logging/TRACE support and adjusts send timing.
freewili/frame_parser.py New frame parsing state machine to separate response frames vs. binary data.
freewili/framing.py Adds start/end-of-frame detection & validation helpers used by the parser.
freewili/safe_reponse_frame_dict.py Extracts thread-safe response-frame storage into its own module.
freewili/fw_serial.py Improves response-frame timeout error context; tightens file download write logic.
tests/test_frame_parser.py Adds unit tests for FrameParser behavior across framed and binary data.
tests/test_framing.py Adds tests for framing start/end validation helpers.
tests/test_get_file.py Refactors context usage; adds multi-download stress test and improves callback test.
tests/test_fw.py / tests/test_hw.py / tests/test_hw_io.py / tests/test_i2c.py Refactors tests to use context manager patterns for device lifecycle.
tests/assets/invalid.fwi Adds binary fixture for file transfer stress testing.
examples/*.py Refactors examples to use fw = ...; with fw: pattern.
.vscode/launch.json Adds a debug configuration for running pytest with logging enabled.
Comments suppressed due to low confidence (1)

freewili/serialport.py:275

  • The serial port is now opened with exclusive=False. This can allow multiple processes/threads to open the same port simultaneously, which can cause data corruption or hard-to-debug IO errors. If the previous exclusive=True was intentional, consider keeping it as the default and making exclusivity configurable per SerialPort instance (or documenting why exclusivity must be disabled).
                            self.logger.debug(f"[{time.time() - start_time:.3f}] Opening {self._port}...")
                            serial_port = Serial(
                                self._port,
                                baudrate=self._baudrate,
                                timeout=0.001,
                                exclusive=False,
                                rtscts=False,
                                xonxoff=False,
                                dsrdtr=False,
                            )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_i2c.py Outdated
Comment thread freewili/frame_parser.py
Comment thread freewili/frame_parser.py
Comment thread tests/test_i2c.py Outdated
Comment thread tests/test_frame_parser.py Outdated
Comment thread freewili/safe_reponse_frame_dict.py Outdated
Comment thread tests/test_hw.py Outdated
Comment thread tests/test_hw.py Outdated
Comment thread freewili/serialport.py Outdated
Comment thread tests/test_get_file.py Outdated
@drebbe-intrepid
drebbe-intrepid merged commit afadabc into master Jan 26, 2026
3 checks passed
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.

2 participants