Skip to content

gps: route GPS_DEBUG diagnostics through a LOG_DEBUG_GPS() macro - #11414

Merged
jp-bennett merged 1 commit into
claude/meshtastic-logging-trace-gatefrom
claude/meshtastic-gps-debug-macro
Aug 11, 2026
Merged

gps: route GPS_DEBUG diagnostics through a LOG_DEBUG_GPS() macro#11414
jp-bennett merged 1 commit into
claude/meshtastic-logging-trace-gatefrom
claude/meshtastic-gps-debug-macro

Conversation

@jp-bennett

@jp-bennett jp-bennett commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Third installment of the logging work (#11374#11391 → this). Based on #11391's branch since both touch GPS.cpp; retarget to develop after #11391 merges.

What: replaces the 27 log-only #ifdef GPS_DEBUG / log / #endif triples across GPS.cpp, PositionModule.cpp, MeshService.cpp, and GPSStatus.h with single-line LOG_DEBUG_GPS(...) calls. The macro lives in new src/gps/GPSLog.h, modeled on LOG_MIGRATION: value-gated (#ifndef default 0, #if GPS_DEBUG test, so -DGPS_DEBUG=0 explicitly disables), ((void)0) off-branch (safe in braceless if/else). When the gate is off the macro's arguments vanish at preprocessing, so call sites referencing gated-only variables (the debugmsg probe dumps) still compile.

Deliberately NOT converted (kept as explicit #if GPS_DEBUG blocks, flipped from #ifdef to value tests): the debugmsg/response accumulation declarations, blocks wrapping control flow, the block that also calls DEBUG_PORT.hexDump, the gate that spans an else if clause, the AGE: log with preprocessor conditionals nested in its argument list, and the inverted #ifndef GPS_DEBUG checksum-threshold gate (behavioral, not verbosity). The handful of gated LOG_INFO/LOG_WARN diagnostics unify to the single DEBUG-level macro — they're opt-in diagnostics, so the level tag is incidental.

Also:

  • src/gps/RTC.cpp's per-reading raw time dumps (RV3028/RX8130CE get/set) and per-candidate rejection chatter fold under the same gate (−432 B on rak4631, measured); RTC-quality transitions and boot-time seeding stay at DEBUG.
  • Fixes the // define GPS_DEBUG missing-# typo in two variant headers (uncommenting them silently did nothing) and updates all seven commented examples to the value form #define GPS_DEBUG 1.
  • Documents the tiering convention in .github/copilot-instructions.md: LOG_TRACE = per-packet firehose (globally gated), LOG_DEBUG_<SUBSYS> = subsystem bring-up detail (per-subsystem gate), anomalies stay unconditional.

Other subsystems (sensors, radio interfaces, input, PhoneAPI) could get the same treatment later — deliberately out of scope here.

🤝 Attestations

  • 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 via native (portduino): full compile green and ./bin/run-tests.sh GREEN 47/47 suites, all CLEAN. rak4631 compiles in both gate states — default (GPS_DEBUG=0, 768,188 B vs 768,620 B base) and -DGPS_DEBUG=1 (exercises every converted call site, including the gated-variable consumers). Behavior surface is log output only; no runtime logic touched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Added a dedicated GPS diagnostic logging channel with configurable enablement.
    • Enabled GPS debug output for selected device variants.
  • Improvements

    • Standardized GPS, RTC, positioning, and lost-lock diagnostics under the GPS-specific logging channel.
    • Clarified logging guidance for trace, debug, warning, and error messages.
    • GPS functionality and control flow remain unchanged.

Replaces 27 log-only #ifdef GPS_DEBUG blocks across GPS.cpp,
PositionModule, MeshService, and GPSStatus.h with a single-line
LOG_DEBUG_GPS() call (src/gps/GPSLog.h, modeled on LOG_MIGRATION:
value-gated, ((void)0) when off). Blocks containing declarations,
control flow, hexDump, or nested conditionals keep an explicit
'#if GPS_DEBUG' guard. RTC.cpp's per-reading raw time dumps and
per-candidate rejection chatter fold under the same gate; quality
transitions and boot-time seeding stay at debug.

Also fixes the '// define GPS_DEBUG' missing-# typo in two variant
headers and updates all seven commented examples to the value form
('#define GPS_DEBUG 1') required by the value-based gate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1
@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Note

Building this pull request… the flash button, badges and supported-board
list will appear here automatically once CI finishes.

@coderabbitai

coderabbitai Bot commented Aug 11, 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: 3632bf70-8ced-4585-a370-0270aa7ded62

📥 Commits

Reviewing files that changed from the base of the PR and between 533361f and 5e16422.

📒 Files selected for processing (14)
  • .github/copilot-instructions.md
  • src/GPSStatus.h
  • src/gps/GPS.cpp
  • src/gps/GPSLog.h
  • src/gps/RTC.cpp
  • src/mesh/MeshService.cpp
  • src/modules/PositionModule.cpp
  • variants/esp32/chatter2/variant.h
  • variants/esp32/tbeam/variant.h
  • variants/nrf52840/diy/nrf52_promicro_diy_tcxo/variant.h
  • variants/nrf52840/dls_Minimesh_Lite/variant.h
  • variants/nrf52840/seeed_wio_tracker_L1/variant.h
  • variants/nrf52840/seeed_wio_tracker_L1_eink/variant.h
  • variants/nrf52840/t-echo-lite/variant.h

📝 Walkthrough

Walkthrough

The PR adds the LOG_DEBUG_GPS channel and GPS_DEBUG switch. GPS, RTC, mesh, and position diagnostics use the new channel. Variant headers explicitly enable or disable GPS debugging.

Changes

GPS diagnostic logging

Layer / File(s) Summary
Logging contract
.github/copilot-instructions.md, src/gps/GPSLog.h
Defines GPS-specific debug logging and documents diagnostic logging tiers.
GPS core diagnostics
src/GPSStatus.h, src/gps/GPS.cpp
Migrates GPS protocol, fix, probe, power, checksum, and serial-buffer diagnostics to LOG_DEBUG_GPS.
GPS-related integrations
src/gps/RTC.cpp, src/mesh/MeshService.cpp, src/modules/PositionModule.cpp
Migrates RTC, lost-lock, position-send, and smart-broadcast diagnostics to LOG_DEBUG_GPS.
Variant debug configuration
variants/esp32/*/variant.h, variants/nrf52840/*/variant.h
Updates variant-level GPS_DEBUG definitions and enablement.

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

Possibly related PRs

Suggested labels: cleanup

Suggested reviewers: thebentern, nomdetom, caveman99

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes routing GPS diagnostics through the new LOG_DEBUG_GPS macro.
Description check ✅ Passed The description explains the changes, scope, testing results, and attestations with sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/meshtastic-gps-debug-macro

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.

@jp-bennett jp-bennett added the cleanup Code cleanup or refactor label Aug 11, 2026 — with Claude
@jp-bennett
jp-bennett merged commit 377370b into claude/meshtastic-logging-trace-gate Aug 11, 2026
7 of 9 checks passed
@jp-bennett
jp-bennett deleted the claude/meshtastic-gps-debug-macro branch August 11, 2026 19:24
daniel-gallagher pushed a commit to daniel-gallagher/meshtastic_firmware that referenced this pull request Aug 12, 2026
… drop redundant logs (meshtastic#11391)

* logging: gate LOG_TRACE behind MESHTASTIC_TRACE_LOGGING, drop redundant reclock logs

LOG_TRACE now compiles out by default so trace-level diagnostics cost no
flash; enable with -DMESHTASTIC_TRACE_LOGGING. Portduino keeps it on for
the traceFilename packet-trace feature.

Remove the 66 caller-side I2C reclock/restore log lines in the telemetry
sensors: ReClockI2C::setClock/restoreClock already log both frequencies
internally (now at trace level, since they fire every sensor read).

Also unify near-duplicate literals (colon/case/punctuation variants) so
linker string dedup applies, and drop an information-free bare 'done'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* logging: demote chatty per-packet/per-poll DEBUG lines to trace level

With LOG_TRACE compiled out by default, per-iteration chatter (packet
bookkeeping, sensor poll values, e-ink refresh reasons, GPS pin states,
UI runState traces) now costs no flash on device builds while remaining
one -DMESHTASTIC_TRACE_LOGGING away. 108 lines demoted, 4 information-
free lines removed; failure paths, drop reasons, and one-time init logs
all stay at debug level.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* logging: address CodeRabbit review on trace-gate PR

- GPS: pass serial-derived buffers as %s args, never as format strings
  (untrusted bytes could contain % directives)
- 0x%08x for packet id / NodeNum per convention (Router, CannedMessage,
  NeighborInfo); unsigned casts for size_t args; %u for uint32_t delta
- EInk: async full-refresh begin/complete back to DEBUG (rare state
  transitions); per-frame SKIPPED lines stay trace

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* logging: gate trace on the flag's value, not its presence

-DMESHTASTIC_TRACE_LOGGING=0 previously *enabled* trace logging because
the gate tested definedness. The flag now defaults per-platform
(portduino 1, else 0) and both backends test the value, so =0 disables,
=1 or a bare -D enables. Also cast tx_after-millis() to uint32_t for %u
(millis() is unsigned long on native).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* logging: clang-format rewrap after specifier widening

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* Even fewer bytes!

* logging: keep compile-gated debug lines at debug level; fix native-suite-count

Lines already inside default-off #ifdef blocks (GPS_DEBUG,
DEBUG_LOOP_TIMING) cost no flash and should stay visible at debug level
when their gate is enabled, rather than also requiring
MESHTASTIC_TRACE_LOGGING.

test/native-suite-count lags the two test_event_channel_* suites added
by meshtastic#11045 (develop's Native Suite Count check has the same mismatch);
bump 46 -> 47.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

* gps: route GPS_DEBUG diagnostics through a LOG_DEBUG_GPS() macro (meshtastic#11414)

Replaces 27 log-only #ifdef GPS_DEBUG blocks across GPS.cpp,
PositionModule, MeshService, and GPSStatus.h with a single-line
LOG_DEBUG_GPS() call (src/gps/GPSLog.h, modeled on LOG_MIGRATION:
value-gated, ((void)0) when off). Blocks containing declarations,
control flow, hexDump, or nested conditionals keep an explicit
'#if GPS_DEBUG' guard. RTC.cpp's per-reading raw time dumps and
per-candidate rejection chatter fold under the same gate; quality
transitions and boot-time seeding stay at debug.

Also fixes the '// define GPS_DEBUG' missing-# typo in two variant
headers and updates all seven commented examples to the value form
('#define GPS_DEBUG 1') required by the value-based gate.


Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

Co-authored-by: Claude <noreply@anthropic.com>

* gps: declare RTC gmtime result as pointer to const (cppcheck)

With the setTime debug dump gated behind GPS_DEBUG, all remaining uses
of t are reads; cppcheck (constVariablePointer) now flags it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LBiZc9sfPrH1MZ2L3Fxgt1

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanup or refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants