QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
UBXPlan.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <chrono>
5#include <cstdint>
6#include <string_view>
7#include <type_traits>
8#include <vector>
9
10#include "GPSReceiverConfig.h"
11#include "UBX/UBXConfigKeys.h"
12#include "UBX/UBXFrame.h"
14
15namespace UBX {
16enum class Board : uint8_t
17{
18 unknown = 0,
19 u_blox5 = 5,
20 u_blox6 = 6,
21 u_blox7 = 7,
22 u_blox8 = 8,
23 u_blox9 = 9,
25 u_blox10 = 11,
27 u_blox10_L1L5 = 13,
28 u_blox_X20 = 14
29};
30
34{
37 std::string_view hardwareVersion{};
39 bool rtcmOutput = false;
41 bool baseCapabilityKnown = false;
43 bool l5HealthOverride = false;
46 uint16_t measurementPeriodMs = 100;
48 bool protocol27 = false;
49};
50
51inline constexpr std::array RECEIVER_PROFILES = {
53 // Generations before u-blox 8 cannot output RTCM, so they are never configured as a base.
54 ReceiverProfile{.board = Board::u_blox5, .hardwareVersion = "00040005", .baseCapabilityKnown = true},
55 ReceiverProfile{.board = Board::u_blox6, .hardwareVersion = "00040007", .baseCapabilityKnown = true},
56 ReceiverProfile{.board = Board::u_blox7, .hardwareVersion = "00070000", .baseCapabilityKnown = true},
57 ReceiverProfile{.board = Board::u_blox8, .hardwareVersion = "00080000"},
59 .board = Board::u_blox9, .hardwareVersion = "00190000", .baseCapabilityKnown = true, .protocol27 = true},
61 .rtcmOutput = true,
62 .baseCapabilityKnown = true,
63 .measurementPeriodMs = 200,
64 .protocol27 = true},
66 .board = Board::u_blox10, .hardwareVersion = "000A0000", .baseCapabilityKnown = true, .protocol27 = true},
68 .rtcmOutput = true,
69 .baseCapabilityKnown = true,
70 .l5HealthOverride = true,
71 .measurementPeriodMs = 200,
72 .protocol27 = true},
73 ReceiverProfile{.board = Board::u_blox10_L1L5, .baseCapabilityKnown = true, .protocol27 = true},
75 .hardwareVersion = "000B0000",
76 .rtcmOutput = true,
77 .baseCapabilityKnown = true,
78 .l5HealthOverride = true,
79 .protocol27 = true},
80};
81
82[[nodiscard]] constexpr ReceiverProfile receiverProfile(Board board)
83{
84 for (const auto& profile : RECEIVER_PROFILES) {
85 if (profile.board == board) {
86 return profile;
87 }
88 }
89 return RECEIVER_PROFILES.front();
90}
91
93[[nodiscard]] constexpr Board boardFromHardwareVersion(std::string_view hardwareVersion)
94{
95 for (const auto& profile : RECEIVER_PROFILES) {
96 if (!profile.hardwareVersion.empty() && profile.hardwareVersion == hardwareVersion) {
97 return profile.board;
98 }
99 }
100 return Board::unknown;
101}
102} // namespace UBX
103
107namespace UBX::Plan {
108
110inline constexpr std::chrono::milliseconds CONFIG_TIMEOUT{250};
112inline constexpr std::chrono::milliseconds LEGACY_REPLY_TIMEOUT{1000};
114inline constexpr std::chrono::milliseconds IDENTITY_TIMEOUT{2000};
115inline constexpr std::chrono::milliseconds PORT_TIMEOUT{2000};
117inline constexpr std::chrono::milliseconds BAUD_PROBE_DRAIN{20};
118inline constexpr std::chrono::milliseconds SURVEY_STOP_TIMEOUT{3000};
119inline constexpr std::chrono::milliseconds SURVEY_STOP_POLL{100};
121inline constexpr std::chrono::microseconds DISABLE_MESSAGE_INTERVAL = std::chrono::seconds(1);
122
124inline constexpr std::array BAUD_RATES{38400u, 57600u, 9600u, 115200u, 230400u, 460800u, 921600u};
126inline constexpr unsigned BASE_BAUD = 115200;
127
129inline constexpr size_t VALSET_CAPACITY = 256;
130
131inline constexpr uint8_t NO_OUTPUT = 0;
133inline constexpr uint8_t STATIONARY_DYNAMIC_MODEL = 2;
135inline constexpr uint8_t SURVEY_SATELLITE_RATE = 10;
138inline constexpr uint8_t BASE_SATELLITE_INFO_RATE = 2;
139inline constexpr uint8_t SURVEY_STATUS_RATE = 5;
141inline constexpr uint16_t BASE_MEASUREMENT_PERIOD_MS = 1000;
142
146{
147 template <typename T>
148 constexpr ValsetItem(CfgKey<T> setting, std::type_identity_t<T> setValue, bool when = true)
149 : key(setting.id)
150 , value(static_cast<uint32_t>(static_cast<std::make_unsigned_t<T>>(setValue)))
151 , included(when)
152 {}
153
154 constexpr ValsetItem(MsgOutKey output, uint8_t rate, bool when = true)
155 : key(output.i2c.id)
156 , value(rate)
157 , msgOut(true)
158 , included(when)
159 {}
160
162 uint32_t key;
163 uint32_t value;
164 bool msgOut = false;
165 bool included = true;
166};
167
169enum class NakPolicy : uint8_t
170{
171 Fail,
172 Tolerate,
173 Warn,
174 WriteOnly,
175};
176
178{
180 bool included = true;
182 std::chrono::milliseconds timeout = CONFIG_TIMEOUT;
183 const char* warning = nullptr;
184 std::vector<ValsetItem> items{};
185
186 [[nodiscard]] bool required() const { return policy == NakPolicy::Fail || policy == NakPolicy::WriteOnly; }
187};
188
190[[nodiscard]] ValsetBatch uart1Protocols();
191[[nodiscard]] ValsetBatch uart1Baudrate(uint32_t baudrate);
193[[nodiscard]] std::vector<ValsetBatch> portsAndNavigation(const ReceiverProfile& profile);
195[[nodiscard]] ValsetBatch jammingDetection();
197[[nodiscard]] ValsetBatch interferenceMonitor();
199[[nodiscard]] std::vector<ValsetBatch> messageOutput(const ReceiverProfile& profile);
201[[nodiscard]] ValsetBatch disableRTCMOutput();
202[[nodiscard]] ValsetBatch disableTimeMode();
203[[nodiscard]] ValsetBatch surveyIn(const GPSBaseStationConfig::SurveyIn& survey);
204[[nodiscard]] ValsetBatch fixedBase(const GPSBaseStationConfig::Fixed& fixed);
206[[nodiscard]] ValsetBatch rtcmOutput(bool compactObservations);
207
214
218
220[[nodiscard]] ValsetBatch disableMessage(MsgOutKey key);
221
224{
226 uint8_t rate;
227};
228
229inline constexpr uint16_t LEGACY_PORT_UART1 = 1;
230inline constexpr uint16_t LEGACY_PORT_USB = 3;
231
234[[nodiscard]] std::array<uint8_t, 2 * WIRE_SIZE<CfgPrt>> legacyPorts(uint32_t baudrate);
235
237inline constexpr CfgRate LEGACY_SURVEY_RATE{.measRate = 200, .navRate = 1, .timeRef = 0};
238inline constexpr CfgRate LEGACY_BASE_RATE{.measRate = BASE_MEASUREMENT_PERIOD_MS, .navRate = 1, .timeRef = 0};
240inline constexpr CfgNav5 LEGACY_NAVIGATION{.mask = 0x0005, .dynModel = STATIONARY_DYNAMIC_MODEL, .fixMode = 2};
242[[nodiscard]] std::array<MessageRate, 5> legacyMessageOutput();
245[[nodiscard]] std::array<MessageRate, 10> legacyDisableRTCMOutput();
247[[nodiscard]] std::array<MessageRate, 2> legacyBaseStatus();
248
251enum class RTCMContent : uint8_t
252{
255 Optional,
256};
257
263
264[[nodiscard]] std::array<RTCMOutput, 6> legacyRTCMOutput(bool compactObservations);
265[[nodiscard]] CfgTmode3 legacySurveyIn(const GPSBaseStationConfig::SurveyIn& survey);
266[[nodiscard]] CfgTmode3 legacyFixedBase(const GPSBaseStationConfig::Fixed& fixed);
267
268} // namespace UBX::Plan
constexpr MsgOutKey MSGOUT_UBX_RXM_SFRBX
constexpr MsgOutKey MSGOUT_UBX_RXM_RAWX
constexpr MsgOutKey MSGOUT_UBX_NAV_TIMEGPS
constexpr MessageId NAV_SVIN
Definition UBXFrame.h:51
constexpr MessageId RXM_SFRBX
Definition UBXFrame.h:53
constexpr MessageId NAV_TIMEGPS
Definition UBXFrame.h:48
constexpr MessageId RXM_RAWX
Definition UBXFrame.h:54
ValsetBatch rtcmOutput(bool compactObservations)
Base output at 1 Hz: station position, observations in the selected MSM format and GLONASS biases.
Definition UBXPlan.cc:188
constexpr uint8_t NO_OUTPUT
Definition UBXPlan.h:131
constexpr MessageRate LEGACY_SURVEY_STATUS
Definition UBXPlan.h:243
ValsetBatch fixedBase(const GPSBaseStationConfig::Fixed &fixed)
Definition UBXPlan.cc:174
constexpr CfgRate LEGACY_BASE_RATE
Definition UBXPlan.h:238
ValsetBatch jammingDetection()
Probes CFG-SEC-JAMDET, which F9 HPG 1.50+, F9 L1L5 and X20 have instead of CFG-ITFM.
Definition UBXPlan.cc:106
std::array< MessageRate, 5 > legacyMessageOutput()
NAV-PVT, status, satellite and MON-HW (antenna and jamming) rates during the survey.
Definition UBXPlan.cc:230
ValsetBatch disableRTCMOutput()
Stops RTCM output, including observations a previous session left in the other MSM format.
Definition UBXPlan.cc:146
constexpr std::chrono::milliseconds CONFIG_TIMEOUT
Acknowledgement timeout of one configuration command.
Definition UBXPlan.h:110
constexpr uint8_t SURVEY_SATELLITE_RATE
NAV-SAT every tenth survey epoch.
Definition UBXPlan.h:135
ValsetBatch interferenceMonitor()
Enables the interference monitor of firmware without CFG-SEC-JAMDET.
Definition UBXPlan.cc:111
constexpr std::chrono::milliseconds LEGACY_REPLY_TIMEOUT
The u-blox 8 protocol has CFG commands acknowledged within one second.
Definition UBXPlan.h:112
constexpr uint16_t BASE_MEASUREMENT_PERIOD_MS
RTCM output only needs 1 Hz; the survey keeps the faster navigation rate because it converges faster.
Definition UBXPlan.h:141
constexpr std::array< UnexpectedOutput, 3 > UNEXPECTED_OUTPUT
Definition UBXPlan.h:215
constexpr std::chrono::milliseconds IDENTITY_TIMEOUT
Slow factory NMEA output can delay a MON-VER response by over a second.
Definition UBXPlan.h:114
constexpr std::chrono::milliseconds PORT_TIMEOUT
Definition UBXPlan.h:115
constexpr std::chrono::milliseconds SURVEY_STOP_TIMEOUT
Definition UBXPlan.h:118
constexpr uint8_t BASE_SATELLITE_INFO_RATE
Definition UBXPlan.h:138
ValsetBatch uart1Baudrate(uint32_t baudrate)
Definition UBXPlan.cc:72
constexpr uint16_t LEGACY_PORT_UART1
Definition UBXPlan.h:229
constexpr std::chrono::milliseconds SURVEY_STOP_POLL
Definition UBXPlan.h:119
std::vector< ValsetBatch > portsAndNavigation(const ReceiverProfile &profile)
Protocol 27+ configuration before jamming detection: ports, navigation, odometer and RTK.
Definition UBXPlan.cc:77
constexpr size_t VALSET_CAPACITY
Bounds a CFG-VALSET independently of received message sizes.
Definition UBXPlan.h:129
std::array< MessageRate, 10 > legacyDisableRTCMOutput()
Written without waiting for acknowledgements.
Definition UBXPlan.cc:235
constexpr CfgRate LEGACY_SURVEY_RATE
5 Hz, UTC-aligned.
Definition UBXPlan.h:237
CfgTmode3 legacySurveyIn(const GPSBaseStationConfig::SurveyIn &survey)
Definition UBXPlan.cc:265
NakPolicy
What a batch that is rejected, unanswered or not written means for configuration.
Definition UBXPlan.h:170
@ WriteOnly
Required, but written without awaiting the reply.
@ Warn
Optional, but worth a warning.
@ Tolerate
Optional: firmware without these keys rejects them, or the configuration flow decides.
@ Fail
Required: configuration stops.
std::vector< ValsetBatch > messageOutput(const ReceiverProfile &profile)
Protocol 27+ configuration after jamming detection: message output and receiver-specific extras.
Definition UBXPlan.cc:118
ValsetBatch uart1Protocols()
Protocol 27+ port setup at the detected baud rate: UBX only on UART1, 8N1.
Definition UBXPlan.cc:60
constexpr CfgNav5 LEGACY_NAVIGATION
Updates only the dynamic model and the fix mode (3D only).
Definition UBXPlan.h:240
constexpr unsigned BASE_BAUD
The link rate a base is moved to when no rate is selected.
Definition UBXPlan.h:126
std::array< uint8_t, 2 *WIRE_SIZE< CfgPrt > > legacyPorts(uint32_t baudrate)
Definition UBXPlan.cc:213
std::array< RTCMOutput, 6 > legacyRTCMOutput(bool compactObservations)
Definition UBXPlan.cc:254
ValsetBatch disableTimeMode()
Definition UBXPlan.cc:161
CfgTmode3 legacyFixedBase(const GPSBaseStationConfig::Fixed &fixed)
Definition UBXPlan.cc:272
ValsetBatch surveyIn(const GPSBaseStationConfig::SurveyIn &survey)
Definition UBXPlan.cc:166
constexpr uint16_t LEGACY_PORT_USB
Definition UBXPlan.h:230
constexpr uint8_t SURVEY_STATUS_RATE
Definition UBXPlan.h:139
constexpr std::array BAUD_RATES
Probing order of the automatic baud detection.
Definition UBXPlan.h:124
constexpr std::chrono::microseconds DISABLE_MESSAGE_INTERVAL
An unwanted message is disabled at most this often; some cannot be disabled.
Definition UBXPlan.h:121
ValsetBatch disableMessage(MsgOutKey key)
Disables unexpected output; the reply is not awaited.
Definition UBXPlan.cc:208
constexpr std::chrono::milliseconds BAUD_PROBE_DRAIN
Traffic the baud probe drains before polling MON-VER.
Definition UBXPlan.h:117
std::array< MessageRate, 2 > legacyBaseStatus()
Survey status and satellite rates for the 1 Hz base; rejections are ignored.
Definition UBXPlan.cc:249
constexpr uint8_t STATIONARY_DYNAMIC_MODEL
Base stations always use the stationary navigation model.
Definition UBXPlan.h:133
u-blox receivers over UBX: CFG-VALSET configuration from protocol 27, CFG-MSG and CFG-TMODE3 before i...
constexpr ReceiverProfile receiverProfile(Board board)
Definition UBXPlan.h:82
constexpr std::array RECEIVER_PROFILES
Definition UBXPlan.h:51
Board
Definition UBXPlan.h:17
constexpr Board boardFromHardwareVersion(std::string_view hardwareVersion)
The generation whose MON-VER hwVersion is hardwareVersion; unknown when none matches.
Definition UBXPlan.h:93
A configuration key whose value is written and read as T.
uint16_t measRate
ms
A CFG-MSGOUT output rate key family, named by its I2C key.
CFG-MSG output rate of one message, as a divisor of the measurement rate.
Definition UBXPlan.h:224
MessageRate rate
Definition UBXPlan.h:260
RTCMContent content
Definition UBXPlan.h:261
Messages a protocol 27+ receiver can send unasked and their CFG-MSGOUT keys, which a message ID does ...
Definition UBXPlan.h:210
std::chrono::milliseconds timeout
Definition UBXPlan.h:182
bool included
Whether the receiver takes this batch at all.
Definition UBXPlan.h:180
std::vector< ValsetItem > items
Definition UBXPlan.h:184
bool required() const
Definition UBXPlan.h:186
const char * warning
Definition UBXPlan.h:183
uint32_t key
The key, or the I2C key of a CFG-MSGOUT family.
Definition UBXPlan.h:162
constexpr ValsetItem(CfgKey< T > setting, std::type_identity_t< T > setValue, bool when=true)
Definition UBXPlan.h:148
constexpr ValsetItem(MsgOutKey output, uint8_t rate, bool when=true)
Definition UBXPlan.h:154
bool protocol27
Configures through CFG-VALSET unless MON-VER reports an older protocol version.
Definition UBXPlan.h:48
bool rtcmOutput
RTCM3 base output (F9P and X20); only these receivers are configured as a base.
Definition UBXPlan.h:39
bool baseCapabilityKnown
The board alone tells whether it can be a base station.
Definition UBXPlan.h:41
uint16_t measurementPeriodMs
Definition UBXPlan.h:46
bool l5HealthOverride
GPS L5 is broadcast unhealthy while pre-operational; L1/L5 receivers take the L1 health flag instead.
Definition UBXPlan.h:43
std::string_view hardwareVersion
MON-VER hwVersion of a generation; refined boards have none.
Definition UBXPlan.h:37