fix: pad short PAN IDs for the XBee, and force router role at boot - #50
Merged
Merged
Conversation
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>
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.
Summary
4133could be entered, saved and displayed, but switching to it failed with "Set PAN failed" —XbeeControl::setPanIdrequires exactly 16 hex digits and rejected it before anything reached the radio. The boot-time droid-name lookup alsostrcmp'd the saved4133against the module's0000000000004133, so the Droid Name complication showed "(none)" after every reboot.PanId::normalize/PanId::equivalent(uppercase, left-pad to 16).DroidSwitcher::switchTopads before calling the transport; an invalid ID returns the newkInvalidPanId("Invalid PAN ID") without touching the network.DroidStore::findByPanId, used bySnipsController.inoat boot in place ofstrcmp.ensureRouterRole()reads the XBee'sCE; if it isn't 0 it writesCE=0, thenWRandAC. Failures are logged to Serial and boot continues.Notes for review
CE→WR→ACsequence inXbeeControlis best-effort against Digi's manual and not yet validated on hardware (same caveat the class already carries). Worth confirming during bring-up thatACis enough for a coordinator→router change to take effect, versus needing a reset.CE=0means "join a network"; whether the module ends up a router or an end device is governed bySM(sleep mode). This PR only checks/setsCE, as requested.4133); padding happens only when talking to the radio or comparing.Test plan
pio test -e native— 252 passed, including newtest_pan_idandtest_xbee_rolesuites and regression tests intest_droid_store,test_droid_switcherandtest_menupio run -e esp32s3builds (covers.inoandxbee_control.cpp, which aren't compiled natively)🤖 Generated with Claude Code