15 , _staleAfter(staleAfter)
17 , _publishTask(_scheduler, this)
18 , _rateTracker([this]() {
return _scheduler->nowUs(); })
21std::chrono::milliseconds NTRIPConnectionStats::_now()
const
23 return std::chrono::milliseconds(_scheduler->
nowMs());
31 (void) _updateDataStale(_now());
39 _startedAt = std::chrono::milliseconds::zero();
47 return age ? std::chrono::duration<double>(*age).count() : -1.0;
50bool NTRIPConnectionStats::_updateDataStale(std::chrono::milliseconds now)
52 const auto since = _lastReceivedAt > std::chrono::milliseconds::zero() ? _lastReceivedAt : _startedAt;
54 const bool stale = age && *age >= _staleAfter;
55 return std::exchange(_dataStale, stale) != stale;
65 ++_messageCountsById[messageId];
66 const auto now = _now();
67 const std::chrono::milliseconds receivedAt(receivedAtMs);
68 if (receivedAt <= std::chrono::milliseconds::zero() || receivedAt > now) {
69 qCWarning(NTRIPConnectionStatsLog) <<
"Invalid RTCM receipt timestamp:" << receivedAtMs;
71 _lastReceivedAt = (std::max) (_lastReceivedAt, receivedAt);
74 if (_updateDataStale(now)) {
82 _messagesReceived = 0;
83 _lastReceivedAt = std::chrono::milliseconds::zero();
84 _startedAt = std::chrono::milliseconds::zero();
85 _messageCountsById.clear();
92 QList<RTCMMessageCount> counts;
93 counts.reserve(_messageCountsById.size());
94 for (
auto it = _messageCountsById.cbegin(); it != _messageCountsById.cend(); ++it) {
95 counts.append({it.key(), it.value()});
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void reset()
Reset all counters and restart the rate window.
void recordBytes(qsizetype bytes)
Record incoming/outgoing bytes. Call whenever data passes through.
void refresh()
Advance the rate window without changing cumulative bytes.
void resetRate()
Zero the rate and restart its window; cumulative bytes are kept.
void recordMessage(int bytes, int messageId, qint64 receivedAtMs)
Count every message; health uses the newest valid receipt on the scheduler's clock.
double correctionAgeSec() const
QList< RTCMMessageCount > messageCountsById() const
bool scheduleRepeating(std::chrono::microseconds interval, RuntimeScheduler::Callback callback)
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.