Fixposition SDK 0.0.0-heads/main-0-g90a51ff
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
gnss.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 *
9 * Based on work by flipflip (https://github.com/phkehl)
10 * \endverbatim
11 *
12 * @file
13 * @brief Fixposition SDK: GNSS types and utilities
14 *
15 * @page FPSDK_COMMON_GNSS GNSS types and utilities
16 *
17 * **API**: fpsdk_common/gnss.hpp and fpsdk::common::gnss
18 *
19 */
20#ifndef __FPSDK_COMMON_GNSS_HPP__
21#define __FPSDK_COMMON_GNSS_HPP__
22
23/* LIBC/STL */
24#include <cstdint>
25
26/* EXTERNAL */
27
28/* PACKAGE */
29#include "types.hpp"
30
31namespace fpsdk {
32namespace common {
33/**
34 * @brief GNSS types and utilities
35 */
36namespace gnss {
37/* ****************************************************************************************************************** */
38
39/**
40 * @brief GNSS fix types
41 */
42enum class GnssFixType : uint8_t
43{ // clang-format off
44 UNKNOWN = 0, //!< Unknown fix
45 NOFIX = 1, //!< No fix
46 DRONLY = 2, //!< Dead-reckoning only fix
47 TIME = 3, //!< Time only fix
48 SPP_2D = 4, //!< 2D fix
49 SPP_3D = 5, //!< 3D fix
50 SPP_3D_DR = 6, //!< 3D + dead-reckoning fix
51 RTK_FLOAT = 7, //!< RTK float fix (implies 3D fix)
52 RTK_FIXED = 8, //!< RTK fixed fix (implies 3D fix)
53 RTK_FLOAT_DR = 9, //!< RTK float fix + dead-reckoning (implies RTK_FLOAT fix)
54 RTK_FIXED_DR = 10, //!< RTK fixed fix + dead-reckoning (implies RTK_FIXED fix)
55}; // clang-format on
56
57/**
58 * @brief Stringify GNSS fix type
59 *
60 * @param[in] fix_type The fix type
61 *
62 * @returns a concise and unique string for the fix types, "?" for bad values
63 */
64const char* GnssFixTypeStr(const GnssFixType fix_type);
65
66/**
67 * @brief GNSS
68 */
69enum class Gnss : uint8_t
70{ // clang-format off
71 UNKNOWN = 0, //!< Unknown/unspecified GNSS
72 GPS = 'G', //!< GPS
73 SBAS = 'S', //!< SBAS
74 GAL = 'E', //!< Galileo
75 BDS = 'C', //!< BeiDou
76 QZSS = 'J', //!< QZSS
77 GLO = 'R', //!< GLONASS
78 NAVIC = 'I', //!< NavIC (IRNSS)
79}; // clang-format on
80
81/**
82 * @brief Stringify GNSS
83 *
84 * @param[in] gnss The GNSS
85 *
86 * @returns a concise and unique string for the GNSS, "?" for bad values
87 */
88const char* GnssStr(const Gnss gnss);
89
90/**
91 * @brief Signals
92 */
93enum class Signal : uint8_t
94{ // clang-format off
95 UNKNOWN = 0, //!< Unknown/unspecified signal
96 BDS_B1C, //!< BeiDou B1c signal (B1 Cp and B1 Cd)
97 BDS_B1I, //!< BeiDou B1I signal (B1I D1 and B1I D2)
98 BDS_B2A, //!< BeiDou B2a signal (B2 ap and B2 ad)
99 BDS_B2I, //!< BeiDou B2I signal (B2I D1 and B2I D2)
100 GAL_E1, //!< Galileo E1 signal (E1 C and E1 B)
101 GAL_E5A, //!< Galileo E5a signal (E5 aI and E5 aQ)
102 GAL_E5B, //!< Galileo E5b signal (E5 bI and E5 bQ)
103 GLO_L1OF, //!< GLONASS L1 OF signal
104 GLO_L2OF, //!< GLONASS L2 OF signal
105 GPS_L1CA, //!< GPS L1 C/A signal
106 GPS_L2C, //!< GPS L2 C signal (L2 CL and L2 CM)
107 GPS_L5, //!< GPS L5 signal (L5 I and L5 Q)
108 QZSS_L1CA, //!< QZSS L1 C/A signal
109 QZSS_L1S, //!< QZSS L1 S (SAIF) signal
110 QZSS_L2C, //!< QZSS L2 C signal (L2 CL and L2 CM)
111 QZSS_L5, //!< QZSS L5 signal (L5 I and L5 Q)
112 SBAS_L1CA, //!< SBAS L1 C/A signal
113 NAVIC_L5A, //!< NavIC L5 A
114}; // clang-format on
115
116/**
117 * @brief Stringify signal
118 *
119 * @param[in] signal The signal
120 *
121 * @returns a concise and unique string for the signal, "?" for bad values
122 */
123const char* SignalStr(const Signal signal);
124
125/**
126 * @brief Frequency bands
127 */
128enum class Band : uint8_t
129{
130 UNKNOWN = 0, //!< Unknown/unspecified band
131 L1, //!< L1 band (~1.5GHz)
132 L2, //!< L2 band (~1.2GHz)
133 L5, //!< L5 band (~1.1GHz)
134};
135
136/**
137 * @brief Stringify frequency band
138 *
139 * @param[in] band The frequency band
140 *
141 * @returns a concise and unique string for the frequency band, "?" for bad values
142 */
143const char* BandStr(const Band band);
144
145/**
146 * @brief Get frequency band for a signal
147 *
148 * @param[in] signal The signal
149 *
150 * @returns the frequency band for the signal
151 */
153
154/**
155 * @brief Satellite number (within a GNSS)
156 */
157using SvNr = uint8_t;
158
159// Number of satellites per constellation, see https://igs.org/mgex/constellations/. Satellite numbers are two digits
160// satellite numbers as defined by IGS (see RINEX v3.04 section 3.5).
161// clang-format off
162static constexpr SvNr NUM_GPS = 32; //!< Number of GPS satellites (G01-G32, PRN)
163static constexpr SvNr NUM_SBAS = 39; //!< Number of SBAS satellites (S20-S59, PRN - 100)
164static constexpr SvNr NUM_GAL = 36; //!< Number of Galileo satellites (E01-E36, PRN)
165static constexpr SvNr NUM_BDS = 63; //!< Number of BeiDou satellites (C01-C63, PRN)
166static constexpr SvNr NUM_QZSS = 10; //!< Number of QZSS satellites (J01-J10, PRN - 192)
167static constexpr SvNr NUM_GLO = 32; //!< Number of GLONASS satellites (R01-R32, slot)
168static constexpr SvNr NUM_NAVIC = 14; //!< Number of NavIC satellites (I01-I14, PRN)
169static constexpr SvNr FIRST_GPS = 1; //!< First GPS satellite number
170static constexpr SvNr FIRST_SBAS = 20; //!< First SBAS satellite number
171static constexpr SvNr FIRST_GAL = 1; //!< First Galileo satellite number
172static constexpr SvNr FIRST_BDS = 1; //!< First BeiDou satellite number
173static constexpr SvNr FIRST_QZSS = 1; //!< First QZSS satellite number
174static constexpr SvNr FIRST_GLO = 1; //!< First GLONASS satellite number
175static constexpr SvNr FIRST_NAVIC = 1; //!< First NavIC satellite number
176static constexpr SvNr INAVLID_SVNR = 0; //!< Invalid satellite number (in any GNSS)
177// clang-format on
178
179// ---------------------------------------------------------------------------------------------------------------------
180
181/**
182 * @brief Satellite ("sat"), consisting of GNSS and satellite number, suitable for indexing and sorting
183 */
184using Sat = uint16_t;
185
186/**
187 * @brief Get "sat" from GNSS and satellite ID
188 *
189 * @note This does not do any range checking and it's up to the user to provide a valid satellite ID for the given GNSS.
190 *
191 * @param[in] gnss GNSS
192 * @param[in] svnr Satellite ID
193 *
194 * @returns the "sat"
195 */
196static constexpr Sat GnssSvNrToSat(const Gnss gnss, const SvNr svnr)
197{
198 return ((Sat)types::EnumToVal(gnss) << 8) | (Sat)svnr;
199}
200
201/**
202 * @brief Invalid "sat"
203 *
204 * @note This is not the only invalid combination of GNSS and satellite number!
205 */
207
208/**
209 * @brief Get GNSS from "sat"
210 *
211 * @param[in] sat The "sat"
212 *
213 * @returns the GNSS
214 */
215static constexpr Gnss SatToGnss(const Sat sat)
216{
217 return (Gnss)((sat >> 8) & 0xff);
218}
219
220/**
221 * @brief Get satellite nr from "sat"
222 *
223 * @param[in] sat The "sat"
224 *
225 * @returns the satellite nr
226 */
227static constexpr SvNr SatToSvNr(const Sat sat)
228{
229 return sat & 0xff;
230}
231
232// ---------------------------------------------------------------------------------------------------------------------
233
234/**
235 * @brief Satellite plus frequency band and signal ("satsig"), suitable for indexing and sorting
236 */
237using SatSig = uint32_t;
238
239/**
240 * @brief Get "satsig" from components
241 *
242 * @note This does not do any range checking and it's up to the user to provide a valid satellite ID for the given GNSS.
243 *
244 * @param[in] gnss GNSS
245 * @param[in] svnr Satellite ID
246 * @param[in] band Frequency band
247 * @param[in] signal Signal
248 *
249 * @returns the "satsig"
250 */
252 const Gnss gnss, const SvNr svnr, const Band band, const Signal signal)
253{
254 return ((SatSig)types::EnumToVal(gnss) << 24) | ((SatSig)svnr << 16) | ((SatSig)band << 8) | (SatSig)signal;
255}
256
257/**
258 * @brief Invalid "satsig""
259 *
260 * @note This is not the only invalid combination of GNSS, satellite number, band and signal!
261 */
262static constexpr SatSig INVALID_SATSIG =
264
265/**
266 * @brief Get GNSS from "satsig"
267 *
268 * @param[in] satsig The "satsig"
269 *
270 * @returns the GNSS
271 */
272static constexpr Gnss SatSigToGnss(const SatSig satsig)
273{
274 return (Gnss)((satsig >> 24) & 0xff);
275}
276
277/**
278 * @brief Get satellite nr from "satsig"
279 *
280 * @param[in] satsig The "satsig"
281 *
282 * @returns the satellite nr
283 */
284static constexpr SvNr SatSigToSvNr(const SatSig satsig)
285{
286 return (SvNr)((satsig >> 16) & 0xff);
287}
288
289/**
290 * @brief Get frequency band from "satsig"
291 *
292 * @param[in] satsig The "satsig"
293 *
294 * @returns the frequency band
295 */
296static constexpr Band SatSigToBand(const SatSig satsig)
297{
298 return (Band)((satsig >> 8) & 0xff);
299}
300
301/**
302 * @brief Get signal from "satsig"
303 *
304 * @param[in] satsig The "satsig"
305 *
306 * @returns the signal
307 */
308static constexpr Signal SatSigToSignal(const SatSig satsig)
309{
310 return (Signal)(satsig & 0xff);
311}
312
313// ---------------------------------------------------------------------------------------------------------------------
314
315/**
316 * @brief Stringify satellite
317 *
318 * @param[in] sat The satellite
319 *
320 * @returns a unique string identifying the satellite
321 */
322const char* SatStr(const Sat sat);
323
324/**
325 * @brief Satellite from string
326 *
327 * @param[in] str The string ("G03", "R22", "C12", ...)
328 *
329 * @returns the satellite (INVALID_SAT if str was invalid)
330 */
331Sat StrSat(const char* str);
332
333/**
334 * @brief Convert UBX gnssId to GNSS
335 *
336 * @param[in] gnssId UBX gnssId
337 *
338 * @returns the GNSS
339 */
340Gnss UbxGnssIdToGnss(const uint8_t gnssId);
341
342/**
343 * @brief Convert UBX gnssId and svId to satellite
344 *
345 * @param[in] gnssId UBX gnssId
346 * @param[in] svId UBX svId
347 *
348 * @returns the satellite, INVALID_SAT for invalid gnssId/svId
349 */
350Sat UbxGnssIdSvIdToSat(const uint8_t gnssId, const uint8_t svId);
351
352/**
353 * @brief Convert UBX gnssId and sigId to signal
354 *
355 * @param[in] gnssId UBX gnssId
356 * @param[in] sigId UBX sigId
357 *
358 * @returns the signal
359 */
360Signal UbxGnssIdSigIdToSignal(const uint8_t gnssId, const uint8_t sigId);
361
362/* ****************************************************************************************************************** */
363} // namespace gnss
364} // namespace common
365} // namespace fpsdk
366#endif // __FPSDK_COMMON_GNSS_HPP__
static constexpr SvNr NUM_QZSS
Number of QZSS satellites (J01-J10, PRN - 192)
Definition gnss.hpp:166
static constexpr Gnss SatSigToGnss(const SatSig satsig)
Get GNSS from "satsig".
Definition gnss.hpp:272
static constexpr Signal SatSigToSignal(const SatSig satsig)
Get signal from "satsig".
Definition gnss.hpp:308
static constexpr SvNr FIRST_GLO
First GLONASS satellite number.
Definition gnss.hpp:174
uint32_t SatSig
Satellite plus frequency band and signal ("satsig"), suitable for indexing and sorting.
Definition gnss.hpp:237
static constexpr SvNr FIRST_QZSS
First QZSS satellite number.
Definition gnss.hpp:173
@ QZSS_L1S
QZSS L1 S (SAIF) signal.
@ BDS_B2A
BeiDou B2a signal (B2 ap and B2 ad)
@ GLO_L2OF
GLONASS L2 OF signal.
@ QZSS_L1CA
QZSS L1 C/A signal.
@ GAL_E5A
Galileo E5a signal (E5 aI and E5 aQ)
@ GPS_L5
GPS L5 signal (L5 I and L5 Q)
@ QZSS_L5
QZSS L5 signal (L5 I and L5 Q)
@ BDS_B1C
BeiDou B1c signal (B1 Cp and B1 Cd)
@ BDS_B2I
BeiDou B2I signal (B2I D1 and B2I D2)
@ GLO_L1OF
GLONASS L1 OF signal.
@ UNKNOWN
Unknown/unspecified signal.
@ GAL_E1
Galileo E1 signal (E1 C and E1 B)
@ SBAS_L1CA
SBAS L1 C/A signal.
@ GAL_E5B
Galileo E5b signal (E5 bI and E5 bQ)
@ GPS_L1CA
GPS L1 C/A signal.
@ GPS_L2C
GPS L2 C signal (L2 CL and L2 CM)
@ BDS_B1I
BeiDou B1I signal (B1I D1 and B1I D2)
@ QZSS_L2C
QZSS L2 C signal (L2 CL and L2 CM)
uint8_t SvNr
Satellite number (within a GNSS)
Definition gnss.hpp:157
static constexpr SatSig GnssSvNrBandSignalToSatSig(const Gnss gnss, const SvNr svnr, const Band band, const Signal signal)
Get "satsig" from components.
Definition gnss.hpp:251
static constexpr SvNr FIRST_BDS
First BeiDou satellite number.
Definition gnss.hpp:172
Sat UbxGnssIdSvIdToSat(const uint8_t gnssId, const uint8_t svId)
Convert UBX gnssId and svId to satellite.
static constexpr SvNr NUM_GLO
Number of GLONASS satellites (R01-R32, slot)
Definition gnss.hpp:167
static constexpr SatSig INVALID_SATSIG
Invalid "satsig"".
Definition gnss.hpp:262
static constexpr SvNr FIRST_SBAS
First SBAS satellite number.
Definition gnss.hpp:170
static constexpr SvNr NUM_SBAS
Number of SBAS satellites (S20-S59, PRN - 100)
Definition gnss.hpp:163
static constexpr SvNr NUM_GAL
Number of Galileo satellites (E01-E36, PRN)
Definition gnss.hpp:164
Sat StrSat(const char *str)
Satellite from string.
Gnss UbxGnssIdToGnss(const uint8_t gnssId)
Convert UBX gnssId to GNSS.
static constexpr Sat INVALID_SAT
Invalid "sat".
Definition gnss.hpp:206
uint16_t Sat
Satellite ("sat"), consisting of GNSS and satellite number, suitable for indexing and sorting.
Definition gnss.hpp:184
@ UNKNOWN
Unknown/unspecified GNSS.
const char * BandStr(const Band band)
Stringify frequency band.
const char * GnssFixTypeStr(const GnssFixType fix_type)
Stringify GNSS fix type.
const char * SignalStr(const Signal signal)
Stringify signal.
static constexpr SvNr NUM_GPS
Number of GPS satellites (G01-G32, PRN)
Definition gnss.hpp:162
static constexpr SvNr SatSigToSvNr(const SatSig satsig)
Get satellite nr from "satsig".
Definition gnss.hpp:284
static constexpr Band SatSigToBand(const SatSig satsig)
Get frequency band from "satsig".
Definition gnss.hpp:296
static constexpr SvNr NUM_BDS
Number of BeiDou satellites (C01-C63, PRN)
Definition gnss.hpp:165
static constexpr SvNr FIRST_NAVIC
First NavIC satellite number.
Definition gnss.hpp:175
const char * GnssStr(const Gnss gnss)
Stringify GNSS.
static constexpr SvNr FIRST_GPS
First GPS satellite number.
Definition gnss.hpp:169
static constexpr SvNr SatToSvNr(const Sat sat)
Get satellite nr from "sat".
Definition gnss.hpp:227
static constexpr SvNr NUM_NAVIC
Number of NavIC satellites (I01-I14, PRN)
Definition gnss.hpp:168
static constexpr SvNr FIRST_GAL
First Galileo satellite number.
Definition gnss.hpp:171
const char * SatStr(const Sat sat)
Stringify satellite.
static constexpr Gnss SatToGnss(const Sat sat)
Get GNSS from "sat".
Definition gnss.hpp:215
Band
Frequency bands.
Definition gnss.hpp:129
@ L5
L5 band (~1.1GHz)
@ UNKNOWN
Unknown/unspecified band.
@ L2
L2 band (~1.2GHz)
@ L1
L1 band (~1.5GHz)
static constexpr SvNr INAVLID_SVNR
Invalid satellite number (in any GNSS)
Definition gnss.hpp:176
GnssFixType
GNSS fix types.
Definition gnss.hpp:43
@ DRONLY
Dead-reckoning only fix.
@ SPP_3D_DR
3D + dead-reckoning fix
@ RTK_FLOAT
RTK float fix (implies 3D fix)
@ RTK_FIXED_DR
RTK fixed fix + dead-reckoning (implies RTK_FIXED fix)
@ RTK_FLOAT_DR
RTK float fix + dead-reckoning (implies RTK_FLOAT fix)
@ RTK_FIXED
RTK fixed fix (implies 3D fix)
static constexpr Sat GnssSvNrToSat(const Gnss gnss, const SvNr svnr)
Get "sat" from GNSS and satellite ID.
Definition gnss.hpp:196
Band SignalToBand(const Signal signal)
Get frequency band for a signal.
Signal UbxGnssIdSigIdToSignal(const uint8_t gnssId, const uint8_t sigId)
Convert UBX gnssId and sigId to signal.
constexpr std::underlying_type< T >::type EnumToVal(T enum_val)
Convert enum class constant to the underlying integral type value.
Definition types.hpp:46
Fixposition SDK.
Fixposition SDK: Common types.