Skip to content

fix(nodedb): seed and persist the USERPREFS_FIXED_GPS position - #11640

Open
Simplycissmus wants to merge 1 commit into
meshtastic:developfrom
Simplycissmus:fix/userprefs-fixed-gps
Open

fix(nodedb): seed and persist the USERPREFS_FIXED_GPS position#11640
Simplycissmus wants to merge 1 commit into
meshtastic:developfrom
Simplycissmus:fix/userprefs-fixed-gps

Conversation

@Simplycissmus

@Simplycissmus Simplycissmus commented Aug 28, 2026

Copy link
Copy Markdown

The USERPREFS_FIXED_GPS block in NodeDB.cpp was broken four ways. It did not compile: the satellite-map insert uses info->num with info undeclared in that scope. It called nodeDB->setLocalPosition() from inside the NodeDB constructor, where the global nodeDB pointer is still null — a store through null this, which panics with a store-access fault on ESP32-C6 and segfaults the native build. It ran after the boot save decision, so even a successful seed was never written to flash. And it was gated on myNodeInfo.reboot_count == 1, an ESP32-only NVS counter that is >1 after any non-erase reflash, so the path effectively never ran on real devices.

This change moves the feature to where the other USERPREFS_ defaults live: installDefaultConfig() turns config.position.fixed_position on when the defines are present, and the constructor's existing "restore persisted position" block seeds the compiled-in coordinates via updatePosition() when fixed_position is on but no self position is stored, ORing SEGMENT_CONFIG | SEGMENT_NODEDATABASE into saveWhat (the nodePositions satellite map is not covered by the nodeDatabase CRC compare). A position set or removed from the app wins on later boots.

Tests: new native suite test_fixed_gps_userprefs, run in two flavours. The plain coverage env (no defines) covers 3 cases: no position appears from nowhere, an app-set fixed position is restored after reboot, remove stays removed. The new coverage-fixed-gps env (defines set) covers 5 cases: first boot seeds and persists, reboot restores, app override survives reboot, a lost self position is re-seeded, remove stays removed. On unfixed code the seeded suite segfaults in the first new NodeDB(). CI runs it as its own step, mirroring the existing coverage steps.

Tested on hardware: Seeed XIAO ESP32-C6 DIY node. After erase+flash, the first boot seeded and persisted the position; the next boot logged "Restored fixed position", and the CLI shows fixedPosition true with the compiled-in coordinates. No Heltec/RAK hardware available.

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

Tested on Other: Seeed XIAO ESP32-C6 DIY (LLCC68).

Summary by CodeRabbit

  • New Features

    • Added support for configuring a fixed GPS position at build time.
    • Fixed GPS coordinates are automatically initialized and persisted when no position is already stored.
    • Existing position updates and removals continue to override the configured default.
  • Tests

    • Added comprehensive coverage for first-boot setup, reboot restoration, overrides, reseeding, and builds without fixed GPS preferences.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f5334ff8-fca7-4744-87ce-84d68c493698

📥 Commits

Reviewing files that changed from the base of the PR and between 7aa8ad3 and a11455b.

⛔ Files ignored due to path filters (1)
  • test/state-manifest.tsv is excluded by !**/*.tsv
📒 Files selected for processing (4)
  • .github/workflows/test_native.yml
  • src/mesh/NodeDB.cpp
  • test/test_fixed_gps_userprefs/test_main.cpp
  • variants/native/portduino/platformio.ini

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds a native fixed-GPS test environment, seeds compiled coordinates into NodeDB when no stored position exists, persists the state, and tests reboot, override, removal, reseeding, and vanilla-build behavior.

Changes

Fixed GPS user preferences

Layer / File(s) Summary
Fixed GPS configuration and seeding
variants/native/portduino/platformio.ini, src/mesh/NodeDB.cpp
The new coverage-fixed-gps environment defines fixed coordinates. NodeDB enables fixed positioning and seeds the coordinates when no stored position exists.
Fixed GPS behavior tests
test/test_fixed_gps_userprefs/test_main.cpp
Tests cover first-boot persistence, reboot restoration, application overrides and removals, reseeding after position loss, and vanilla builds.
Native coverage validation
.github/workflows/test_native.yml
The workflow runs the fixed-GPS suite and verifies test attribution in the generated report.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: 🟡 Moderate · up to a1145

This change makes compiled fixed GPS coordinates seed and persist correctly, but interruption during separate writes, encrypted-storage reload, or tracker startup cleanup can still leave location state missing, stale, or replaced. Because that state may be emitted by the device, the PR needs these lifecycle cases addressed or explicitly accepted before merge.

Sequence Diagram(s)

sequenceDiagram
  participant FixedGPSTests
  participant NodeDB
  participant NodeDBStorage
  FixedGPSTests->>NodeDB: initialize baked or vanilla build
  NodeDB->>NodeDBStorage: read persisted configuration and position
  NodeDB->>NodeDBStorage: save seeded or application-updated position
  FixedGPSTests->>NodeDB: simulate reboot and assert coordinates
Loading

Suggested reviewers: thebentern

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 2 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: seeding and persisting the USERPREFS_FIXED_GPS position in NodeDB.
Description check ✅ Passed The description is complete and directly related to the changes. It explains the defects, implementation, test coverage, hardware validation, and unavailable regression devices. The required attestati…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and directly related to the changes. It explains the defects, implementation, test coverage, hardware validation, and unavailable regression devices. The required attestations are included with the tested device identified.

Full details: Docstring Coverage

Explanation

Docstring coverage is 23.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 2 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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