Repository navigation
Arrival time fix perhaps #11274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thebentern
merged 9 commits into
meshtastic:develop
from
NomDeTom:arrival-time-fix-perhaps
Jul 29, 2026
Merged
Arrival time fix perhaps #11274
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
af117da
Add explicit presence for MeshPacket.rx_time (arrival time)
NomDeTom 50742ed
Dedupe rx_time stamping into a shared helper; trim a debug log string
NomDeTom bd44b4e
Fix has_rx_rssi presence carried unconditionally through StoreForward…
NomDeTom 54597e9
Trim comment blocks to the repo's 1-2 line guideline
NomDeTom cc02d57
Add rx_time explicit-presence test coverage
NomDeTom c81f711
Fix three correctness issues flagged in review
NomDeTom 2cdd0b0
tryfix CI
NomDeTom cdd14a4
post review fixes
NomDeTom 2cc646e
more test fixes
NomDeTom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // See UptimeClock.h for the full contract. | ||
| #include "UptimeClock.h" | ||
| #include <Arduino.h> | ||
|
|
||
| uint32_t Time::getMillis() | ||
| { | ||
| #ifdef PIO_UNIT_TESTING | ||
| if (Time::useTestClock) | ||
| return Time::testNowMs; | ||
| #endif | ||
| return millis(); | ||
| } | ||
|
|
||
| uint64_t Time::getMillis64() | ||
| { | ||
| static uint32_t lastLow = 0; // last 32-bit sample | ||
| static uint32_t highWord = 0; // number of observed wraps | ||
|
|
||
| uint32_t now = Time::getMillis(); | ||
| #ifdef PIO_UNIT_TESTING | ||
| // A test swapping clock sources (real <-> injected) can make `now` jump backward for | ||
| // reasons other than a genuine wrap - rebase rather than miscount it as one. | ||
| if (Time::clockSourceChanged) { | ||
| lastLow = now; | ||
| highWord = 0; | ||
| Time::clockSourceChanged = false; | ||
| } | ||
| #endif | ||
| if (now < lastLow) | ||
| highWord++; // low word wrapped since last call | ||
| lastLow = now; | ||
| return (static_cast<uint64_t>(highWord) << 32) | now; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| // Monotonic uptime clock, injectable so tests can drive a virtual timebase instead of sleeping. | ||
| // Uptime only; see gps/RTC.h for wall-clock. Not named Time.h: -Isrc would shadow C's <time.h>. | ||
| namespace Time | ||
| { | ||
| #ifdef PIO_UNIT_TESTING | ||
| // Test-only virtual clock; OFF by default so suites relying on real time are unaffected. | ||
| inline uint32_t testNowMs = 0; | ||
| inline bool useTestClock = false; | ||
| inline bool clockSourceChanged = true; // forces getMillis64() to rebase its wrap accumulator | ||
|
|
||
| inline void setTestMillis(uint32_t ms) | ||
| { | ||
| testNowMs = ms; | ||
| useTestClock = true; | ||
| clockSourceChanged = true; | ||
| } | ||
| inline void advanceTestMillis(uint32_t deltaMs) | ||
| { | ||
| // Advancing from 0 after getMillis64() sampled the real clock steps backward, which would | ||
| // otherwise be miscounted as a wrap. | ||
| if (!useTestClock) | ||
| clockSourceChanged = true; | ||
| testNowMs += deltaMs; | ||
| useTestClock = true; | ||
| } | ||
| // Restore real-clock behaviour (call in test tearDown if a suite mixes real and fake time). | ||
| inline void useRealClock() | ||
| { | ||
| useTestClock = false; | ||
| testNowMs = 0; | ||
| clockSourceChanged = true; | ||
| } | ||
| #endif | ||
|
|
||
| /// Milliseconds since boot, 32-bit (wraps ~49.7 days). Drop-in for millis(). | ||
| uint32_t getMillis(); | ||
|
|
||
| /// Milliseconds since boot, 64-bit, rollover-immune. Must be polled at least once per ~49.7-day | ||
| /// wrap window to catch every wrap, and keeps mutable static carry state, so it is NOT ISR-safe. | ||
| uint64_t getMillis64(); | ||
|
|
||
| } // namespace Time |
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.