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 2 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,32 @@ | ||
| /** | ||
| * @file Time.cpp | ||
| * @brief Monotonic uptime clock with test injection and a rollover-immune 64-bit form. | ||
| * | ||
| * getMillis() is a thin wrapper over the platform millis() (or the injected test clock). | ||
| * getMillis64() extends it to 64 bits with a software carry: it samples the 32-bit clock and | ||
| * bumps a high word each time the low word wraps. The sampler must be polled at least once per | ||
| * ~49.7-day wrap window to catch every wrap - trivially satisfied by normal device activity. | ||
| * It keeps mutable static state, so it is not ISR-safe (documented in Time.h). | ||
| */ | ||
| #include "Time.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(); | ||
| 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,61 @@ | ||
| #pragma once | ||
| #ifndef _MT_TIME_H | ||
| #define _MT_TIME_H | ||
|
|
||
| #include <Arduino.h> | ||
|
|
||
| /** | ||
| * Monotonic uptime clock - the single seam for "milliseconds since boot". | ||
| * | ||
| * Why this exists: | ||
| * - Test injection: any unit test can drive a virtual timebase via setTestMillis() / | ||
| * advanceTestMillis() instead of sleeping real seconds. One seam for all suites - no | ||
| * per-module test clock (this replaces the ad-hoc HopScalingModule::s_testNowMs / | ||
| * TrafficManagementModule::clockMs patterns). | ||
| * - Rollover immunity: getMillis64() never wraps (uint32 millis() wraps at ~49.7 days, which | ||
| * routers/repeaters exceed). Use it for any "duration over days" logic. | ||
| * | ||
| * This is uptime, NOT wall-clock. For wall-clock seconds (RTC/GPS/NTP) use getTime() in | ||
| * src/gps/RTC.h - a separate axis that can jump and be unset. | ||
| * | ||
| * Hot/ISR paths use getMillis() (32-bit, a drop-in for millis(), rollover-safe only with the | ||
| * unsigned-subtraction idiom `(uint32_t)(now - then)`). getMillis64() keeps mutable static | ||
| * carry state and is NOT ISR-safe - call it from normal task context only. | ||
| * An interrupt landing mid-update of that state (a read-then-write with no locking) could tear | ||
| * it, corrupting the high word for every caller afterward, not just the interrupted one. | ||
| */ | ||
| namespace Time | ||
| { | ||
| #ifdef PIO_UNIT_TESTING | ||
| // Test-only virtual clock. Default: OFF - getMillis() returns real millis() so suites that | ||
| // rely on real time are unaffected by the seam. A test opts in by calling setTestMillis(). | ||
| inline uint32_t testNowMs = 0; | ||
| inline bool useTestClock = false; | ||
|
|
||
| inline void setTestMillis(uint32_t ms) | ||
| { | ||
| testNowMs = ms; | ||
| useTestClock = true; | ||
| } | ||
| inline void advanceTestMillis(uint32_t deltaMs) | ||
| { | ||
| 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; | ||
| } | ||
| #endif | ||
|
|
||
| /// Milliseconds since boot, 32-bit (wraps ~49.7 days). Drop-in for millis(). | ||
| uint32_t getMillis(); | ||
|
|
||
| /// Milliseconds since boot, 64-bit, rollover-immune. Non-ISR use only. | ||
| uint64_t getMillis64(); | ||
|
|
||
| } // namespace Time | ||
|
|
||
| #endif | ||
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
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.