QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPConnectionStats.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4
5#include <QtCore/QHash>
6#include <QtCore/QObject>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9#include "DataRateTracker.h"
10#include "RTCMMessageCount.h"
11#include "ScheduledTask.h"
12
14
17class NTRIPConnectionStats : public QObject
18{
19 Q_OBJECT
20 QML_ELEMENT
21 QML_UNCREATABLE("")
22 Q_PROPERTY(quint64 bytesReceived READ bytesReceived NOTIFY statsChanged FINAL)
23 Q_PROPERTY(quint32 messagesReceived READ messagesReceived NOTIFY statsChanged FINAL)
24 Q_PROPERTY(double dataRateBytesPerSec READ dataRateBytesPerSec NOTIFY statsChanged FINAL)
25 Q_PROPERTY(double correctionAgeSec READ correctionAgeSec NOTIFY statsChanged FINAL)
26 Q_PROPERTY(bool dataStale READ dataStale NOTIFY statsChanged FINAL)
28 Q_PROPERTY(bool dataUsageHigh READ dataUsageHigh NOTIFY statsChanged FINAL)
31 Q_PROPERTY(QList<RTCMMessageCount> messageCountsById READ messageCountsById NOTIFY statsChanged FINAL)
32
33public:
34 static constexpr quint64 DATA_USAGE_WARNING_BYTES = 50 * 1024 * 1024;
35
37 explicit NTRIPConnectionStats(std::chrono::milliseconds staleAfter, QObject* parent = nullptr,
38 RuntimeScheduler* scheduler = nullptr);
39
40 void start();
41 void stop();
43 void recordMessage(int bytes, int messageId, qint64 receivedAtMs);
44 void reset();
45
46 quint64 bytesReceived() const { return _rateTracker.totalBytes(); }
47
48 quint32 messagesReceived() const { return _messagesReceived; }
49
50 double dataRateBytesPerSec() const { return _rateTracker.bytesPerSec(); }
51
52 double correctionAgeSec() const;
53
54 bool dataStale() const { return _dataStale; }
55
57
58 QList<RTCMMessageCount> messageCountsById() const;
59
60signals:
62
63private:
65 bool _updateDataStale(std::chrono::milliseconds now);
66 std::chrono::milliseconds _now() const;
67
68 const std::chrono::milliseconds _staleAfter;
69 RuntimeScheduler* const _scheduler;
70 ScheduledTask _publishTask;
71 DataRateTracker _rateTracker;
72 quint32 _messagesReceived = 0;
73 bool _dataStale = false;
75 std::chrono::milliseconds _lastReceivedAt{0};
76 std::chrono::milliseconds _startedAt{0};
77 QHash<int, quint32> _messageCountsById;
78};
double bytesPerSec() const
Rate of the last completed window, in bytes/sec.
quint64 totalBytes() const
Total bytes recorded since construction or last reset.
void recordMessage(int bytes, int messageId, qint64 receivedAtMs)
Count every message; health uses the newest valid receipt on the scheduler's clock.
quint32 messagesReceived() const
quint64 bytesReceived() const
double dataRateBytesPerSec() const
static constexpr quint64 DATA_USAGE_WARNING_BYTES
More than DATA_USAGE_WARNING_BYTES received, which may cost money on metered connections.
QList< RTCMMessageCount > messageCountsById() const