Skip to content

add rs485 bridge usermod (HMTL submodule + ArduinoLibs/WLED bumps) - #20

Merged
aphelps-claude-bot merged 5 commits into
mainfrom
rs485-bridge-usermod
Jul 30, 2026
Merged

aphelps-claude-bot merged 5 commits into
mainfrom
rs485-bridge-usermod

Conversation

@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator

Summary

Adds a WiFi ↔ RS485 bridge usermod for legacy HMTL modules,
plus the submodule plumbing it needs. Three repos, one change:

Repo What lands
WLED_dev (here) New HMTL submodule, bumped ArduinoLibs + WLED pointers, docs
ArduinoLibs Vendored RS485_non_blocking, library manifests, portability + build guards
WLED The rs485_bridge usermod itself

Submodule PRs

The new HMTL submodule

aphelps/HMTL is added at the repo root as a reference checkout, deliberately not on the
PlatformIO build path.
The audit that drove this (plan subtask 3):

  • HMTL/Libraries ships no PlatformIO manifests at all, so under lib_compat_mode = strict
    it would be silently dropped anyway.
  • HMTLTypes.cpp includes Debug.h, EEPromUtils.h, PixelUtil.h, MPR121.h, XBeeSocket.h;
    HMTLMessaging.cpp includes HMTLPrograms.h → FastLED.h, which WLED 16 removed. None of
    that builds.
  • The good news: the public header HMTLMessaging.h is clean (Socket.h, RS485Utils.h,
    HMTLTypes.h) and pulls no Debug.h, so the two-argument DEBUG_PRINT(v, x) vs WLED's
    one-argument DEBUG_PRINT(x) collision the plan worried about never arises.

So the usermod vendors only the HMTL wire format (message header, type codes, CRC-8 poly
0xD8) into a dependency-free header, with static_asserts guarding layout drift. Keeping the
submodule gives us the protocol source of truth and the Python tooling, and it removes the need
to clone HMTL in WLED's CI.

setup.sh needs no logic change — git submodule update --init --recursive already picks up
a new .gitmodules entry; only its descriptive strings and the CLAUDE.md submodule
documentation are updated.

Test plan

Automated:

  • c++ -std=c++11 -Wall -Wextra -o /tmp/rs485_test WLED/usermods/rs485_bridge/tests/rs485_bridge_test.cpp && /tmp/rs485_test — host test for the pure bridge/framing logic
    ALL TESTS PASSED
  • c++ -std=c++11 -Wall -Wextra -o /tmp/ss_test WLED/usermods/ampworks/tests/sensor_sync_test.cpp && /tmp/ss_test — existing host test still passes
    ALL TESTS PASSED
  • cd WLED && pio run -e ampworks — builds clean with the usermod enabled, no new warnings
    RAM: [=== ] 25.3% (used 82856 bytes from 327680 bytes) Flash: [======== ] 83.6% (used 1315033 bytes from 1572864 bytes) ampworks SUCCESS 00:00:27.376
  • cd WLED && pio run -e esp32dev — stock env still builds after the const.h /
    pin_manager.h / platformio.ini edits (usermod absent, not merely disabled)
    esp32dev SUCCESS 00:00:04.043
  • cd WLED && pio run -e usermods — the custom_usermods = * wildcard env builds with
    usermods/rs485_bridge/ present and no RS485 flags
    usermods SUCCESS 00:00:18.630
  • Per-usermod CI matrix reproduced locally (platformio_override.usermods.ini +
    custom_usermods = rs485_bridge, with PLATFORMIO_LIB_EXTRA_DIRS set exactly as both
    workflows do); override file deleted afterwards
    usermods_esp32 SUCCESS 00:00:07.269 usermods_esp32c3 SUCCESS 00:00:06.049 usermods_esp32s2 SUCCESS 00:00:07.816 usermods_esp32s3 SUCCESS 00:00:08.029
  • cd WLED && pio run -e apa102_mpr121 — the env extending env:ampworks still builds
    apa102_mpr121 SUCCESS 00:00:27.011
  • Portability: grep -rnE '/Users/|/home/|\blib_dir\b' ArduinoLibs/RS485Utils WLED/platformio.ini
    returns nothing (exit 1), and pio pkg list -e ampworks resolves everything repo-relative
    ├── RS485Utils @ 0.0.0+... (required: .../ArduinoLibs/RS485Utils) │ ├── RS485_non_blocking @ 1.0.0 (required: RS485_non_blocking) │ └── Socket @ 0.0.0+... (required: Socket)
  • git submodule status — HMTL registered and pinned; bash -n setup.sh clean
    +b2a8a93… ArduinoLibs (heads/rs485-bridge-usermod) 838a6be… HMTL (0.1-111-g838a6be) 467c222… WLED (heads/rs485-bridge-usermod) syntax OK
  • grep CLAUDE.md + usermods/rs485_bridge/readme.md for the new env flags, submodule and
    config-field docs — all present (submodule table, -D USERMOD_RS485_BRIDGE -D RS485_HARDWARE_SERIAL=2, and all nine config keys documented).

Manual — hardware, blocks the merge:

  • Flash ampworks to an ESP32 with an RS485 transceiver (Serial2 RX16/TX17/EN18); confirm a
    clean boot with the usermod enabled and disabled.
  • Send an HMTL command over WiFi (UDP :21331) and confirm a legacy HMTL module on the RS485
    bus receives/acts on it.
  • Send an HMTL VALUE/RGB command addressed to the WLED device over RS485 and confirm the LEDs
    respond.
  • Confirm an RS485 response frame is relayed back to the WiFi sender.
  • Config round-trip: set every RS485 field in Settings → Usermods, save, reboot, confirm the
    values persist (curl -s http://<ip>/json/cfg | python3 -m json.tool).

Merge order

ArduinoLibs #5 → WLED #11 → this PR (the submodule pointers here already point at both branch
tips and will be re-pointed at the merged commits).

Adds aphelps/HMTL as a third submodule at the repo root. It is a reference
checkout, deliberately NOT on the PlatformIO build path: HMTL/Libraries
transitively pulls FastLED/PixelUtil, EEPromUtils, MPR121 and XBeeSocket, none
of which build under WLED 16, so the rs485_bridge usermod vendors just the HMTL
wire format instead. Keeping the submodule gives us the protocol source of
truth and the Python tooling.

setup.sh needs no logic change — `git submodule update --init --recursive`
already picks up the new .gitmodules entry; only its descriptive strings and
CLAUDE.md's submodule documentation are updated.

Submodule pointers:
- ArduinoLibs: vendored Gammon RS485_non_blocking, Socket/RS485Utils manifests,
  portable example projects, RS485UTILS_SUPPORTED guard.
- WLED: the rs485_bridge usermod itself.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What was done. Decisions (user, 2026-07-26): phase core+HMTL first; both HMTL directions; add aphelps/HMTL as a submodule for the protocol libs; merge ArduinoLibs PR #4 (RS485 ESP32 example fixes, aphelps/ArduinoLibs#4) before basing ArduinoLibs work. Precondition cleared: PR #4 MERGED 2026-07-27 01:17 UTC (b2a8a93). Related: WLED PRs #9/#10 (sensor mesh) are the follow-up's context.

