Fixposition SDK 0.0.0-heads/main-0-gd0a6ce2
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 BDS_B3I, //!< BeiDou B3I signal (B3I D1 and B3I D2)
101 GAL_E1, //!< Galileo E1 signal (E1 C and E1 B)
102 GAL_E5A, //!< Galileo E5a signal (E5 aI and E5 aQ)
103 GAL_E5B, //!< Galileo E5b signal (E5 bI and E5 bQ)
104 GAL_E6, //!< Galileo E6 signal (E6A, E6B, adn E6C)
105 GLO_L1OF, //!< GLONASS L1 OF signal
106 GLO_L2OF, //!< GLONASS L2 OF signal
107 GPS_L1CA, //!< GPS L1 C/A signal
108 GPS_L2C, //!< GPS L2 C signal (L2 CL and L2 CM)
109 GPS_L5, //!< GPS L5 signal (L5 I and L5 Q)
110 QZSS_L1CA, //!< QZSS L1 C/A signal
111 QZSS_L1S, //!< QZSS L1 S (SAIF) signal
112 QZSS_L2C, //!< QZSS L2 C signal (L2 CL and L2 CM)
113 QZSS_L5, //!< QZSS L5 signal (L5 I and L5 Q)
114 SBAS_L1CA, //!< SBAS L1 C/A signal
115 NAVIC_L5A, //!< NavIC L5 A
116}; // clang-format on
117
118/**
119 * @brief Stringify signal
120 *
121 * @param[in] signal The signal
122 * @param[in] kurz Get short string (for example, "L1CA" instead of "GPS_L1CA")
123 *
124 * @returns a concise and unique string for the signal, "?" for bad values
125 */
126const char* SignalStr(const Signal signal, const bool kurz = false);
127
128/**
129 * @brief Frequency bands
130 */
131enum class Band : uint8_t
132{
133 UNKNOWN = 0, //!< Unknown/unspecified band
134 L1, //!< L1 band (~1.5GHz)
135 L2, //!< L2 band (~1.2GHz)
136 E6, //!< E6 band (~1.3GHz)
137 L5, //!< L5 band (~1.1GHz)
138};
139
140/**
141 * @brief Stringify frequency band
142 *
143 * @param[in] band The frequency band
144 *
145 * @returns a concise and unique string for the frequency band, "?" for bad values
146 */
147const char* BandStr(const Band band);
148
149/**
150 * @brief Get frequency band for a signal
151 *
152 * @param[in] signal The signal
153 *
154 * @returns the frequency band for the signal
155 */
157
158/**
159 * @brief Satellite number (within a GNSS)
160 */
161using SvNr = uint8_t;
162
163// Number of satellites per constellation, see https://igs.org/mgex/constellations/. Satellite numbers are two digits
164// satellite numbers as defined by IGS (see RINEX v3.04 section 3.5).
165// clang-format off
166static constexpr SvNr NUM_GPS = 32; //!< Number of GPS satellites (G01-G32, PRN)
167static constexpr SvNr NUM_SBAS = 39; //!< Number of SBAS satellites (S20-S59, PRN - 100)
168static constexpr SvNr NUM_GAL = 36; //!< Number of Galileo satellites (E01-E36, PRN)
169static constexpr SvNr NUM_BDS = 63; //!< Number of BeiDou satellites (C01-C63, PRN)
170static constexpr SvNr NUM_QZSS = 10; //!< Number of QZSS satellites (J01-J10, PRN - 192)
171static constexpr SvNr NUM_GLO = 32; //!< Number of GLONASS satellites (R01-R32, slot)
172static constexpr SvNr NUM_NAVIC = 14; //!< Number of NavIC satellites (I01-I14, PRN)
173static constexpr SvNr FIRST_GPS = 1; //!< First GPS satellite number
174static constexpr SvNr FIRST_SBAS = 20; //!< First SBAS satellite number
175static constexpr SvNr FIRST_GAL = 1; //!< First Galileo satellite number
176static constexpr SvNr FIRST_BDS = 1; //!< First BeiDou satellite number
177static constexpr SvNr FIRST_QZSS = 1; //!< First QZSS satellite number
178static constexpr SvNr FIRST_GLO = 1; //!< First GLONASS satellite number
179static constexpr SvNr FIRST_NAVIC = 1; //!< First NavIC satellite number
180static constexpr SvNr INAVLID_SVNR = 0; //!< Invalid satellite number (in any GNSS)
181// clang-format on
182
183// ---------------------------------------------------------------------------------------------------------------------
184
185/**
186 * @brief Satellite ("sat"), consisting of GNSS and satellite number, suitable for indexing and sorting
187 */
188using Sat = uint16_t;
189
190/**
191 * @brief Get "sat" from GNSS and satellite ID
192 *
193 * @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.
194 *
195 * @param[in] gnss GNSS
196 * @param[in] svnr Satellite ID
197 *
198 * @returns the "sat"
199 */
200static constexpr Sat GnssSvNrToSat(const Gnss gnss, const SvNr svnr)
201{
202 return ((Sat)types::EnumToVal(gnss) << 8) | (Sat)svnr;
203}
204
205/**
206 * @brief Invalid "sat"
207 *
208 * @note This is not the only invalid combination of GNSS and satellite number!
209 */
211
212/**
213 * @brief Get GNSS from "sat"
214 *
215 * @param[in] sat The "sat"
216 *
217 * @returns the GNSS
218 */
219static constexpr Gnss SatToGnss(const Sat sat)
220{
221 return (Gnss)((sat >> 8) & 0xff);
222}
223
224/**
225 * @brief Get satellite nr from "sat"
226 *
227 * @param[in] sat The "sat"
228 *
229 * @returns the satellite nr
230 */
231static constexpr SvNr SatToSvNr(const Sat sat)
232{
233 return sat & 0xff;
234}
235
236// ---------------------------------------------------------------------------------------------------------------------
237
238/**
239 * @brief Satellite plus frequency band and signal ("satsig"), suitable for indexing and sorting
240 */
241using SatSig = uint32_t;
242
243/**
244 * @brief Get "satsig" from components
245 *
246 * @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.
247 *
248 * @param[in] gnss GNSS
249 * @param[in] svnr Satellite ID
250 * @param[in] band Frequency band
251 * @param[in] signal Signal
252 *
253 * @returns the "satsig"
254 */
256 const Gnss gnss, const SvNr svnr, const Band band, const Signal signal)
257{
258 return ((SatSig)types::EnumToVal(gnss) << 24) | ((SatSig)svnr << 16) | ((SatSig)band << 8) | (SatSig)signal;
259}
260
261/**
262 * @brief Invalid "satsig""
263 *
264 * @note This is not the only invalid combination of GNSS, satellite number, band and signal!
265 */
266static constexpr SatSig INVALID_SATSIG =
268
269/**
270 * @brief Get GNSS from "satsig"
271 *
272 * @param[in] satsig The "satsig"
273 *
274 * @returns the GNSS
275 */
276static constexpr Gnss SatSigToGnss(const SatSig satsig)
277{
278 return (Gnss)((satsig >> 24) & 0xff);
279}
280
281/**
282 * @brief Get satellite nr from "satsig"
283 *
284 * @param[in] satsig The "satsig"
285 *
286 * @returns the satellite nr
287 */
288static constexpr SvNr SatSigToSvNr(const SatSig satsig)
289{
290 return (SvNr)((satsig >> 16) & 0xff);
291}
292
293/**
294 * @brief Get frequency band from "satsig"
295 *
296 * @param[in] satsig The "satsig"
297 *
298 * @returns the frequency band
299 */
300static constexpr Band SatSigToBand(const SatSig satsig)
301{
302 return (Band)((satsig >> 8) & 0xff);
303}
304
305/**
306 * @brief Get signal from "satsig"
307 *
308 * @param[in] satsig The "satsig"
309 *
310 * @returns the signal
311 */
312static constexpr Signal SatSigToSignal(const SatSig satsig)
313{
314 return (Signal)(satsig & 0xff);
315}
316
317// ---------------------------------------------------------------------------------------------------------------------
318
319/**
320 * @brief Stringify satellite
321 *
322 * @param[in] sat The satellite
323 *
324 * @returns a unique string identifying the satellite
325 */
326const char* SatStr(const Sat sat);
327
328/**
329 * @brief Satellite from string
330 *
331 * @param[in] str The string ("G03", "R22", "C12", ...)
332 *
333 * @returns the satellite (INVALID_SAT if str was invalid)
334 */
335Sat StrSat(const char* str);
336
337/**
338 * @brief Convert UBX gnssId to GNSS
339 *
340 * @param[in] gnssId UBX gnssId
341 *
342 * @returns the GNSS
343 */
344Gnss UbxGnssIdToGnss(const uint8_t gnssId);
345
346/**
347 * @brief Convert UBX gnssId and svId to satellite
348 *
349 * @param[in] gnssId UBX gnssId
350 * @param[in] svId UBX svId
351 *
352 * @returns the satellite, INVALID_SAT for invalid gnssId/svId
353 */
354Sat UbxGnssIdSvIdToSat(const uint8_t gnssId, const uint8_t svId);
355
356/**
357 * @brief Convert UBX gnssId and sigId to signal
358 *
359 * @param[in] gnssId UBX gnssId
360 * @param[in] sigId UBX sigId
361 *
362 * @returns the signal
363 */
364Signal UbxGnssIdSigIdToSignal(const uint8_t gnssId, const uint8_t sigId);
365
366/* ****************************************************************************************************************** */
367} // namespace gnss
368} // namespace common
369} // namespace fpsdk
370#endif // __FPSDK_COMMON_GNSS_HPP__
static constexpr SvNr NUM_QZSS
Number of QZSS satellites (J01-J10, PRN - 192)
Definition gnss.hpp:170
static constexpr Gnss SatSigToGnss(const SatSig satsig)
Get GNSS from "satsig".
Definition gnss.hpp:276
static constexpr Signal SatSigToSignal(const SatSig satsig)
Get signal from "satsig".
Definition gnss.hpp:312
static constexpr SvNr FIRST_GLO
First GLONASS satellite number.
Definition gnss.hpp:178
uint32_t SatSig
Satellite plus frequency band and signal ("satsig"), suitable for indexing and sorting.
Definition gnss.hpp:241
static constexpr SvNr FIRST_QZSS
First QZSS satellite number.
Definition gnss.hpp:177
@ QZSS_L1S
QZSS L1 S (SAIF) signal.
@ BDS_B2A
BeiDou B2a signal (B2 ap and B2 ad)
@ GAL_E6
Galileo E6 signal (E6A, E6B, adn E6C)
@ 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)
@ BDS_B3I
BeiDou B3I signal (B3I D1 and B3I D2)
@ 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:161
static constexpr SatSig GnssSvNrBandSignalToSatSig(const Gnss gnss, const SvNr svnr, const Band band, const Signal signal)
Get "satsig" from components.
Definition gnss.hpp:255
static constexpr SvNr FIRST_BDS
First BeiDou satellite number.
Definition gnss.hpp:176
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:171
static constexpr SatSig INVALID_SATSIG
Invalid "satsig"".
Definition gnss.hpp:266
static constexpr SvNr FIRST_SBAS
First SBAS satellite number.
Definition gnss.hpp:174
static constexpr SvNr NUM_SBAS
Number of SBAS satellites (S20-S59, PRN - 100)
Definition gnss.hpp:167
static constexpr SvNr NUM_GAL
Number of Galileo satellites (E01-E36, PRN)
Definition gnss.hpp:168
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:210
uint16_t Sat
Satellite ("sat"), consisting of GNSS and satellite number, suitable for indexing and sorting.
Definition gnss.hpp:188
@ UNKNOWN
Unknown/unspecified GNSS.
const char * BandStr(const Band band)
Stringify frequency band.
const char * GnssFixTypeStr(const GnssFixType fix_type)
Stringify GNSS fix type.
static constexpr SvNr NUM_GPS
Number of GPS satellites (G01-G32, PRN)
Definition gnss.hpp:166
static constexpr SvNr SatSigToSvNr(const SatSig satsig)
Get satellite nr from "satsig".
Definition gnss.hpp:288
static constexpr Band SatSigToBand(const SatSig satsig)
Get frequency band from "satsig".
Definition gnss.hpp:300
static constexpr SvNr NUM_BDS
Number of BeiDou satellites (C01-C63, PRN)
Definition gnss.hpp:169
static constexpr SvNr FIRST_NAVIC
First NavIC satellite number.
Definition gnss.hpp:179
const char * GnssStr(const Gnss gnss)
Stringify GNSS.
static constexpr SvNr FIRST_GPS
First GPS satellite number.
Definition gnss.hpp:173
static constexpr SvNr SatToSvNr(const Sat sat)
Get satellite nr from "sat".
Definition gnss.hpp:231
static constexpr SvNr NUM_NAVIC
Number of NavIC satellites (I01-I14, PRN)
Definition gnss.hpp:172
static constexpr SvNr FIRST_GAL
First Galileo satellite number.
Definition gnss.hpp:175
const char * SatStr(const Sat sat)
Stringify satellite.
static constexpr Gnss SatToGnss(const Sat sat)
Get GNSS from "sat".
Definition gnss.hpp:219
Band
Frequency bands.
Definition gnss.hpp:132
@ E6
E6 band (~1.3GHz)
@ 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:180
const char * SignalStr(const Signal signal, const bool kurz=false)
Stringify signal.
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:200
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.