QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
UBXProtocol.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <chrono>
5#include <cstddef>
6#include <cstdint>
7#include <optional>
8#include <span>
9#include <vector>
10
11#include <QtCore/QByteArray>
12#include <QtCore/QString>
13
14#include "GPSCommand.h"
15#include "GPSFamilyProtocol.h"
16#include "GPSProtocolEvent.h"
17#include "GPSReceiverConfig.h"
18#include "GPSStreamDemux.h"
19#include "UBX/UBXConfigKeys.h"
21#include "UBX/UBXFrame.h"
22#include "UBX/UBXPlan.h"
24
27class GPSStreamDemux;
28
29namespace UBX {
30
33{
35 bool isM8p = false;
36 bool protocol27 = false;
37 bool timeModeUnsupported = false;
39 QByteArray hardware;
40 QByteArray protocolVersion;
41 QByteArray model;
42 QByteArray firmware;
43};
44
50class Protocol final : public GPSFamilyProtocol
51{
52public:
59
61 static constexpr std::chrono::seconds REPEATED_WARNING_INTERVAL{60};
62
63 bool configure(GPSCommandChannel& channel, GPSConfig config, unsigned& baud) override;
64
65 bool probe(GPSCommandChannel& channel) override;
66
67 GPSReceiveUpdates onFrame(const GPSFrame& frame, GPSDecodeContext& context) override;
68
70 void flush(GPSDecodeContext& context) override;
71
72 bool receiverReady() const override { return _ready; }
73
74 QString identity() const override { return gpsReceiverIdentity(_identity.model, _identity.firmware); }
75
77 bool armDecodeOnly(const GPSConfig& config, GPSDecodeContext& context) override;
78
79 bool armNavigationDecode(GPSNavigationDecode decode, GPSDecodeContext& context) override;
80
82 bool completeReceiveCycle(GPSReceiveUpdates handled) override;
83
85 [[nodiscard]] std::chrono::milliseconds nextReadSlice(std::chrono::milliseconds timeout) const override;
86
88 void serviceStreaming(GPSCommandChannel& channel) override;
89
90private:
91 struct Mode
92 {
95 bool navigation = false;
97 bool corrections = false;
98 };
99
101 struct Requests
102 {
104 bool rtcmActivation = false;
106 uint16_t disableMessage = 0;
107 };
108
110 enum class RTCMActivation : uint8_t
111 {
112 Active,
113 Failed,
114 Unanswered,
115 };
116
118 struct RateConfirmation
119 {
120 GPSCommandOutcome outcome;
122 bool settled;
123 };
124
126 struct LegacyRTCMProgress
127 {
128 size_t next = 0;
129 bool stationPosition = false;
130 bool observations = false;
131 };
132
133 // Decoding (UBXDecoder.cc)
134
136 void _setMode(const Mode& mode, GPSStreamDemux& stream);
137 GPSReceiveUpdates _decode(uint16_t message, std::span<const uint8_t> payload, GPSDecodeContext& context);
138 // The decoders below receive payloads that _decode() validated against their message schema.
139 bool _accept(uint16_t message, std::span<const uint8_t> payload);
140 void _decodeEpoch(uint16_t message, std::span<const uint8_t> payload, EpochAssembler::Epoch& epoch);
141 GPSReceiveUpdates _decodeHandled(uint16_t message, std::span<const uint8_t> payload, GPSDecodeContext& context);
142 GPSReceiveUpdates _decodeSurveyIn(std::span<const uint8_t> payload, GPSDecodeContext& context);
143 void _decodeMonVer(std::span<const uint8_t> payload);
144 void _decodeSatellites(uint16_t message, std::span<const uint8_t> payload);
145
146 // Configuration and streaming services (UBXConfigurator.cc)
147
148 [[nodiscard]] bool _baseStationUnsupported() const;
149 bool _identify(GPSCommandChannel& channel);
150 bool _setUpPort(GPSCommandChannel& channel, unsigned detectedBaud, unsigned desiredBaud);
151 bool _configureDevice(GPSCommandChannel& channel);
152 bool _configureJammingDetection(GPSCommandChannel& channel);
153 bool _configureLegacyDevice(GPSCommandChannel& channel);
154 bool _restartSurveyIn(GPSCommandChannel& channel);
155 bool _restartLegacySurveyIn(GPSCommandChannel& channel);
156 bool _disableTimeMode(GPSCommandChannel& channel);
157 bool _waitForSurveyStop(GPSCommandChannel& channel);
158 RTCMActivation _activateRTCMOutput(GPSCommandChannel& channel);
159 RTCMActivation _activateLegacyRTCMOutput(GPSCommandChannel& channel);
160 void _disableUnexpectedMessage(GPSCommandChannel& channel, uint16_t message);
161
163 bool _send(GPSCommandChannel& channel, MessageId message, std::span<const uint8_t> payload,
165 bool _sendAcknowledged(GPSCommandChannel& channel, MessageId message, std::span<const uint8_t> payload);
166 GPSConfigurationEvidence _waitForAck(GPSCommandChannel& channel, MessageId message);
167 bool _setMessageRate(GPSCommandChannel& channel, Plan::MessageRate rate);
168 bool _setMessageRateAcknowledged(GPSCommandChannel& channel, Plan::MessageRate rate);
169 GPSCommandOutcome _setMessageRateReply(GPSCommandChannel& channel, Plan::MessageRate rate);
173 RateConfirmation _confirmMessageRate(GPSCommandChannel& channel, Plan::MessageRate rate);
174 bool _runPlan(GPSCommandChannel& channel, const std::vector<Plan::ValsetBatch>& batches);
176 [[nodiscard]] bool _valsetsRefused() const;
177 void _load(const Plan::ValsetBatch& batch);
178 bool _writeValset(GPSCommandChannel& channel, const Plan::ValsetBatch& batch);
179 GPSConfigurationEvidence _transactValset(GPSCommandChannel& channel, const Plan::ValsetBatch& batch);
181 GPSConfigurationEvidence _awaitValsetAck(GPSCommandChannel& channel);
184
185 // What configuration and the streaming services share with decoding.
186 Identity _identity{};
187 ReceiverController _controller{};
188 Mode _mode{};
189 Requests _requests{};
191 bool _timeModeReadbackPending = false;
192 std::optional<uint8_t> _timeModeReadback = std::nullopt;
194 bool _surveyStopped = false;
195 bool _ready = false;
197 bool _secSigSeen = false;
198
199 // Decoding
200 EpochAssembler _epochs;
201 GPSDecodedSatellites _satellites;
202 GPSIntegrityReport _integrity;
204 bool _epochStarted = false;
206 QString _lastWarning;
207 uint64_t _lastWarningUs = 0;
208
209 // Configuration
211 CheckedValsetBatch<Plan::VALSET_CAPACITY> _valset;
214 bool _valsetAckAmbiguous = false;
215 LegacyRTCMProgress _legacyRTCM;
216 uint64_t _lastDisableUs = 0;
217};
218
219} // namespace UBX
GPSCommandOutcome
Definition GPSCommand.h:33
QString gpsReceiverIdentity(const QByteArray &model, const QByteArray &firmware)
A receiver identity as GPSFamilyProtocol::identity() reports it: "<model> <firmware>",...
Config config
void flush(GPSDecodeContext &context) override
Publishes epochs past their deadline.
bool receiverReady() const override
Definition UBXProtocol.h:72
bool probe(GPSCommandChannel &channel) override
The MON-VER poll Protocol::configure() identifies receivers with, under the same label and timeout.
bool completeReceiveCycle(GPSReceiveUpdates handled) override
Whether a receive cycle has what it waits for: a pending readback, or else a navigation update.
void serviceStreaming(GPSCommandChannel &channel) override
RTCM activation after survey-in and disabling unexpected output, as decoding requested.
QString identity() const override
Model and firmware reported during configuration; empty when unknown.
Definition UBXProtocol.h:74
bool configure(GPSCommandChannel &channel, GPSConfig config, unsigned &baud) override
GPSReceiveUpdates onFrame(const GPSFrame &frame, GPSDecodeContext &context) override
bool armNavigationDecode(GPSNavigationDecode decode, GPSDecodeContext &context) override
static constexpr std::chrono::seconds REPEATED_WARNING_INTERVAL
A receiver warning or error repeated within this interval is logged at debug level.
Definition UBXProtocol.h:61
std::chrono::milliseconds nextReadSlice(std::chrono::milliseconds timeout) const override
Reads briefly once part of an epoch has arrived, as the rest follows back to back.
static constexpr std::array NAVIGATION_MESSAGES
Definition UBXProtocol.h:56
bool armDecodeOnly(const GPSConfig &config, GPSDecodeContext &context) override
The decoder state a successful configure() leaves: navigation, survey and corrections decoding.
constexpr MessageId MON_HW
Definition UBXFrame.h:69
constexpr MessageId MON_RF
Definition UBXFrame.h:70
constexpr MessageId SEC_SIG
Definition UBXFrame.h:71
constexpr MessageId NAV_STATUS
Definition UBXFrame.h:44
constexpr MessageId NAV_DOP
Definition UBXFrame.h:45
constexpr MessageId NAV_SAT
Definition UBXFrame.h:50
constexpr MessageId NAV_SVINFO
Definition UBXFrame.h:49
constexpr MessageId NAV_HPPOSLLH
Definition UBXFrame.h:47
constexpr MessageId NAV_PVT
Definition UBXFrame.h:46
u-blox receivers over UBX: CFG-VALSET configuration from protocol 27, CFG-MSG and CFG-TMODE3 before i...
Board
Definition UBXPlan.h:17
Configuration used only by the RTK base-station role.
The receiver configuration requested for one configure() attempt.
Evidence from one configuration command, not a claim of physical receiver operation.
Definition GPSCommand.h:46
What a decode-only runtime decodes from a receiver configured elsewhere (GPSFamilyProtocol::armNaviga...
Receiver identity from MON-VER.
Definition UBXProtocol.h:33
QByteArray firmware
Definition UBXProtocol.h:42
QByteArray protocolVersion
Definition UBXProtocol.h:40
QByteArray model
Definition UBXProtocol.h:41
bool timeModeUnsupported
Definition UBXProtocol.h:37
QByteArray hardware
MON-VER hwVersion, such as "00190000", and the PROTVER extension, such as "27.31"; empty when not rep...
Definition UBXProtocol.h:39