QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSReceiverSession.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <optional>
5#include <utility>
6
7#include <QtCore/QObject>
8#include <QtCore/QPointer>
9#include <QtCore/QString>
10
11#include "GPSObservation.h"
12#include "GPSReceiverConfig.h"
14#include "GPSReceiverReports.h"
15#include "GPSReceiverWorker.h"
16#include "PositionManager.h"
17
20class GPSSourceHealth;
21
24{
26 std::optional<BaseModeDefinition::Mode> mode;
28 std::optional<std::pair<GPSEllipsoidPosition, double>> position;
30 std::optional<double> surveyAccuracyLimitMeters;
31
33 void applySurvey(const GPSSurveyReport& report);
34};
35
39[[nodiscard]] GPSReceiverConfig gpsReceiverConfigFor(const GPSBaseStationConfig& base, GPSType type, uint32_t baudRate,
40 bool allowPersistentChanges, QString* error);
41
44
48class GPSReceiverSession : public QObject
49{
50 Q_OBJECT
51
52public:
65
66 GPSReceiverSession(quint64 id, Connection connection, QObject* parent);
67 ~GPSReceiverSession() override;
68
70 void registerCorrections(GPSCorrectionManager* manager, const QString& sourceInstance);
72 bool start(const GPSReceiverWorkerFactory& factory, GPSReceiverWorker::TransportFactory transportFactory);
74 void registerPosition(PositionManager* positionManager, GPSSourceHealth* producer);
77 void retire();
78
79 bool hasWorker() const { return !_worker.isNull(); }
80
82 QPointer<GPSReceiverWorker> worker() const { return _worker; }
83
84 RTKSettings::ReceiverRole role() const { return _connection.role; }
85
86 bool forwardsCorrections() const { return _connection.forwardsCorrections; }
87
89 bool compactObservations() const { return _connection.config.base.compactObservations; }
90
92 int manufacturer() const
93 {
95 _connection.type == GPSType::automatic ? _detectedType.value_or(GPSType::automatic) : _connection.type);
96 }
97
100 std::optional<GPSType> detectedType() const { return _detectedType; }
101
103 int baseMode() const { return _base.mode ? static_cast<int>(*_base.mode) : -1; }
104
105 const QString& serialDevice() const { return _connection.serialDevice; }
106
107 const QString& endpoint() const { return _connection.endpoint; }
108
109 const QString& identity() const { return _identity; }
110
112 GPSObservation observation(const GPSPositionReport& report, quint64 receivedAtUs) const;
113
114signals:
119 void receiverReady(const QString& identity);
125 void ended(GPSConnectionError error, const QString& detail);
126
127private:
128 void _onSurvey(const GPSSurveyReport& report);
129 void _onReady(const QString& identity);
130 void _onDetected(GPSType type);
131 void _forwardCorrection(const QByteArray& data, qint64 receivedAtMs);
132
133 const quint64 _sessionId;
134 const Connection _connection;
136 QPointer<GPSReceiverWorker> _worker;
138 std::unique_ptr<GPSCorrectionSourceHandle> _correction;
140 QString _identity;
141 std::optional<GPSType> _detectedType;
142 bool _retired = false;
143};
std::function< GPSReceiverWorker *(GPSReceiverWorker::TransportFactory, GPSType, const GPSReceiverConfig &, QObject *)> GPSReceiverWorkerFactory
Creates a receiver session's worker; tests inject scripted workers.
int gpsReceiverManufacturerForType(GPSType type)
The persisted manufacturer of type, or GPS_AUTOMATIC_MANUFACTURER when it has none.
GPSBaseStationState gpsBaseStationStateFor(GPSType type, const GPSReceiverConfig &config)
The state a session starts from; a fixed base knows its position before the receiver reports.
GPSReceiverConfig gpsReceiverConfigFor(const GPSBaseStationConfig &base, GPSType type, uint32_t baudRate, bool allowPersistentChanges, QString *error)
Config config
std::shared_ptr< const void > GPSPositionSourceRegistration
Error error
A begun correction source and the stream it delivers; destroying it ends the source.
void registerPosition(PositionManager *positionManager, GPSSourceHealth *producer)
Publishes producer as the receiver position source. Registration observers may retire this session.
void registerCorrections(GPSCorrectionManager *manager, const QString &sourceInstance)
Forwards the receiver's RTCM as the local correction source when the connection asks for it.
void receiverReady(const QString &identity)
GPSObservation observation(const GPSPositionReport &report, quint64 receivedAtUs) const
A base with a known antenna position reports that position instead of its navigation solution.
int baseMode() const
BaseModeDefinition::Mode of a configured base, or -1 for a passive receiver.
void ended(GPSConnectionError error, const QString &detail)
The worker failed or exited; the owner ends the session.
void surveyInStatusUpdated(const GPSSurveyReport &report)
Survey progress of a configured base.
bool compactObservations() const
A configured base sends compact (MSM4) observations.
QPointer< GPSReceiverWorker > worker() const
The worker, which outlives the session once retired until its thread exits.
const QString & serialDevice() const
RTKSettings::ReceiverRole role() const
bool start(const GPSReceiverWorkerFactory &factory, GPSReceiverWorker::TransportFactory transportFactory)
Creates the worker, with a real worker for an empty factory, and starts it. False when none is create...
void positionUpdated(const GPSPositionReport &report)
const QString & identity() const
std::optional< GPSType > detectedType() const
const QString & endpoint() const
void receiverDetected(GPSType type)
The family an Automatic session detected, or the protocol a passive receiver's output carries.
int manufacturer() const
The detected family's once an Automatic session detected it; a passive receiver's stays passive.
void inputProblem(GPSInputProblem problem)
Why a passive receiver delivers no position; None once positions arrive.
void satelliteInfoUpdated(const GPSSatelliteReport &report)
bool forwardsCorrections() const
std::function< std::unique_ptr< GPSTransport >(GPSCancelToken)> TransportFactory
Consumed on the worker thread, so transport construction, I/O and destruction share that thread.
Session health is independent of transport readiness and RTK survey-in validity.
ReceiverRole
Persisted values of receiverRole. The storage type keeps any saved value a valid enum value.
Definition RTKSettings.h:36
GPSInputProblem
Why a receiver that stays connected while silent reports no position.
Configuration used only by the RTK base-station role.
bool compactObservations
MSM4 instead of MSM7 observations: about a third less correction bandwidth, without Doppler.
A receiver session's base-station mode and the antenna position it reports.
void applySurvey(const GPSSurveyReport &report)
A surveying base adopts a valid, located result and otherwise has no position.
std::optional< std::pair< GPSEllipsoidPosition, double > > position
Antenna position and its accuracy in meters once known; the receiver then reports only a time fix.
std::optional< double > surveyAccuracyLimitMeters
Assumed accuracy of a survey-in result that reports none.
std::optional< BaseModeDefinition::Mode > mode
Base mode of a configured base; empty for a passive receiver.
Receiver-independent data. Unknown metadata remains absent, never a manufactured zero.
GPSBaseStationConfig base
QString endpoint
Serial device or network address shown to the user.
RTKSettings::ReceiverRole role
QString serialDevice
Serial device whose removal ends the session; empty for network receivers.
bool forwardsCorrections
The receiver's RTCM output is a correction source.