9 const int index =
static_cast<int>(source);
13bool GPSCorrectionSelector::_fresh(
const Category& category, qint64 now)
const
16 MonotonicClock::age(std::chrono::milliseconds(category.lastRoutableMs), std::chrono::milliseconds(now));
20bool GPSCorrectionSelector::_eligible(
int index, qint64 now)
const
22 if (index <= 0 || !_fresh(_categories[index], now)) {
28void GPSCorrectionSelector::_select(qint64 now)
32 if (_eligible(index, now)) {
36 if (!_eligible(_active, now)) {
41 if (best < 0 || best >= _active) {
45 if (_candidate != best) {
47 _candidateSinceMs = now;
48 }
else if (
const auto held =
49 MonotonicClock::age(std::chrono::milliseconds(_candidateSinceMs), std::chrono::milliseconds(now));
58 if (_shutdown || _index(source) < 0 || source == _configuredSource) {
61 _configuredSource = source;
69 const int index = _index(source);
70 if (_shutdown || index <= 0) {
74 _categories[index].begun =
true;
79 const int index = _index(source);
83 _categories[index] = {};
88 qint64 receivedAtMs, qint64 now)
90 const int index = _index(source);
91 if (_shutdown || index <= 0 || !_categories[index].begun) {
94 const auto age =
MonotonicClock::age(std::chrono::milliseconds(receivedAtMs), std::chrono::milliseconds(now));
98 Category& category = _categories[index];
99 if (category.instance != instance) {
101 if (_fresh(category, now)) {
104 category.instance = instance;
106 category.lastRoutableMs = (std::max) (category.lastRoutableMs, receivedAtMs);
108 return _active == index;
113 return std::ranges::any_of(_categories, &Category::begun);
118 if (!_eligible(_active, now)) {
constexpr int GPS_CORRECTION_SOURCE_COUNT
static constexpr std::chrono::milliseconds SWITCH_HOLD_DOWN
bool hasSources() const
Whether any source is begun.
bool submit(GPSCorrectionSettings::CorrectionSource source, const QString &instance, qint64 receivedAtMs, qint64 now)
void beginSource(GPSCorrectionSettings::CorrectionSource source, qint64 now)
Starts source. A category has one source at a time, which ends itself before a replacement begins.
std::optional< GPSCorrectionStream > selectedStream(qint64 now) const
The selected fresh stream, if any.
void endSource(GPSCorrectionSettings::CorrectionSource source, qint64 now)
Stops routing source.
static constexpr std::chrono::milliseconds FRESHNESS_TIMEOUT
Age at which a frame is no longer routed and its stream stops being eligible for selection.
void configure(GPSCorrectionSettings::CorrectionSource source, qint64 now)
Routes only source, or selects automatically for HighestPriority. A valid, changed source reselects a...
CorrectionSource
Persisted values of correctionSource. The storage type keeps any saved value a valid enum value.
constexpr std::optional< std::chrono::duration< Rep, Period > > age(std::chrono::duration< Rep, Period > timestamp, std::chrono::duration< Rep, Period > now)
Age of timestamp at now, both in the same unit; empty for a missing or future timestamp.
The stream vehicles receive: its source category and the instance within it.