Add DotPad buffered-receive and skipped BLE tests#19942
Open
bramd wants to merge 4 commits into
Open
Conversation
5b1170b to
2ca075c
Compare
Member
|
@bramd - is this ready for review? |
Member
|
@bramd - is this ready for review? |
Replace the fragile _onReceive that did inline blocking reads with a buffered-receive approach that accumulates bytes and extracts complete packets. This handles resynchronization on bad sync bytes, buffer overflow protection, and partial-packet buffering. Works with both byte-at-a-time delivery (Serial) and packet-based delivery (BLE). Extract _processPacket from the old inline parsing for clarity. Add 9 unit tests covering: complete packet, byte-at-a-time, partial chunks, multiple packets, resync, overflow, incomplete, empty, and partial header. All pass. Add 5 skipped BLE-specific DotPad tests (TDD skeleton for PR C): _isBleDotPad, check(), addBleDevices registration, _tryConnect BLE. Also fixes "Received responce" typo → "Received response".
2ca075c to
79a17e9
Compare
Two correctness fixes to the buffered-receive path: - Clear _receiveBuffer at the start of each _tryConnect probe. The buffer is instance-level and was reused across auto-detect probes; the USB match is a generic FTDI VID, so stray bytes from a non-DotPad device on an earlier port could prefix and corrupt the real device's first response. - Validate the declared packet length at parse time instead of capping the accumulation buffer. Real DotPad frames are small, so a declared length beyond DP_MAX_PACKET_SIZE means a false/garbled header: discard one byte and resync. This drops the old pre-extraction buffer wipe, which (a) discarded multi-packet bursts exceeding 512 bytes before processing any of them and (b) could never assemble a frame larger than 512 bytes. It also fixes a stall where a false sync followed by a large bogus length waited indefinitely (recoverable only by wiping queued real packets). Tests: replace test_bufferOverflow_cleared (obsolete semantics) with test_implausibleLength_resynchronize, and assert extracted packet body content in test_completePacketAtOnce to cover the header-stripping slice.
Replace the old "covered by the GNU General Public License / See the file COPYING" reference with the current two-line license reference documented in projectDocs/dev/copyrightHeaders.md, across the files touched in this PR.
Replace "frame" with "packet" in the comments/docstrings touched in this PR to match the terminology used in the code (packet, packetBody, packetLength).
Contributor
Author
|
@seanbudd Yes, this is ready now. |
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.
Link to issue number:
N/A. This is a follow-up to #19122 (DotPad BLE support) and #19838 (hwIo.ble module). As discussed in those PRs, the work is being split into three smaller PRs. This is "PR B" — the buffered-receive implementation and skipped BLE tests in preparation for the final BLE driver integration in PR C. There is no standalone issue tracking this change.
Summary of the issue:
The DotPad driver's
_onReceivemethod reads remaining packet bytes synchronously viaself._dev.read()and raisesRuntimeErroron any malformed byte, which can kill the display connection. This approach also cannot handle BLE's packet-based delivery model where entire packets arrive in a single callback. The buffered-receive replaces this with a more robust approach as a prerequisite for BLE support.Description of user facing changes:
DotPad braille displays now handle malformed serial data more gracefully. Instead of crashing the display connection on a single corrupted byte, the driver resynchronizes and continues operating. In practice, since DotPad devices currently only connect over USB serial (which is a stable connection), users are unlikely to notice this change. The real benefit comes when BLE support lands in PR C, where packet-based delivery makes the buffered approach essential.
Description of developer facing changes:
_onReceive(self, header1: bytes)with a buffered-receive approach_onReceive(self, data: bytes)that accepts variable-length input (1 byte from Serial, full packets from BLE)._processPacket(self, packetBody: bytes)from the old inline parsing for clarity.DP_MAX_PACKET_SIZEprotocol constant todefs.py.Description of development approach:
Ported the buffered-receive logic from the
dotpad-blebranch (#19122), keeping only the transport-agnostic parts. No BLE-specific code is included — that lands in PR C.The approach replaces synchronous
self._dev.read()calls within the callback with a_receiveBufferthat accumulates bytes across callbacks. Complete packets are extracted from the buffer as they become available.Testing strategy:
Unit tests: 9 unskipped tests covering:
Additionally, 5 skipped BLE-specific tests (
_isBleDotPad,check(),addBleDevicesregistration,_tryConnectBLE path) are included as a TDD skeleton for PR C.rununittests.bat: 1095 tests, 5 skipped, all pass.ruff,pyright,markdownlintall pass.runcheckpot.bat: 0 errors.Manual testing: Tested with a DotPad connected over USB serial. The display works correctly with the new buffered-receive code — navigation, key input, and braille output all function as expected.
Known issues with pull request:
None.
Code Review Checklist:
_onReceive,_processPacket