Skip to content

fix: pad short PAN IDs for the XBee, and force router role at boot - #50

Merged
thePunderWoman merged 2 commits into
mainfrom
fix/pan-id-padding-and-router-role
Sep 19, 2026
Merged

thePunderWoman merged 2 commits into
mainfrom
fix/pan-id-padding-and-router-role

Conversation

@thePunderWoman

@thePunderWoman thePunderWoman commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Short PAN IDs now work end to end. A PAN ID like 4133 could be entered, saved and displayed, but switching to it failed with "Set PAN failed" — XbeeControl::setPanId requires exactly 16 hex digits and rejected it before anything reached the radio. The boot-time droid-name lookup also strcmp'd the saved 4133 against the module's 0000000000004133, so the Droid Name complication showed "(none)" after every reboot.
    • New pure PanId::normalize / PanId::equivalent (uppercase, left-pad to 16).
    • DroidSwitcher::switchTo pads before calling the transport; an invalid ID returns the new kInvalidPanId ("Invalid PAN ID") without touching the network.
    • New DroidStore::findByPanId, used by SnipsController.ino at boot in place of strcmp.
    • Finishing PAN ID entry with nothing typed now restarts the entry rather than saving an ID that pads to all zeros (Factory Reset's "unconfigured" value).
  • Router role enforced at boot. New ensureRouterRole() reads the XBee's CE; if it isn't 0 it writes CE=0, then WR and AC. Failures are logged to Serial and boot continues.

Notes for review

  • The CEWRAC sequence in XbeeControl is best-effort against Digi's manual and not yet validated on hardware (same caveat the class already carries). Worth confirming during bring-up that AC is enough for a coordinator→router change to take effect, versus needing a reset.
  • CE=0 means "join a network"; whether the module ends up a router or an end device is governed by SM (sleep mode). This PR only checks/sets CE, as requested.
  • Stored PAN IDs stay as typed (4133); padding happens only when talking to the radio or comparing.

Test plan

  • pio test -e native — 252 passed, including new test_pan_id and test_xbee_role suites and regression tests in test_droid_store, test_droid_switcher and test_menu
  • pio run -e esp32s3 builds (covers .ino and xbee_control.cpp, which aren't compiled natively)
  • Coverage: 97.9% line coverage locally via gcovr with the CI filters (threshold 90%); all new files at 100%
  • On hardware: switch to a droid saved as a short PAN ID; boot with CE=1 and confirm it comes up as a router

🤖 Generated with Claude Code

thePunderWoman and others added 2 commits September 19, 2026 08:43
Short PAN IDs (e.g. "4133") could be saved and displayed, but switching
to one failed with "Set PAN failed": XbeeControl::setPanId requires
exactly 16 hex digits and rejected it before sending anything. The
boot-time droid-name lookup also strcmp'd the saved "4133" against the
module's zero-padded "0000000000004133", so it never matched.

- Add PanId::normalize/equivalent (pure, tested): uppercase + left-pad
  to 16 digits.
- DroidSwitcher pads before calling the transport; invalid IDs now
  report "Invalid PAN ID" without touching the network.
- DroidStore::findByPanId does the boot-time match with equivalent();
  the .ino uses it instead of strcmp.
- Manage Droids: finishing PAN ID entry with nothing typed restarts the
  entry instead of saving an ID that would pad to all zeros (the
  "unconfigured" value Factory Reset uses).

Also, at boot, read the XBee's CE parameter and, if it isn't 0 (router),
write CE=0, WR, AC. The check is pure (ensureRouterRole over an
XbeeRoleTransport) with the AT sequencing in XbeeControl.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@thePunderWoman
thePunderWoman merged commit 10aa9a1 into main Sep 19, 2026
2 checks passed
@thePunderWoman
thePunderWoman deleted the fix/pan-id-padding-and-router-role branch September 19, 2026 15:50
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.

1 participant