QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSCorrectionManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <optional>
5
6#include <QtCore/QObject>
7#include <QtCore/QPointer>
8#include <QtQmlIntegration/QtQmlIntegration>
9
10#include "DataRateTracker.h"
12#include "RTCMMAVLink.h"
13#include "RTCMUdpInput.h"
14#include "ScheduledTask.h"
15#include "UdpForwarder.h"
16
19
22{
23public:
25 Q_DISABLE_COPY_MOVE(GPSCorrectionSourceHandle)
26
27
30 void submit(const QByteArray& data, qint64 receivedAtMs, const QString& instance = {}) const;
31
32private:
35 const QString& instance);
36
37 const QPointer<GPSCorrectionManager> _manager;
39 const QString _instance;
40};
41
45class GPSCorrectionManager : public QObject
46{
47 Q_OBJECT
48 QML_ELEMENT
49 QML_UNCREATABLE("Provided by the GPS manager")
50 Q_PROPERTY(State state READ state NOTIFY stateChanged FINAL)
54 Q_PROPERTY(QString udpInputError READ udpInputError NOTIFY udpInputChanged FINAL)
55 Q_PROPERTY(QString udpOutputError READ udpOutputError NOTIFY udpOutputChanged FINAL)
56
58
59public:
61 enum class State
62 {
66 Waiting,
68 Fresh,
69 };
70 Q_ENUM(State)
71
73 {
74 bool enabled = false;
75 quint16 port = 0;
76 bool operator==(const UdpInputConfiguration&) const = default;
77 };
78
80 {
81 bool enabled = false;
82 QString address{};
83 quint16 port = 0;
84 bool operator==(const UdpOutputConfiguration&) const = default;
85 };
86
98
99 explicit GPSCorrectionManager(QObject* parent = nullptr, RuntimeScheduler* scheduler = nullptr);
100 ~GPSCorrectionManager() override;
101
102 void shutdown();
103
105 RTCMMAVLink* rtcmMavlink() { return &_rtcmMavlink; }
106
108 void setConfiguration(const Configuration& configuration);
111 [[nodiscard]] std::unique_ptr<GPSCorrectionSourceHandle> openSource(GPSCorrectionSettings::CorrectionSource source,
112 const QString& instance);
113
115 State state() const { return _state; }
116
119 GPSCorrectionStream selectedStream() const { return _selected; }
120
122 quint64 selectedBytesPerSecond() const { return _selectedBytesPerSecond; }
123
125 quint64 vehicleBytesSubmitted() const { return _rtcmMavlink.totalBytesSubmitted(); }
126
128 QString udpInputError() const { return _udpInputError; }
129
131 QString udpOutputError() const { return _udpOutputError; }
132
133 Q_INVOKABLE static QString sourceName(int source);
134
135signals:
141
142private:
144 void _beginSource(GPSCorrectionSettings::CorrectionSource source);
145 void _endSource(GPSCorrectionSettings::CorrectionSource source);
147 void _submit(GPSCorrectionSettings::CorrectionSource source, const QString& instance, const QByteArray& data,
148 qint64 receivedAtMs);
149
151 [[nodiscard]] bool _applyUdpInput();
152 [[nodiscard]] bool _applyUdpOutput();
153 bool _udpInputEnabled() const;
154 void _startUdpInput();
155 void _retryUdpInput();
156
157 void _scheduleRefresh();
158 void _refresh();
159
160 RuntimeScheduler* const _scheduler;
161 ScheduledTask _refreshTask;
163 ScheduledTask _tickTask;
164 GPSCorrectionSelector _selector;
165 DataRateTracker _selectedRate;
166 RTCMMAVLink _rtcmMavlink;
167 RTCMUdpInput _udpInput;
168 std::unique_ptr<GPSCorrectionSourceHandle> _udpSource;
169 UdpForwarder _udpOutput{this};
170 std::optional<Configuration> _configuration;
171 State _state = State::Inactive;
172 GPSCorrectionStream _selected;
173 quint64 _selectedBytesPerSecond = 0;
174 QString _udpInputError;
175 QString _udpOutputError;
176 bool _shutdown = false;
177};
QString udpOutputError() const
Why the enabled UDP output does not forward; empty while it forwards or is disabled.
static Q_INVOKABLE QString sourceName(int source)
void vehicleBytesSubmittedChanged()
QString udpInputError() const
Why the enabled UDP input is not listening; empty while it listens or is disabled.
quint64 vehicleBytesSubmitted() const
Bytes of the selected streams that vehicle links admitted, from every source since startup.
quint64 selectedBytesPerSecond() const
Rate of the corrections sent from the selected stream.
void selectedBytesPerSecondChanged()
GPSCorrectionStream selectedStream() const
State
Whether vehicles receive RTK corrections, across NTRIP, UDP input, and the local receiver.
@ Inactive
No correction source is enabled.
@ Waiting
A source is enabled, but no fresh stream is selected for vehicles.
@ Fresh
A fresh stream is selected for vehicles.
RTCMMAVLink * rtcmMavlink()
The vehicle output, whose links tests replace with RTCMMAVLink::setOutputProvider().
std::unique_ptr< GPSCorrectionSourceHandle > openSource(GPSCorrectionSettings::CorrectionSource source, const QString &instance)
State state() const
As last published with stateChanged().
void setConfiguration(const Configuration &configuration)
Applies the parts that changed; ignored after shutdown().
CorrectionSource
Persisted values of correctionSource. The storage type keeps any saved value a valid enum value.
A begun correction source and the stream it delivers; destroying it ends the source.
void submit(const QByteArray &data, qint64 receivedAtMs, const QString &instance={}) const
The correction settings as values; the application's settings binding supplies them.
bool operator==(const Configuration &) const =default
GPSCorrectionSettings::CorrectionSource source
The only source routed to vehicles, or HighestPriority to select automatically.
UdpInputConfiguration udpInput
Listens for RTCM on a UDP port as the Udp source. A port that cannot be bound is retried every second...
UdpOutputConfiguration udpOutput
Forwards the selected stream to a UDP peer.
bool operator==(const UdpInputConfiguration &) const =default
bool operator==(const UdpOutputConfiguration &) const =default
The stream vehicles receive: its source category and the instance within it.