From b6a5171357d92da69cfd88acd9eec473ca52b8e9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 25 Apr 2026 11:06:35 +0000 Subject: [PATCH] Fix searchedTooLong: move 15-min cap before UINT32_MAX check, cache elapsed, add constexpr Agent-Logs-Url: https://github.com/meshtastic/firmware/sessions/b7f74430-9e7e-4a6f-8095-6176c1eee972 Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- src/gps/GPSUpdateScheduling.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gps/GPSUpdateScheduling.cpp b/src/gps/GPSUpdateScheduling.cpp index 525d72a31..bf44caa8a 100644 --- a/src/gps/GPSUpdateScheduling.cpp +++ b/src/gps/GPSUpdateScheduling.cpp @@ -70,25 +70,28 @@ bool GPSUpdateScheduling::isUpdateDue() // Have we been searching for a GPS position for too long? bool GPSUpdateScheduling::searchedTooLong() { + constexpr uint32_t maxSearchClampMs = 1000UL * 60 * 15; // Hard cap: 15 minutes is always too long + uint32_t elapsed = elapsedSearchMs(); + + // Anything over 15 minutes is too long, regardless of the broadcast interval. + // TODO: Make a smarter algorithm that backs off the search dwell time when not getting a lock. + if (elapsed > maxSearchClampMs) + return true; + uint32_t minimumOrConfiguredSecs = Default::getConfiguredOrMinimumValue(config.position.position_broadcast_secs, default_broadcast_interval_secs); uint32_t maxSearchMs = Default::getConfiguredOrDefaultMs(minimumOrConfiguredSecs, default_broadcast_interval_secs); + // If broadcast interval set to max, no such thing as "too long" if (maxSearchMs == UINT32_MAX) return false; // If we've been searching longer than our position broadcast interval: that's too long - else if (elapsedSearchMs() > maxSearchMs) - return true; - - // Anything over 15 minutes is too long. TODO: Make a smarter algorithm that backs off the search dwell time when not getting - // a lock. - else if (elapsedSearchMs() > 1000 * 60 * 15) + if (elapsed > maxSearchMs) return true; // Otherwise, not too long yet! - else - return false; + return false; } // Updates the predicted time-to-get-lock, by exponentially smoothing the latest observation