What's needed from you. Review the PR — code, tests, and the disposition of any self-review findings.

Links.
plan: todo_plans/rs485-bridge-usermod-using-arduinolibs.md
PR: #20

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Self-review of the combined change set: this PR plus submodule PRs ArduinoLibs#5 and WLED#11. The base-repo diff itself (submodule pointers, CLAUDE.md submodule table, setup.sh strings) is consistent and accurate. All findings below concern submodule-PR code, so they are listed here rather than as inline comments (those files are not part of this PR's diff). Findings 1, 2 and 4 were verified against the reference implementation in HMTL/Libraries/HMTLMessaging/ at the pinned submodule commit.

1. Incoming poll responses are re-answered as poll requests (breaks the WiFi-side discovery flow). rs485b_decide() (WLED#11, usermods/rs485_bridge/rs485_bridge_protocol.h ~line 355) treats every MSG_TYPE_POLL addressed to this node as a request, ignoring MSG_FLAG_ACK. Legacy poll responses are MSG_TYPE_POLL | MSG_FLAG_ACK (HMTLMessaging.cpp:313-314), and the reference MessageHandler::process_msg explicitly refuses to act on ACK-flagged frames, forwarding them toward the original source instead (MessageHandler.cpp:81-95). Failure scenario: a WiFi client sends a POLL through the bridge; each module's response comes back socket-addressed to the bridge, which then (a) never relays the response to the WiFi peer and (b) transmits its own poll response back at the module — discovery returns nothing and the bus gets spurious ~48 ms blocking transmissions. Fix: in rs485b_decide, route frames carrying HMTL_MSG_FLAG_ACK (except MSG_TYPE_SENSOR, which the reference code deliberately still processes) to relay-to-peer instead of local handling, and add a host-test case for a POLL|ACK frame.

2. The bridge's poll response addresses its HMTL header to itself, not the requester. sendPollResponse() (WLED#11, usermods/rs485_bridge/usermod_rs485_bridge.cpp ~line 261) calls rs485b_hmtl_fmt(frame, sizeof(frame), address, ...) — address is the bridge's own address. The reference implementation sets the response's msg_hdr.address to the requester (hmtl_poll_fmt(..., source_address, ...), MessageHandler.cpp:130-136, where source_address is the socket-layer source of the request). A master that validates the response's destination address will drop the bridge's poll responses. Fix: pass to instead of address.

3. Disabling the usermod at runtime doesn't stop it. readFromConfig() (WLED#11, usermod_rs485_bridge.cpp ~line 347) stores enabled = false but never clears running, so loop() keeps servicing RS485 + UDP while the info page reports disabled; relatedly, releasePins() is defined but has no caller anywhere. Either clear running (and stop the UDP listener) on disable — pins/UART can legitimately stay held until reboot given the documented no-re-init policy — or mark Enabled as "reboot required" in the settings help text and readme like the other fields.

4. Broadcast-POLL responses aren't collision-staggered. Legacy modules delay address * 2 ms before answering a broadcast poll, precisely to serialize responses on the shared half-duplex bus (MessageHandler.cpp:140-145). The bridge queues its response for the next loop() pass, so on a mixed bus a broadcast poll can produce responses that collide with low-address modules'. Consider the same address-based delay before enqueuing, or at least document the deviation in the readme's HMTL-subset table.

5. Suggested test: golden wire-format vectors for the vendored protocol. The CRC unit test computes its "reference" with a byte-for-byte copy of the implementation's own loop (WLED#11, usermods/rs485_bridge/tests/rs485_bridge_test.cpp, test group 2), so a mistranscribed polynomial or bit order from EEPromUtils.cpp would still pass; and the size-only static_asserts don't pin the HmtlMsgValue 13/3-bit bitfield packing. Add a few byte-exact golden frames (e.g. generated with the HMTL submodule's Python tooling, which is what the submodule is kept for) covering RGB/VALUE/POLL, asserting the CRC byte and the full byte layout. This is the check that actually protects interop with legacy modules — today only the hardware-gated Testing Required items would catch a transcription error.

6. WiFi datagrams addressed to the bridge itself are forwarded, never applied. serviceUdp() (WLED#11, usermod_rs485_bridge.cpp ~lines 146-163) forwards every valid datagram to the bus, including ones whose HMTL address is the bridge's own (a ~48 ms blocking transmission no module will act on) and broadcasts (the local node is the one bus citizen that won't execute them). If intentional — local control being expected via WLED's native APIs — one sentence in the readme would prevent surprise; otherwise run accepted to-self/broadcast datagrams through rs485b_decide/handleDecision and skip the bus write for the self-unicast case.

7. Dead check in rs485b_validate_udp_ingress. The frameLen > 255 clause (WLED#11, rs485_bridge_protocol.h ~line 252) can never be true — frameLen is uint8_t. Minor, but it reads as if it guards something. Relatedly: because UDP_BUF_LEN is 64, a valid-but-long HMTL frame (up to 128 per HMTL_MAX_MSG_LEN) is truncated by udp.read() and lands in errShort rather than errOversize — worth a one-line comment so the counters aren't misread during bring-up.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

⏳ Testing Tasks — human confirmation required before merge

What was done. Decisions (user, 2026-07-26): phase core+HMTL first; both HMTL directions; add aphelps/HMTL as a submodule for the protocol libs; merge ArduinoLibs PR #4 (RS485 ESP32 example fixes, aphelps/ArduinoLibs#4) before basing ArduinoLibs work. Precondition cleared: PR #4 MERGED 2026-07-27 01:17 UTC (b2a8a93). Related: WLED PRs #9/#10 (sensor mesh) are the follow-up's context.

What's needed from you. Run the ## Testing Required steps on the live system, then /ack (or 'yes' on Telegram).

Links.
plan: todo_plans/rs485-bridge-usermod-using-arduinolibs.md
PR: #20
last log: 2026-07-28 03:14:33 UTC [MOVED] rs485-bridge-usermod-using-arduinolibs Review Tasks → Testing Tasks

Once all ## Testing Required items are confirmed, leave /ack-tested as a comment and the bot will merge.

Note: aphelps/WLED#11 (the WLED submodule PR) has no approval yet. Submodule PRs merge first, so it needs a review before this stack can land.

@aphelps aphelps left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please do the refactor we discussed

Bumps both submodule pointers for the rework Adam asked for on WLED#11
("Why isn't this imported from the HMTL libraries? ... We should do this
right, even if that means changes to HMTL code."):

  HMTL 838a6be -> 7ca6637  aphelps/HMTL#6 -- extract the wire format
                           into HMTLprotocol/HMTLWireFormat.h, a
                           dependency-free header (<stdint.h> +
                           Socket.h, never Arduino.h). Pure move:
                           every relocated line byte-identical.
  WLED 87ac5e22 -> 1beb4f83  aphelps/WLED#11 -- rs485_bridge_protocol.h
                           now includes that header instead of
                           declaring ~150 lines of its own, plus the
                           lib_extra_dirs/lib_deps wiring and the four
                           comment-accuracy fixes from re-review
                           4793843525.

CLAUDE.md's HMTL/ submodule row is rewritten: it claimed "Reference only
-- deliberately NOT on the PlatformIO build path" and gave a
transitive-dependency rationale that turned out to be about the .cpp
files, not the headers. HMTL/Libraries is now on the build path via
lib_extra_dirs in [env:ampworks], with only HMTLprotocol ever compiled
in, and the "keep it in sync" instruction is gone because there is no
longer a second copy.

Test: full plan Test Plan green -- host tests (rs485_bridge with the
real HMTL/ArduinoLibs headers under plain c++, sensor_sync), pio run for
ampworks / esp32dev / usermods / apa102_mpr121 and the
usermods_esp32{c3,s2,s3} CI matrix, portability grep, bash -n setup.sh.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Rework landed: the HMTL wire format is now imported, not vendored

Following the review comment on aphelps/WLED#11 — "Why isn't this imported from the HMTL libraries? ... We should do this right, even if that means changes to HMTL code."

The stack now has a third submodule PR:

Repo PR What
aphelps/HMTL #6 (new) Extract the wire format into Libraries/HMTLprotocol/HMTLWireFormat.h — dependency-free (<stdint.h> + Socket.h, never Arduino.h). Pure move, byte-identical. Adds PlatformIO manifests.
aphelps/WLED #11 → 1beb4f83 rs485_bridge_protocol.h includes that header instead of declaring ~150 lines of its own; build wiring; the 4 comment-accuracy fixes from re-review 4793843525.
aphelps/ArduinoLibs #5 Unchanged by this round.

Here (dc10058): both submodule pointers bumped (HMTL 838a6be → 7ca6637, WLED 87ac5e22 → 1beb4f83) and the HMTL/ row of CLAUDE.md rewritten. It previously said "Reference only — deliberately NOT on the PlatformIO build path" and gave a transitive-dependency rationale that turned out to be about the .cpp files rather than the headers, plus a "keep it in sync" instruction. HMTL/Libraries is now on the build path via lib_extra_dirs in [env:ampworks], with only HMTLprotocol ever compiled in, and there is no second copy left to sync.

Why the original audit was wrong. It conflated header dependencies with implementation dependencies. HMTLProtocol.h and HMTLTypes.h have zero #includes; every heavy dependency (PixelUtil/FastLED, EEPromUtils, MPR121, XBeeSocket) lives in HMTLTypes.cpp. The only genuine coupling was HMTLMessaging.h → RS485Utils.h → Arduino.h, plus HMTLPrograms.h → FastLED.h for the program codes — all of which the extraction routes around.

Acceptance check. The bridge's host unit test now compiles the real HMTL and ArduinoLibs headers with a plain c++ and no Arduino toolchain, which makes it a standing regression check that HMTLWireFormat.h stays dependency-free:

c++ -std=c++11 -Wall -Wextra -I HMTL/Libraries/HMTLprotocol -I ArduinoLibs/Socket \
    -o /tmp/rs485_test WLED/usermods/rs485_bridge/tests/rs485_bridge_test.cpp && /tmp/rs485_test

Worth a second pair of eyes (all three explained in detail on the WLED#11 thread):

  1. The extraction is larger than the subtask text proposed — the message structs embed output_hdr_t / config_hdr_t, so those moved out of HMTLTypes.h too. Still a pure move; verified byte-identical block-by-block.
  2. No srcFilter exclusions in the new HMTL manifests. Excluding HMTLTypes.cpp / HMTLMessaging.cpp would break HMTL's own module builds, and with the extraction done nothing outside HMTLprotocol is on the WLED build path anyway.
  3. One wire-visible change: the POLL response is now HMTL_MSG_POLL_MIN_LEN (24 B on ESP32) rather than the packed vendored copy's 23 B. That is exactly what HMTL's own hmtl_poll_fmt() emits for this target, and only trailing padding differs, so field offsets are unchanged for a legacy master.

Knock-on: rs485_bridge_protocol.h is no longer compiled in [env:usermods] or the per-usermod CI matrix, since it now depends on a submodule those workflows do not clone. The inert placeholder still supplies the DWARF compilation unit validate_modules.py requires; the wire-layout static_asserts are covered by pio run -e ampworks and the host test.

Test Plan: green.

Check Result
rs485_bridge host test (plain c++, real HMTL headers) ✅ ALL TESTS PASSED
sensor_sync host test ✅ ALL TESTS PASSED
HMTLWireFormat.h include list is exactly <stdint.h> + Socket.h ✅
Pure-move verification (5/5 blocks, 191 lines byte-identical) ✅
pio test -e native in HMTL ✅ 50/50
pio run -e ampworks / esp32dev / usermods / apa102_mpr121 ✅ no new warnings
pio run -e usermods_esp32{c3,s2,s3} (CI matrix) ✅
Portability grep, git submodule status, bash -n setup.sh ✅

The 7 code findings from review 4783222046 remain open and untouched — this round was the import rework plus the comment-accuracy nits, as agreed.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Already done — our messages crossed. Your review landed at 06:35 UTC; the refactor was pushed at 07:00–07:03.

The vendored copy is gone. What landed:

  • New PR aphelps/HMTL#6 (7ca6637) — extracts the block already titled "Transport-agnostic message types" out of HMTLMessaging.h into a dependency-free HMTLprotocol/HMTLWireFormat.h. HMTLMessaging.h now includes it, so existing HMTL code compiles unchanged. Verified a pure move: 5 of 5 relocated blocks byte-identical, and HMTL's own pio test -e native passes 50/50.
  • WLED#11 ← 1beb4f83 — deletes the 656-line duplicated header, includes the real HMTL header, and fixes the four comment-accuracy nits from the last re-review.
  • WLED_dev#20 ← dc10058 — HMTL/Libraries onto lib_extra_dirs, HMTL submodule pointer bumped, and the CLAUDE.md HMTL row rewritten (it had claimed "reference only — deliberately NOT on the build path" on a transitive-dependency rationale that turned out to be wrong, plus a keep-in-sync instruction this change exists to delete).

The proof it's genuinely dependency-free: the host tests still compile under plain c++ -std=c++11 while including the real HMTL and ArduinoLibs headers, so any Arduino.h leak fails there. All seven PlatformIO envs build clean.

Two deviations from the spec worth knowing, both documented in #6: the extraction also had to move output_hdr_t / config_hdr_* / HMTL_PROGRAM_* because the message structs embed them, and the planned srcFilter exclusions turned out unnecessary — they would have broken HMTL's own module builds, and nothing outside HMTLprotocol is on the WLED path anyway.

One real wrinkle: msg_poll_response_t is unpacked upstream, so it is 23 B on AVR and 24 B on ESP32 where uint16_t forces alignment — trailing padding only, every field offset identical. The bridge emits HMTL_MSG_POLL_MIN_LEN, which is exactly what HMTL's own hmtl_poll_fmt() emits on the same platform, and the inbound path is unaffected (a poll request carries no payload, so nothing validates against that length). But an AVR master that length-checks a poll response against its own 23 B constant could reject ours. I added a ## Testing Required item to check both directions on the bus; if outbound fails, the fix is to pack the struct or emit 23 explicitly. A static_assert block now pins every other wire struct, so that is the only size that can drift.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Follow-up review of dc10058 (base-repo half of the HMTL wire-format import rework: CLAUDE.md rewrite + HMTL/WLED submodule pointer bumps). Submodule code reviewed separately (aphelps/HMTL#6 review 4794773254, aphelps/WLED#11 review 4794753753) — this reviews only the base-repo diff.

Submodule pointers — verified against the live PR heads, no drift:

  • HMTL @ 7ca6637 == the exact head of aphelps/HMTL#6 (rs485-bridge-wire-format, OPEN, base main); the checked-out submodule commit is the wire-format extraction commit.
  • WLED @ 1beb4f83 == the exact head of aphelps/WLED#11 (rs485-bridge-usermod, OPEN, base base-wled-16.0.1).
  • ArduinoLibs @ b805d19 (unchanged by this commit) is still the head of aphelps/ArduinoLibs#5.
  • All three point at unmerged PR heads, which is correct for the stack at this stage — but it makes the recorded merge order binding: ArduinoLibs#5 → HMTL#6 → WLED#11 → this PR, re-bumping each pointer to the post-merge SHA before #20 merges, so main never pins a commit that exists only on a PR branch.

CLAUDE.md HMTL/ row — accurate, verified claim-by-claim against the tree (not the diff text):

  • HMTL/Libraries on the build path via lib_extra_dirs in [env:ampworks] — confirmed (WLED/platformio.ini:532-533), plus HMTLprotocol pinned in lib_deps (:540).
  • "only HMTLprotocol is ever compiled in" — holds: HMTLprotocol/ contains only headers + library.json, HMTLWireFormat.h's include list is exactly <stdint.h> + "Socket.h", and no source file in the WLED tree includes HMTLTypes.h/HMTLMessaging.h (grep hits only readme prose). The [env:usermods] comment (platformio.ini:834-835) correctly documents why ../HMTL is absent there.
  • Every type/constant the row lists is present in the header (config_hdr_t via the versioned typedef). The disproven "Reference only — deliberately NOT on the PlatformIO build path" claim and the "keep in sync" instruction are both gone, and the replacement rationale (heavy deps are in the .cpps, not the headers) matches what the audit actually found.
  • The updated build-flags line matches [env:ampworks] (only the DEBUG_LEVEL_MPR121=0 debug knob is omitted, fine for a summary), and the new usermods-list row checks out: USERMOD_ID_RS485_BRIDGE = 62 (const.h:235), PinOwner::UM_RS485_BRIDGE (pin_manager.h:80).

Prior issues: the 7 code findings from review 4783222046 all live in WLED#11 code and remain open there (per re-review 4794753753) — this base-repo commit neither addresses nor regresses them, as expected.

New issue (1, minor): one doc comment left stale by the rework, inline on setup.sh.

Nit, pre-existing / outside this diff: CLAUDE.md line 7 still says "Version 0.15.3" although the WLED submodule has been at v16.0.1 since #19 — worth fixing the next time CLAUDE.md is touched.

Comment thread setup.sh Resolved

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

⏳ Testing Tasks — human confirmation required before merge

What was done. Decisions (user, 2026-07-26): phase core+HMTL first; both HMTL directions; add aphelps/HMTL as a submodule for the protocol libs; merge ArduinoLibs PR #4 (RS485 ESP32 example fixes; aphelps/ArduinoLibs PR number 4 — bare URL deliberately omitted, see below) before basing ArduinoLibs work. Precondition cleared: PR #4 MERGED 2026-07-27 01:17 UTC (b2a8a93). (De-linked 2026-07-28: check-for-work.sh:851 harvests any PR URL in a Testing-section task block as one of this task's live PRs, so the raw #4 link kept firing a "closed PR → move to Completed" dispatch against this still-unmerged task. Skill fix filed in claude-skills as anchor-pr-url-scanning-to-the-pr-field-bullets-...; restore the link once that lands.) Related: WLED PRs #9/#10 (sensor mesh) are the follow-up's context.

What's needed from you. Run the ## Testing Required steps on the live system, then /ack (or 'yes' on Telegram).

Links.
plan: todo_plans/rs485-bridge-usermod-using-arduinolibs.md
PR: #20
last log: 2026-07-29 03:34:47 UTC [MOVED] rs485-bridge-usermod-using-arduinolibs Review Tasks → Testing Tasks

Once all ## Testing Required items are confirmed, leave /ack-tested as a comment and the bot will merge.

Two things still block the merge sequence regardless of testing:

  1. aphelps/HMTL#6 has no review yet. Submodule PRs merge before the parent, and #6 carries the extracted HMTLWireFormat.h this stack now depends on. WLED_dev#20, WLED#11 and ArduinoLibs#5 are all approved; #6 is the only one outstanding.
  2. This PR is now CONFLICTING. origin/main gained 7916e67 ("wire esp-now-router submodule + top-level make test"), which collides with this branch's submodule/setup changes. The rebase is part of the merge sequence, so I have deliberately not rebased yet — doing so would rewrite the history you just approved, for no gain while the merge is gated.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Follow-up review of 850f019 (docs-only, one line: fixes the stale setup.sh header comment flagged in review 4803705231).

  • Prior issue addressed: the setup.sh header no longer claims HMTL is "reference only, not on the build path". The replacement wording is verified TRUE against the tree, not just plausible: [env:ampworks] has ${PROJECT_DIR}/../HMTL/Libraries on lib_extra_dirs (WLED/platformio.ini:533) and pins ${PROJECT_DIR}/../HMTL/Libraries/HMTLprotocol in lib_deps (:540), and HMTLprotocol/HMTLWireFormat.h is exactly the wire format rs485_bridge imports.
  • No stale claims remain: grep of setup.sh and CLAUDE.md for "reference only" / "not on the build path" / "keep in sync" finds only the accurate post-rework CLAUDE.md HMTL/ row ("is on the firmware build path", "no second copy ... to keep in sync"); setup.sh's other HMTL mentions (lines 77/79, submodule init) were already correct.
  • No new issues. Comment-only change; no behavior, build, or submodule-pointer changes.

The 7 prior code findings (review 4783222046) live in WLED#11 and remain open there, unaffected by this commit. The pre-existing CLAUDE.md "Version 0.15.3" nit (outside this diff) also remains.

aphelps-claude-bot added a commit to aphelps/HMTL that referenced this pull request Jul 29, 2026
An ATMega328 module and an ESP32 module share one RS485 bus and read each
other's EEPROM config blobs, so a struct in this header must have the same
size AND the same field offsets under avr-gcc and under a 32-bit compiler.
Unpacked it did not: avr-gcc aligns everything to 1 byte, while xtensa/x86
align uint16_t to 2. Two structs drifted for real:

  config_hdr_v2_t      8 B on AVR, address at offset 3
                      10 B on 32-bit, address at offset 4  <- INTERIOR pad
  msg_poll_response_t 15 B on AVR vs 16 B on 32-bit, making
                      HMTL_MSG_POLL_MIN_LEN 23 or 24 by target

The second one is a live interop bug, not just untidiness: an AVR master
that length-checks a poll response against its own constant would reject
a structurally valid 24 B response from the ESP32 bridge.

__attribute__((__packed__)) on all 13 structs is layout-neutral on AVR
(alignment is already 1, so deployed modules see no change) and corrective
everywhere else - it makes the 32-bit layout equal the AVR layout that is
already on the wire. HMTL_MSG_POLL_MIN_LEN is now 23 on every target.

Also in this header, since it is now consumed off-Arduino:

* msg_sensor_response_t::data[] -> data[0]. A C99 flexible array member in
  an otherwise-empty struct is rejected by g++ >= 9 in C++ mode (verified:
  avr-g++ 9.5 errors, avr-g++ 8.5 and Apple clang accept), which would stop
  host consumers building on a typical Linux box. Both spellings give
  sizeof == 0, so HMTL_MSG_SENSOR_MIN_LEN and the wire layout are unchanged.
  Same change to msg_sensor_data_t for consistency.
* Copyright date updated.
* The <Arduino.h> include-order contract is now stated explicitly: on
  Arduino builds the byte/boolean guard is skipped and Socket.h's usage
  needs Arduino.h earlier in the TU. Deliberately NOT fixed by including
  <Arduino.h> under a guard - the entire point of the file is that a host
  consumer can include it with no Arduino toolchain present.

Verified: sizes and offsets for all 13 structs plus all seven HMTL_MSG_*_LEN
macros are identical under host clang 21, host clang 21 -fpack-struct=1,
host g++ 16, host g++ 16 -fpack-struct=1, avr-g++ 9.5 -mmcu=atmega328p,
PlatformIO's avr-g++ 8.5 -mmcu=atmega328p and PlatformIO's
xtensa-esp32-elf-g++ 8.4. Before this change the same check failed on every
32-bit configuration.

Part of aphelps/WLED_dev#20

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/HMTL that referenced this pull request Jul 29, 2026
Two problems with the native suite as the acceptance check for the wire
header.

It could not run on a fresh clone: Socket.h was resolved solely through a
hardcoded absolute -I into one developer's Arduino libraries directory, and
this PR makes Socket.h a hard dependency of HMTLWireFormat.h (and therefore
of HMTLTypes.h) rather than only of HMTLMessaging.h. Vendored a
stubs/Socket.h alongside the Arduino/RS485Utils/PixelUtil/FastLED stubs
already there - its body is byte-identical to ArduinoLibs' Socket.h - and
dropped the absolute path. Every include path in [env:native] is now
repo-relative.

It checked nothing about layout: the packing invariant the previous commit
introduced was prose. test/test_wire_format/ static_asserts the size of all
13 structs, the offset of every named field and all seven HMTL_MSG_*_LEN
macros, so it holds for whatever target the file is compiled for - running
the native suite proves the 32-bit layout, building any module firmware
proves the AVR one. Four runtime cases cover what static_assert cannot:
the byte image of msg_hdr_t, config_hdr_v2_t's interior-padding-free
address at offset 3, the msg_value_t 13/3 bitfield split (packing a struct
with bitfields is the one case where the attribute could move more than
padding), and the 23 B poll response.

pio test -e native: 54 test cases, 54 succeeded (was 50), with no external
include paths.

Part of aphelps/WLED_dev#20

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/HMTL that referenced this pull request Jul 29, 2026
HMTLTypes.h used to be include-free and HMTLMessaging reached socket_addr_t
through RS485Utils; both now include HMTLWireFormat.h, so HMTLprotocol and
Socket must also be linked into the Arduino libraries directory wherever
HMTLTypes or HMTLMessaging is used. The Arduino IDE and the PlatformIO LDF
resolve the transitive include automatically, but only if the library is
present - someone following the "linked individually" instruction with just
the old set gets a missing-header error.

Also records why the wire structs are packed, what drifted without it, and
how to run the layout test.

Part of aphelps/WLED_dev#20

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 that referenced this pull request Jul 29, 2026
HMTL now declares every wire struct __attribute__((__packed__))
(aphelps/HMTL#6, per Adam's directive that one format has to serve both an
ATMega328 and an ESP32 because they are communicating), which changes struct
sizes on this side.

rs485_bridge_protocol.h's static_assert block is updated to the uniform
values and its rationale rewritten. It used to say output_hdr_t was the only
packed struct, that the other seven relied on their field ordering happening
to avoid padding, and that msg_poll_response_t was "the one struct whose size
is ABI-dependent" and therefore exempt. None of that is true any more: there
is no struct left to exempt, so msg_poll_response_t (15 B) and
HMTL_MSG_POLL_MIN_LEN (23) are asserted like the rest, along with
config_hdr_v1/v2_t and the two zero-size FAM structs. The wire-visible
consequence is that the bridge's POLL response is 23 B rather than 24 B -
byte-for-byte what a deployed AVR module emits and length-checks.

Host test group 1 now pins the exact size and every field offset of every
wire struct rather than bounding msg_poll_response_t to 15-or-16, adds
config_hdr_v2_t (the interior-padding case: address at offset 3, not 4), and
checks the msg_value_t 13/3 bitfield split at byte level - packing a struct
containing bitfields is the one case where the attribute could have moved
more than padding.

Two changes to keep the new "compile with g++ >= 9 as well as clang" gate
warning-free, both zero-behaviour:

* dropped the dead `frameLen > 255` test in rs485b_validate_udp_ingress
  (frameLen is a uint8_t, so g++ -Wtype-limits is right that it can never
  fire; the 255 ceiling sendMsgTo's `byte` length imposes is enforced by the
  type). The maxPayload bound it sat next to is unchanged.
* removed the line continuations from a // comment block (-Wcomment).

readme gains the packing rationale and a local-edit gotcha worth knowing:
HMTLprotocol is a file:// lib_dep, so PlatformIO caches a copy under
.pio/libdeps/<env>/ and an edit to HMTLWireFormat.h has no effect until that
copy is cleared - which means a stale copy silently checks the old layout.

Verified: rs485_bridge_test passes under clang 21 and g++ 16, each with and
without -fpack-struct=1, all four warning-free and reporting identical sizes
and offsets. pio run -e ampworks / esp32dev / usermods / apa102_mpr121 and
the usermods_esp32c3/s2/s3 CI matrix envs all build clean.

Part of aphelps/WLED_dev#20

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/HMTL that referenced this pull request Jul 30, 2026
* extract the HMTL wire format into HMTLprotocol/HMTLWireFormat.h

Consumers that only need to speak the HMTL protocol previously had to
copy-and-paste the declarations, because every header that carried them
also dragged in the module runtime: HMTLMessaging.h pulls RS485Utils.h ->
Arduino.h, HMTLPrograms.h pulls FastLED.h/PixelUtil.h, and HMTLTypes.h
comes with HMTLTypes.cpp (EEPromUtils, MPR121, XBeeSocket). The WLED
RS485 bridge usermod (aphelps/WLED#11) vendored ~150 lines for exactly
this reason; this is the fix for that.

HMTLWireFormat.h now holds everything that appears on a wire or in
EEPROM and nothing else:

  - from HMTLTypes.h:     HMTL_CONFIG_MAGIC/VERSION, config_hdr_v1..v3_t,
                          config_hdr_t, HMTL_NO_ADDRESS, BYTE_TO_BAUD /
                          BAUD_TO_BYTE, HMTL_OUTPUT_*, IS_HMTL_*_OUTPUT,
                          HMTL_FLAG_*, HMTL_NO_OUTPUT / HMTL_ALL_OUTPUTS,
                          output_hdr_t
  - from HMTLMessaging.h: the block already titled "Transport-agnostic
                          message types" -- msg_hdr_t, MSG_TYPE_* /
                          MSG_FLAG_*, msg_value_t / msg_rgb_t /
                          msg_program_t / msg_poll_response_t /
                          msg_set_addr_t / msg_sensor_*, HMTL_MSG_START,
                          HMTL_MSG_VERSION, HMTL_MAX_MSG_LEN and the
                          HMTL_MSG_*_LEN macros
  - from HMTLPrograms.h:  the HMTL_PROGRAM_* / PROGRAM_* codes, which
                          travel in msg_program_t.type

This is a pure move: every relocated line is byte-identical, verified
block-by-block against HEAD. No field, code point or layout changes --
deployed hardware speaks this format.

The three source headers now include HMTLWireFormat.h, so existing code
that includes them is unaffected. The header takes only <stdint.h> and
Socket.h (itself include-free, socket_addr_t) and supplies the Arduino
`byte`/`boolean` aliases when built off-Arduino, so it compiles with a
plain host compiler.

Also adds library.json manifests to HMTLprotocol, HMTLTypes and
HMTLMessaging declaring atmelavr + espressif32, which PlatformIO's
lib_compat_mode = strict (used by WLED) requires. No srcFilter
exclusions: nothing outside HMTLprotocol is on the WLED build path now,
and excluding HMTLTypes.cpp / HMTLMessaging.cpp would break HMTL's own
module builds.

Test: pio test -e native -- 50/50 pass (HMTL_Test gains
-I ../../Libraries/HMTLprotocol); HMTLTypes.h + HMTLMessaging.h parse
clean against the desktop stub with and without ARDUINO defined;
HMTLWireFormat.h compiles standalone under c++ -std=c++11 -Wall -Wextra
with no Arduino headers.

Part of aphelps/WLED_dev#20

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* pack every wire struct so AVR and ESP32 layouts agree

An ATMega328 module and an ESP32 module share one RS485 bus and read each
other's EEPROM config blobs, so a struct in this header must have the same
size AND the same field offsets under avr-gcc and under a 32-bit compiler.
Unpacked it did not: avr-gcc aligns everything to 1 byte, while xtensa/x86
align uint16_t to 2. Two structs drifted for real:

  config_hdr_v2_t      8 B on AVR, address at offset 3
                      10 B on 32-bit, address at offset 4  <- INTERIOR pad
  msg_poll_response_t 15 B on AVR vs 16 B on 32-bit, making
                      HMTL_MSG_POLL_MIN_LEN 23 or 24 by target

The second one is a live interop bug, not just untidiness: an AVR master
that length-checks a poll response against its own constant would reject
a structurally valid 24 B response from the ESP32 bridge.

__attribute__((__packed__)) on all 13 structs is layout-neutral on AVR
(alignment is already 1, so deployed modules see no change) and corrective
everywhere else - it makes the 32-bit layout equal the AVR layout that is
already on the wire. HMTL_MSG_POLL_MIN_LEN is now 23 on every target.

Also in this header, since it is now consumed off-Arduino:

* msg_sensor_response_t::data[] -> data[0]. A C99 flexible array member in
  an otherwise-empty struct is rejected by g++ >= 9 in C++ mode (verified:
  avr-g++ 9.5 errors, avr-g++ 8.5 and Apple clang accept), which would stop
  host consumers building on a typical Linux box. Both spellings give
  sizeof == 0, so HMTL_MSG_SENSOR_MIN_LEN and the wire layout are unchanged.
  Same change to msg_sensor_data_t for consistency.
* Copyright date updated.
* The <Arduino.h> include-order contract is now stated explicitly: on
  Arduino builds the byte/boolean guard is skipped and Socket.h's usage
  needs Arduino.h earlier in the TU. Deliberately NOT fixed by including
  <Arduino.h> under a guard - the entire point of the file is that a host
  consumer can include it with no Arduino toolchain present.

Verified: sizes and offsets for all 13 structs plus all seven HMTL_MSG_*_LEN
macros are identical under host clang 21, host clang 21 -fpack-struct=1,
host g++ 16, host g++ 16 -fpack-struct=1, avr-g++ 9.5 -mmcu=atmega328p,
PlatformIO's avr-g++ 8.5 -mmcu=atmega328p and PlatformIO's
xtensa-esp32-elf-g++ 8.4. Before this change the same check failed on every
32-bit configuration.

Part of aphelps/WLED_dev#20

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* pin every wire size and offset in a portable native test

Two problems with the native suite as the acceptance check for the wire
header.

It could not run on a fresh clone: Socket.h was resolved solely through a
hardcoded absolute -I into one developer's Arduino libraries directory, and
this PR makes Socket.h a hard dependency of HMTLWireFormat.h (and therefore
of HMTLTypes.h) rather than only of HMTLMessaging.h. Vendored a
stubs/Socket.h alongside the Arduino/RS485Utils/PixelUtil/FastLED stubs
already there - its body is byte-identical to ArduinoLibs' Socket.h - and
dropped the absolute path. Every include path in [env:native] is now
repo-relative.

It checked nothing about layout: the packing invariant the previous commit
introduced was prose. test/test_wire_format/ static_asserts the size of all
13 structs, the offset of every named field and all seven HMTL_MSG_*_LEN
macros, so it holds for whatever target the file is compiled for - running
the native suite proves the 32-bit layout, building any module firmware
proves the AVR one. Four runtime cases cover what static_assert cannot:
the byte image of msg_hdr_t, config_hdr_v2_t's interior-padding-free
address at offset 3, the msg_value_t 13/3 bitfield split (packing a struct
with bitfields is the one case where the attribute could move more than
padding), and the 23 B poll response.

pio test -e native: 54 test cases, 54 succeeded (was 50), with no external
include paths.

Part of aphelps/WLED_dev#20

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* document the HMTLprotocol linking requirement and the packing invariant

HMTLTypes.h used to be include-free and HMTLMessaging reached socket_addr_t
through RS485Utils; both now include HMTLWireFormat.h, so HMTLprotocol and
Socket must also be linked into the Arduino libraries directory wherever
HMTLTypes or HMTLMessaging is used. The Arduino IDE and the PlatformIO LDF
resolve the transitive include automatically, but only if the library is
present - someone following the "linked individually" instruction with just
the old set gets a missing-header error.

Also records why the wire structs are packed, what drifted without it, and
how to run the layout test.

Part of aphelps/WLED_dev#20

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]>
aphelps-claude-bot added a commit to aphelps/WLED that referenced this pull request Jul 30, 2026
* add rs485_bridge usermod: wifi <-> RS485 HMTL bridge

New usermod that gives a WLED ESP32 an RS485 port (ArduinoLibs' RS485Socket over
hardware serial) and bridges the HMTL protocol in both directions:

- Master (WiFi -> RS485): a UDP listener on port 21331 accepts raw HMTL frames,
  validates them and transmits them onto the bus. sendMsgTo blocks while it
  flushes the UART (~48 ms for a 64 B payload at 28000 baud), so at most one
  frame goes out per loop() and the rest sit in a 4-slot drop-oldest ring — a
  UDP flood cannot stall the LED refresh.
- Slave (RS485 -> WLED): frames addressed to this node or broadcast drive the
  main segment (RGB / VALUE / a small program-to-effect map) and answer POLL and
  SET_ADDRESS so the bridge is a proper HMTL bus citizen. Sensor broadcasts and
  frames for other nodes are relayed to the last WiFi peer. Everything else is
  counted and ignored.

The wire format and every parsing/queueing decision live in the dependency-free
rs485_bridge_protocol.h (host unit-tested in tests/), mirroring the
sensor_sync_protocol.h split. HMTL's own libraries stay off the build path:
they transitively pull FastLED/PixelUtil/EEPromUtils/MPR121/XBeeSocket, so only
the framing (header, type codes, CRC-8 poly 0xD8) is vendored.

Bounds checking is done in the usermod because RS485Utils' own length checks sit
inside `#if DEBUG_LEVEL >= DEBUG_TRACE` and vanish in release builds. GPIOs are
reserved through PinManager (new PinOwner::UM_RS485_BRIDGE) all-or-nothing, so
the UART is never opened on a half-allocated pin set; note isPinOk() rejects the
default GPIO 16/17 on PSRAM boards, which the readme calls out. UART/pin/baud
changes apply on reboot only — RS485Utils leaks on re-init().

The whole translation unit is guarded on USERMOD_RS485_BRIDGE +
RS485_HARDWARE_SERIAL + ESP32, with an inert placeholder usermod standing in
elsewhere so the `usermods` wildcard env and the per-usermod CI matrix (which
set none of those flags, and have no UART 2 on C3/S2) still build and still get
compile coverage of the protocol header. `[env:usermods]` gains lib_extra_dirs
so the AMPWorks usermods can resolve ArduinoLibs there at all.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* document every rs485_bridge function and the reasoning behind its checks

Addresses the CHANGES_REQUESTED review on #11: every function now
carries a description covering what it does, its params/return where those are
not obvious, and the protocol or hardware constraint a reader needs to follow
it. Inline commentary explains rationale rather than restating the next line.

Particular attention, as requested:

* HMTL wire format — why the CRC must stay a byte-for-byte transcription of
  ArduinoLibs' EEPROM_crc, why rs485b_hmtl_crc() substitutes a zero at offset 1
  (idempotent stamping), why rs485b_hmtl_fmt() needs the payload in place first
  and why sendPollResponse() therefore re-stamps, and the little-endian
  bitfield assumption behind HmtlMsgValue.
* Bounds/validation — rs485b_validate()'s check ordering documented as never
  reading a byte it has not already justified; the per-payload length re-checks
  in rs485b_decide() explained as non-redundant with validation; the three
  socket-layer tests in serviceRs485() spelled out, including that RS485Utils'
  own checks are compiled out of release builds; rs485b_next_sensor()'s two
  bounds tests framed as what makes a hostile data_len harmless.
* Blocking-send rate limiting — why sendMsgTo() cannot release DE early on a
  half-duplex bus, the ~48 ms figure it implies, why that makes one frame per
  loop() the safe budget, and why the queue is drop-oldest (freshest lighting
  command is the one worth delivering) and fixed-size (no heap in a usermod
  running for months).
* PinManager path — why an unregistered pin is one the LED-bus settings page
  will hand to a strip, why allocateMultiplePins()' all-or-nothing rollback
  matters, and the isPinOk()/PSRAM interaction that makes the RX16/TX17
  defaults fail on WROVER boards.

Comments only; no behaviour change. Host tests pass, ampworks and usermods
envs build clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* import the HMTL wire format instead of vendoring it

Answers the review question on rs485_bridge_protocol.h: "Why isn't this
imported from the HMTL libraries? Seems like a lot of unnecessary copy
and paste."

The header no longer declares the wire format at all. It includes
HMTLWireFormat.h from the HMTL submodule -- extracted upstream in
aphelps/HMTL#6 for exactly this purpose -- and all ~150 vendored lines
are gone: msg_hdr_t, output_hdr_t, config_hdr_t, the msg_* payload
structs, MSG_TYPE_* / MSG_FLAG_*, HMTL_OUTPUT_*, HMTL_PROGRAM_*,
HMTL_SENSOR_*, HMTL_MSG_START / _VERSION / _MAX_MSG_LEN. There is now
one definition of the format, in the repo that owns it, and the local
Hmtl* struct spellings are replaced by HMTL's own names throughout the
usermod and the test.

What stays in rs485_bridge_protocol.h is bridge-specific: frame
validation, the pure receive-path decision function, the bounded
transmit queue and the counters -- plus two algorithm reimplementations
that cannot be linked rather than declarations that were copied:

  * rs485b_crc8() -- ArduinoLibs' EEPROM_crc lives in EEPromUtils.cpp
    behind AVR-only EEPROM.h and is not inline, so neither the ESP32
    firmware nor the host test can link it.
  * rs485b_hmtl_fmt() / rs485b_next_sensor() -- the HMTL equivalents
    (hmtl_msg_fmt, hmtl_next_sensor) live in HMTLMessaging.cpp behind
    Debug.h and HMTLPrograms.h -> FastLED.h.

Both are pinned by the host test, which now compiles the real HMTL and
ArduinoLibs headers with a plain c++ -- making it the standing check
that HMTLWireFormat.h stays free of Arduino.h / RS485Utils.h.

Behaviour notes:

  * The POLL response length is now HMTL's own HMTL_MSG_POLL_MIN_LEN,
    i.e. exactly what hmtl_poll_fmt() puts on the wire for this target:
    24 bytes on ESP32 where uint16_t alignment adds a trailing pad byte
    to msg_poll_response_t, versus the 23 the packed vendored copy
    emitted. Only trailing padding differs, so every field still lands
    at the same offset for a legacy master.
  * rs485_bridge_protocol.h is no longer compiled in the flagless
    builds ([env:usermods] and the per-usermod CI matrix): it now
    depends on the HMTL submodule, which is only on the build path in
    the ampworks env and is not cloned by the CI workflows. The inert
    placeholder usermod still provides the DWARF compilation unit that
    validate_modules.py requires, and the wire-layout static_asserts are
    covered by `pio run -e ampworks` and the host test instead.

Build wiring: ../HMTL/Libraries added to lib_extra_dirs and
../HMTL/Libraries/HMTLprotocol to lib_deps in [env:ampworks] only, with
a comment on [env:usermods] explaining why it is deliberately absent
there.

Also fixes the four comment-accuracy points from review 4793843525:

  * loop() -- the receive/transmit/ingest order is not what enforces the
    rate limit; serviceTx()'s one-frame budget is. Reworded.
  * handleDecision() -- rs485Handled is weaker than "a v1 command was
    executed against local state"; the PROGRAM-bails-inside-applyProgram
    and SENSOR-only-relays caveats are now stated.
  * rs485b_next_sensor() -- the no-wrap guarantee comes from the operand
    ranges under size_t arithmetic, not from signed int promotion.
  * getId() -- described, on both the main class and the placeholder.

Test: host test 50-odd assertions pass under
  c++ -std=c++11 -Wall -Wextra -I HMTL/Libraries/HMTLprotocol \
      -I ArduinoLibs/Socket ...
sensor_sync host test still passes; pio run green for ampworks,
esp32dev, usermods, apa102_mpr121 and the usermods_esp32{c3,s2,s3} CI
matrix; no new warnings.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* pin msg_poll_response_t layout in the host test; correct the packed-struct comment

Two review nits from wled#11 self-review 4794753753.

Comment accuracy: the static_assert block claimed HMTL declares all eight
asserted structs without __attribute__((packed)). False for output_hdr_t,
which HMTLWireFormat.h:130 does declare packed -- and which is embedded in
msg_value_t / msg_rgb_t / msg_program_t, so the wrong claim covered exactly
the structs a reader cares most about. The assertions themselves are
unchanged; only the rationale was wrong.

Suggested test, routed into the plan's Test Plan and run: msg_poll_response_t
is the one wire struct the assert block deliberately omits, because its size
is ABI-dependent (config_hdr_t is 10 B with align 1 on AVR, align 2 where
uint16_t demands it, so the struct is 15 B or 16 B). The claim that only
trailing padding differs and every field offset is identical was prose in the
header and in the plan's hardware-test note. Group 1 of the host test now
asserts offsetof for all five fields (0/10/12/14/15), bounds sizeof to 15 or
16, and ties HMTL_MSG_POLL_MIN_LEN to the two struct sizes. An upstream
HMTLWireFormat.h edit that moves a field now fails the host test; legitimate
padding drift still passes. Verified on both ABIs -- plain c++ and the same
build with -fpack-struct=1 -- both ALL TESTS PASSED.

Comments and tests only, zero behaviour change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* pin the wire layout to the now-uniform packed sizes

HMTL now declares every wire struct __attribute__((__packed__))
(aphelps/HMTL#6, per Adam's directive that one format has to serve both an
ATMega328 and an ESP32 because they are communicating), which changes struct
sizes on this side.

rs485_bridge_protocol.h's static_assert block is updated to the uniform
values and its rationale rewritten. It used to say output_hdr_t was the only
packed struct, that the other seven relied on their field ordering happening
to avoid padding, and that msg_poll_response_t was "the one struct whose size
is ABI-dependent" and therefore exempt. None of that is true any more: there
is no struct left to exempt, so msg_poll_response_t (15 B) and
HMTL_MSG_POLL_MIN_LEN (23) are asserted like the rest, along with
config_hdr_v1/v2_t and the two zero-size FAM structs. The wire-visible
consequence is that the bridge's POLL response is 23 B rather than 24 B -
byte-for-byte what a deployed AVR module emits and length-checks.

Host test group 1 now pins the exact size and every field offset of every
wire struct rather than bounding msg_poll_response_t to 15-or-16, adds
config_hdr_v2_t (the interior-padding case: address at offset 3, not 4), and
checks the msg_value_t 13/3 bitfield split at byte level - packing a struct
containing bitfields is the one case where the attribute could have moved
more than padding.

Two changes to keep the new "compile with g++ >= 9 as well as clang" gate
warning-free, both zero-behaviour:

* dropped the dead `frameLen > 255` test in rs485b_validate_udp_ingress
  (frameLen is a uint8_t, so g++ -Wtype-limits is right that it can never
  fire; the 255 ceiling sendMsgTo's `byte` length imposes is enforced by the
  type). The maxPayload bound it sat next to is unchanged.
* removed the line continuations from a // comment block (-Wcomment).

readme gains the packing rationale and a local-edit gotcha worth knowing:
HMTLprotocol is a file:// lib_dep, so PlatformIO caches a copy under
.pio/libdeps/<env>/ and an edit to HMTLWireFormat.h has no effect until that
copy is cleared - which means a stale copy silently checks the old layout.

Verified: rs485_bridge_test passes under clang 21 and g++ 16, each with and
without -fpack-struct=1, all four warning-free and reporting identical sizes
and offsets. pio run -e ampworks / esp32dev / usermods / apa102_mpr121 and
the usermods_esp32c3/s2/s3 CI matrix envs all build clean.

Part of aphelps/WLED_dev#20

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* keep RS485Utils out of the usermods wildcard env

`Build Environments (usermods)` failed with

    _temp/ArduinoLibs/RS485Utils/RS485Utils.cpp:17:10:
      fatal error: RS485_non_blocking.h: No such file or directory

The rs485_bridge translation unit is correctly guarded and compiles to
nothing in `[env:usermods]`, but PlatformIO's Library Dependency Finder
runs in `chain` mode, which scans `#include` lines without evaluating
preprocessor conditionals. It sees `#include "RS485Utils.h"` inside the
disabled `#if RS485_BRIDGE_BUILD` block anyway, pulls RS485Utils out of
ArduinoLibs and compiles it — a library nothing in this env links
against. RS485Utils.cpp then includes <RS485_non_blocking.h> above its
own RS485UTILS_SUPPORTED guard, and the CI workflows clone ArduinoLibs'
*default* branch, which does not carry that vendored sibling library
(it lands with aphelps/ArduinoLibs#5). So the build died on a dependency
of a dependency this env never asked for, and LDF fell through to a
registry lookup for it.

`lib_ignore = RS485Utils` drops it from the dependency graph, which is
what actually matches reality here: with the bridge compiled out, no
translation unit in this env can reference an RS485Utils symbol. This
holds in both layouts — the super-repo checkout where
`${PROJECT_DIR}/../ArduinoLibs` resolves, and the standalone CI clone
that appends PLATFORMIO_LIB_EXTRA_DIRS — and it does not depend on
which ArduinoLibs revision CI happens to clone.

Verified by reproducing CI exactly: a standalone clone of this branch
with no `../ArduinoLibs` sibling, built against a clone of ArduinoLibs'
default branch on PLATFORMIO_LIB_EXTRA_DIRS. Fails with the identical
error before this commit; clean-builds after. `pio run -e usermods`,
`-e ampworks`, `-e esp32dev`, `-e apa102_mpr121` and all four
`usermods_esp32*` matrix envs still pass from the super-repo layout.

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 Fable 5 <[email protected]>
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