Repository navigation
rs485_bridge: surface a failed socket alloc, and keep rejected frames counted - #15
Merged
Merged
Conversation
… counted Consumer side of the ArduinoLibs receive-path fixes. 1. setup() now refuses to run when rs485.initialized() is false. RS485Socket's receive buffer comes from an unchecked malloc inside RS485::begin(), and a NULL buffer makes update() return false forever -- so the bridge would transmit happily while never receiving a single frame, with /json/info reporting itself healthy. That is the worst possible thing to diagnose in the field: every counter says fine and nothing arrives. It now reports `error: rs485 alloc failed` and releases the pins and the UART instead of half-running. 2. serviceRs485() distinguishes "bus empty" from "frame rejected". Now that RS485Utils validates the socket-layer length itself -- those checks used to be compiled out of release builds -- getMsg() returning NULL no longer implies an empty bus. The drain loop read NULL as "nothing left" and returned, so a stream of malformed frames would have become indistinguishable from silence, abandoning the rest of the pass's budget and showing nothing on the info page. It now reads getRejectCount() around the call, counts a rejection as rs485Rx + RS485B_ERR_SHORT, and keeps draining. This matters most during hardware bring-up, where the runbook's failure diagnoses lean on exactly those counters to tell framing problems from wiring problems. Verified: `pio run -e ampworks` and `-e usermods` both SUCCESS; the bridge's own 19 host test groups still pass on both ABIs. Needs the paired ArduinoLibs PR. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
…ix stale docs * setPacketTimeoutForBaud(baud) after init(). The socket's default timeout is sized for DEFAULT_BAUD, but baud is user-settable from the settings page and a maximal frame at 4800 baud spends 275 ms on the wire -- longer than the 250 ms default. Left alone, every full-size frame would be abandoned mid-flight while small ones still worked, which is a miserable failure to diagnose from the info page. * Timeouts are now visible. getTimeoutCount() was dead weight -- nothing surfaced it, so fix (3) in the paired PR would have been invisible in the field even though the bring-up runbook's soak step is written to watch for exactly that. Added to the `RS485 dropped` row as a separate figure from framing errors, because it means something different: a truncated or interrupted transmission rather than a corrupt one. * Two comments still claimed RS485Utils' length checks are compiled out of release builds (usermod_rs485_bridge.cpp and readme.md). That stopped being true with the paired PR, and the plan explicitly called for updating them. Both now describe what actually happens, including why the usermod keeps its own bounds check anyway: defence in depth against a library built without the fix, plus the empty-payload test, which is the usermod's own and has no library equivalent. Verified: `pio run -e ampworks` SUCCESS; `make test` green across all four suites (45 receive-path assertions, rs485_bridge on both ABIs, ampworks sensor-sync, router). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
aphelps-claude-bot
added a commit
to aphelps/WLED_dev
that referenced
this pull request
Jul 30, 2026
) * bump submodules: RS485 receive-path fixes + first ArduinoLibs tests ArduinoLibs 6d1de81 -- fixes the four receive-path defects found auditing the vendored RS485_non_blocking (stale-packet re-delivery, unchecked malloc, no packet timeout, length checks compiled out of release builds) and adds test/, the first test infrastructure in that repo: an Arduino.h shim plus 28 assertions, each paired with a negative control that confirms disabling the fix turns them red. WLED 0cf79a01 -- bridge side: refuse to run on a failed socket alloc, and keep rejected frames counted now that a NULL from getMsg() no longer means "bus empty". Also extends `make test` to cover two suites it silently skipped: the new ArduinoLibs receive-path tests, and the rs485_bridge wire-format tests, which had to be run by hand and are now run on BOTH ABIs (native and -fpack-struct=1) since the point of most of those assertions is that the two agree. make test -> ampworks sensor-sync + rs485_bridge (x2 ABIs) + ArduinoLibs + router aphelps/ArduinoLibs#10 aphelps/WLED#15 Submodule PRs merge first; these pointers are re-pointed at the merged shas before this lands. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ * bump submodules: self-review fixes on the receive-path stack ArduinoLibs 538a01b -- the packet timeout measured poll latency rather than wire time, so with the check running before update() it could discard a frame whose remaining bytes were already in the FIFO: a regression against pre-timeout behaviour, not a pre-existing bug. Now checked after update(), plus a baud-derived timeout (fixed 250 ms killed every full-size frame at 4800 baud), reachable NULL guards, and uint16_t counters to keep the ATmega328 footprint down. Two of the new tests turned out to pass with their fix disabled and are now deterministic; three uncovered paths added. 45 assertions, up from 28. WLED 2b5baa2c -- scale the timeout to the configured baud, surface timeouts on the info page (the counter existed but nothing read it), and correct two comments that still said the library's length checks are compiled out of release builds. Makefile: test-bridge guards HMTL and ArduinoLibs too, not just WLED. It compiles against headers from all three, so on a fresh clone with uninitialised submodules a bare `make` failed with a confusing missing-header error from the compiler instead of the "run ./setup.sh" message require_submodule exists to print. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ * re-point submodules at the merged receive-path commits ArduinoLibs bceedb3 (#10) -- four receive-path defects fixed, plus test/: the first test infrastructure in that repo (45 assertions, each with a verified negative control). WLED cdfef9c0 (#15) -- bridge side: refuse to run on a failed socket alloc, scale the receive timeout to the configured baud, surface timeouts on the info page, keep rejected frames counted. Both squash-merged, so this replaces the branch-tip pointers this PR opened with. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ --------- Co-authored-by: aphelps-claude-bot <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This was referenced Jul 30, 2026
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.
Consumer side of aphelps/ArduinoLibs#10 (the four RS485 receive-path fixes). Merge that one first.
1.
setup()refuses to run when the socket did not come upRS485Socket's receive buffer comes from an uncheckedmallocinsideRS485::begin(), and a NULL buffer makesupdate()return false forever. So the bridge would transmit happily while never receiving a single frame, with/json/inforeporting itself healthy — the worst possible thing to diagnose in the field: every counter says fine and nothing arrives.It now checks
rs485.initialized()(which, after the paired PR, covers the serial, the channel object and the channel's buffer), reportserror: rs485 alloc failed, and releases the pins and the UART rather than half-running.2.
serviceRs485()distinguishes "bus empty" from "frame rejected"Now that
RS485Utilsvalidates the socket-layer length itself — those checks used to be compiled out of release builds —getMsg()returning NULL no longer implies an empty bus. The drain loop read NULL as "nothing left" andreturned, so a stream of malformed frames would have become indistinguishable from silence: the rest of the pass's four-frame budget abandoned, and nothing shown on the info page.It now reads
getRejectCount()around the call, counts a rejection asrs485Rx+RS485B_ERR_SHORT, and keeps draining. This matters most during hardware bring-up, where the runbook's failure diagnoses lean on exactly those counters to tell framing problems from wiring problems.Verification
pio run -e ampworksand-e usermodsboth SUCCESS-fpack-struct=1)🤖 Generated with Claude Code
https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