QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPSourceTableController.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <memory>
5#include <optional>
6
7#include <QtCore/QAbstractItemModel>
8#include <QtCore/QObject>
9#include <QtCore/QString>
10#include <QtPositioning/QGeoCoordinate>
11#include <QtQmlIntegration/QtQmlIntegration>
12
13#include "NTRIPConfiguration.h"
14
18
21class NTRIPSourceTableController : public QObject
22{
23 Q_OBJECT
24 QML_ELEMENT
25 QML_UNCREATABLE("")
26 Q_PROPERTY(FetchStatus fetchStatus READ fetchStatus NOTIFY fetchStatusChanged FINAL)
27 Q_PROPERTY(QString fetchError READ fetchError NOTIFY fetchErrorChanged FINAL)
28 Q_PROPERTY(QString securityWarning READ securityWarning NOTIFY securityWarningChanged FINAL)
29 Q_PROPERTY(QAbstractItemModel* mountpointModel READ mountpointModel CONSTANT FINAL)
30
31public:
32 enum class FetchStatus
33 {
34 Idle,
36 Success,
37 Error
38 };
39 Q_ENUM(FetchStatus)
40
41 static constexpr std::chrono::milliseconds CACHE_TTL{60000};
42 static constexpr std::chrono::milliseconds FETCH_TIMEOUT{10000};
43 static constexpr qint64 MAX_SOURCE_TABLE_BYTES = 8 * 1024 * 1024;
44
45 explicit NTRIPSourceTableController(QObject* parent = nullptr, RuntimeScheduler* scheduler = nullptr);
47
48 FetchStatus fetchStatus() const { return _fetchStatus; }
49
50 QString fetchError() const { return _fetchError; }
51
53 QString securityWarning() const { return _lastFetchConfig.credentialsInClearWarning(); }
54
55 QAbstractItemModel* mountpointModel() const;
56
57 void fetch(const NTRIPConnectionConfig& config, const QGeoCoordinate& sortCoord = {});
58 void cancel();
59
60signals:
65 void certificatePinned(const QString& pin);
66
67private:
69
70 void _onSourceTableReceived(const QString& table);
71 void _onFetchError(const QString& error);
73 void _setFetchState(FetchStatus status, const QString& error);
74 void _abortFetch();
75 void _startFetch();
76 void _armFetchTimeout();
77 void _readReply(const QByteArray& bytes);
78 void _finishFetch(const QString& error = {});
79
80 NTRIPSourceTableModel* _model = nullptr;
81 NTRIPSourceTableSortModel* _sortedModel = nullptr;
82 struct FetchAttempt;
84 std::unique_ptr<FetchAttempt> _attempt;
85 RuntimeScheduler* const _scheduler;
86 QGeoCoordinate _sortCoord;
87 FetchStatus _fetchStatus = FetchStatus::Idle;
88 QString _fetchError;
89 std::optional<quint64> _cacheStoredAtUs;
90
91 NTRIPConnectionConfig _lastFetchConfig;
92};
Config config
Error error
void fetch(const NTRIPConnectionConfig &config, const QGeoCoordinate &sortCoord={})
static constexpr std::chrono::milliseconds CACHE_TTL
void certificatePinned(const QString &pin)
A self-signed caster certificate was trusted on first use; the owner persists the pin.
static constexpr qint64 MAX_SOURCE_TABLE_BYTES
QAbstractItemModel * mountpointModel() const
static constexpr std::chrono::milliseconds FETCH_TIMEOUT
QString securityWarning() const
Set while the latest fetch sends caster credentials without TLS.
QString credentialsInClearWarning() const
The user-visible warning when credentials go to the caster without TLS; empty otherwise.