QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPGgaProvider.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QChronoTimer>
4#include <QtCore/QHash>
5#include <QtCore/QObject>
6#include <QtCore/QPointer>
7#include <QtCore/QString>
8#include <QtPositioning/QGeoCoordinate>
9#include <chrono>
10#include <functional>
11
12class Fact;
13class FactGroup;
14class NTRIPSettings;
15class NTRIPTransport;
16
18{
19 QGeoCoordinate coordinate;
20 QString source;
21
22 bool isValid() const { return coordinate.isValid(); }
23};
24
25class NTRIPGgaProvider : public QObject
26{
27 Q_OBJECT
28
29public:
30 enum class PositionSource
31 {
32 Auto = 0,
33 VehicleGPS = 1,
34 VehicleEKF = 2,
35 RTKBase = 3,
36 GCSPosition = 4
37 };
38 Q_ENUM(PositionSource)
39
40
41 static constexpr std::chrono::milliseconds kDefaultInterval{5000};
44 static constexpr std::chrono::milliseconds kFastRetryInterval{1000};
45
46 using PositionProvider = std::function<PositionResult()>;
47
48 explicit NTRIPGgaProvider(QObject* parent = nullptr);
49
53 void init(NTRIPSettings* settings);
54
55 void start(NTRIPTransport* transport);
56 void stop();
57
58 QString currentSource() const { return _source; }
59
61
62 // Note: GGA sentence construction lives in NMEAUtils::makeGGA — call it
63 // directly. The pass-through that used to live here was removed to keep
64 // one source of truth for sentence encoding.
65
66signals:
67 void sourceChanged(const QString& source);
68
69private:
70 enum class RetryPhase
71 {
72 Fast,
73 Normal
74 };
75
76 void _sendGGA();
77 void _setRetryPhase(RetryPhase phase);
78 void _ensureDefaultProviders();
79 void _clearSource();
80
81 PositionResult _getBestPosition() const;
82
83 QPointer<NTRIPTransport> _transport;
84 QChronoTimer _timer;
85 QString _source;
86 QHash<PositionSource, PositionProvider> _providers;
87 RetryPhase _retryPhase = RetryPhase::Normal;
88 int _fastRetryCount = 0;
89 // Cached ntripSettings()->ntripGgaPositionSource(); refreshed via rawValueChanged
90 // so we don't dereference SettingsManager on every GGA tick.
92 // Cached ntripSettings()->ntripGgaIntervalSec() converted to ms; refreshed on
93 // rawValueChanged so the hot path avoids SettingsManager dereference.
94 std::chrono::milliseconds _normalInterval = kDefaultInterval;
95};
Used to group Facts together into an object hierarachy.
Definition FactGroup.h:16
A Fact is used to hold a single value within the system.
Definition Fact.h:17
static constexpr std::chrono::milliseconds kDefaultInterval
Fallback when no NTRIPSettings are available (unit tests, early init).
void sourceChanged(const QString &source)
QString currentSource() const
std::function< PositionResult()> PositionProvider
static constexpr std::chrono::milliseconds kFastRetryInterval
void init(NTRIPSettings *settings)
void start(NTRIPTransport *transport)
void setPositionProvider(PositionSource source, PositionProvider provider)
QGeoCoordinate coordinate
bool isValid() const