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());
29 _publishTask.scheduleRepeating(std::chrono::seconds{1}, [
this]() {
30 _rateTracker.refresh();
31 (void) _updateDataStale(_now());
38 _publishTask.cancel();
39 _startedAt = std::chrono::milliseconds::zero();
40 _rateTracker.resetRate();
46 const auto age =
MonotonicClock::age(_lastReceivedAt, std::chrono::milliseconds(_scheduler->nowMs()));
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;
63 _rateTracker.recordBytes(bytes);
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 recordMessage(int bytes, int messageId, qint64 receivedAtMs)
Count every message; health uses the newest valid receipt on the scheduler's clock.
double correctionAgeSec() const
NTRIPConnectionStats(std::chrono::milliseconds staleAfter, QObject *parent=nullptr, RuntimeScheduler *scheduler=nullptr)
The stream counts as stale once no message has arrived for staleAfter.
QList< RTCMMessageCount > messageCountsById() const
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.