signal_defs.h
Go to the documentation of this file.
1 /**************************************************************************/ /**
2  * @brief GNSS signal and frequency type definitions.
3  ******************************************************************************/
4 
5 #pragma once
6 
7 #include <cstdint>
8 #include <ostream>
9 
11 
12 namespace point_one {
13 namespace fusion_engine {
14 namespace messages {
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 // SatelliteType
18 ////////////////////////////////////////////////////////////////////////////////
19 
20 /**
21  * @name GNSS Constellation (System) Definitions
22  * @{
23  */
24 
25 /**
26  * @brief System/constellation type definitions.
27  */
28 enum class SatelliteType : uint8_t {
29  UNKNOWN = 0,
30  GPS = 1,
31  GLONASS = 2,
32  LEO = 3,
33  GALILEO = 4,
34  BEIDOU = 5,
35  QZSS = 6,
36  MIXED = 7,
37  SBAS = 8,
38  IRNSS = 9,
39  MAX_VALUE = IRNSS,
40 };
41 
42 /**
43  * @brief Get a human-friendly string name for the specified @ref SatelliteType
44  * (GNSS constellation).
45  * @ingroup enum_definitions
46  *
47  * @param type The desired satellite type.
48  *
49  * @return The corresponding string name.
50  */
52  switch (type) {
54  return "Unknown";
55 
56  case SatelliteType::GPS:
57  return "GPS";
58 
60  return "GLONASS";
61 
62  case SatelliteType::LEO:
63  return "LEO";
64 
66  return "Galileo";
67 
69  return "BeiDou";
70 
72  return "QZSS";
73 
75  return "Mixed";
76 
78  return "SBAS";
79 
81  return "IRNSS";
82 
83  default:
84  return "Invalid System";
85  }
86 }
87 
88 /**
89  * @brief @ref SatelliteType stream operator.
90  * @ingroup enum_definitions
91  */
92 inline std::ostream& operator<<(std::ostream& stream, SatelliteType type) {
93  stream << to_string(type) << " (" << (int)type << ")";
94  return stream;
95 }
96 
97 /** @} */
98 
99 /**
100  * @defgroup sat_type_masks @ref SatelliteType Bitmask Support
101  * @ingroup config_types
102  *
103  * These values can be used to specify a bitmask for controlling enabled GNSS
104  * constellations. The bit locations are equal to the values set by @ref
105  * SatelliteType for each constellation.
106  *
107  * For example, the mask 0x32 enables GPS, Galileo, and BeiDou. You can create
108  * that mask with the `SATELLITE_TYPE_MASK_*` constants:
109  * ```cpp
110  * uint32_t mask = SATELLITE_TYPE_MASK_GPS | SATELLITE_TYPE_MASK_GALILEO |
111  * SATELLITE_TYPE_MASK_BEIDOU;
112  * ```
113  *
114  * or by calling the @ref ToBitMask(SatelliteType) helper function:
115  * ```cpp
116  * uint32_t mask = ToBitMask(SatelliteType::GPS, SatelliteType::GALILEO,
117  * SatelliteType::BEIDOU);
118  * ```
119  *
120  * @{
121  */
122 
123 static constexpr uint32_t SATELLITE_TYPE_MASK_GPS =
124  (1UL << static_cast<uint8_t>(SatelliteType::GPS));
125 static constexpr uint32_t SATELLITE_TYPE_MASK_GLONASS =
126  (1UL << static_cast<uint8_t>(SatelliteType::GLONASS));
127 static constexpr uint32_t SATELLITE_TYPE_MASK_LEO =
128  (1UL << static_cast<uint8_t>(SatelliteType::LEO));
129 static constexpr uint32_t SATELLITE_TYPE_MASK_GALILEO =
130  (1UL << static_cast<uint8_t>(SatelliteType::GALILEO));
131 static constexpr uint32_t SATELLITE_TYPE_MASK_BEIDOU =
132  (1UL << static_cast<uint8_t>(SatelliteType::BEIDOU));
133 static constexpr uint32_t SATELLITE_TYPE_MASK_QZSS =
134  (1UL << static_cast<uint8_t>(SatelliteType::QZSS));
135 static constexpr uint32_t SATELLITE_TYPE_MASK_MIXED =
136  (1UL << static_cast<uint8_t>(SatelliteType::MIXED));
137 static constexpr uint32_t SATELLITE_TYPE_MASK_SBAS =
138  (1UL << static_cast<uint8_t>(SatelliteType::SBAS));
139 static constexpr uint32_t SATELLITE_TYPE_MASK_IRNSS =
140  (1UL << static_cast<uint8_t>(SatelliteType::IRNSS));
141 
142 static constexpr uint32_t SATELLITE_TYPE_MASK_ALL = 0xFFFFFFFF;
143 
144 /**
145  * @brief Convert a @ref SatelliteType to a corresponding constellation control
146  * bitmask value.
147  *
148  * For example:
149  *
150  * ```cpp
151  * uint32_t mask = ToBitMask(SatelliteType::GPS);
152  * ```
153  *
154  * generates the following bitmask:
155  *
156  * ```cpp
157  * uint32_t mask = (1UL << static_cast<uint8_t>(SatelliteType::GPS));
158  * ```
159  *
160  * @param type The desired constellation.
161  *
162  * @return The corresponding bitmask.
163  */
164 constexpr uint32_t ToBitMask(SatelliteType type) {
165  return (1U << (static_cast<uint8_t>(type)));
166 }
167 
168 /**
169  * @brief Convert two or more @ref SatelliteType values to a bitmask.
170  *
171  * For example:
172  *
173  * ```cpp
174  * uint32_t mask = ToBitMask(SatelliteType::GPS, SatelliteType::GALILEO,
175  * SatelliteType::BEIDOU);
176  * ```
177  *
178  * generates the following bitmask:
179  *
180  * ```cpp
181  * uint32_t mask = (1UL << static_cast<uint8_t>(SatelliteType::GPS)) |
182  * (1UL << static_cast<uint8_t>(SatelliteType::GALILEO)) |
183  * (1UL << static_cast<uint8_t>(SatelliteType::BEIDOU));
184  * ```
185  *
186  * @tparam Args The type of the `others` values (@ref SatelliteType)
187  * @param first The first value.
188  * @param others One or more additional values.
189  *
190  * @return The corresponding bitmask.
191  */
192 template <typename... Args>
193 constexpr uint32_t ToBitMask(SatelliteType first, Args... others) {
194  return ToBitMask(first) | ToBitMask(others...);
195 }
196 
197 /** @} */
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 // FrequencyBand
201 ////////////////////////////////////////////////////////////////////////////////
202 
203 /**
204  * @name GNSS Constellation (System) Definitions
205  * @{
206  */
207 
208 /**
209  * @brief GNSS frequency band definitions.
210  */
211 enum class FrequencyBand : uint8_t {
212  UNKNOWN = 0,
213  /**
214  * L1 band = 1561.098 MHz (BeiDou B1) -> 1602.0 (GLONASS G1)
215  * Includes: GPS/QZSS L1, Galileo E1 (same as GPS L1), BeiDou B1I and B1C
216  * (same as GPS L1), GLONASS G1
217  */
218  L1 = 1,
219  /**
220  * L2 band = 1202.025 MHz (G3) -> 1248.06 (G2)
221  * Includes: GPS L2, Galileo E5b, BeiDou B2I (same as Galileo E5b),
222  * GLONASS G2 & G3
223  */
224  L2 = 2,
225  /**
226  * L5 band = 1176.45 MHz (L5)
227  * Includes: GPS/QZSS L5, Galileo E5a, BeiDou B2a, IRNSS L5
228  */
229  L5 = 5,
230  /**
231  * L2 band = 1262.52 MHz (B3) -> 1278.75 (QZSS L6)
232  * Includes: Galileo E6, BeiDou B3, QZSS L6
233  */
234  L6 = 6,
235  MAX_VALUE = L6,
236 };
237 
238 /**
239  * @brief Get a human-friendly string name for the specified @ref FrequencyBand.
240  * @ingroup enum_definitions
241  *
242  * @param type The desired frequency band.
243  *
244  * @return The corresponding string name.
245  */
247  switch (type) {
249  return "Unknown";
250 
251  case FrequencyBand::L1:
252  return "L1";
253 
254  case FrequencyBand::L2:
255  return "L2";
256 
257  case FrequencyBand::L5:
258  return "L5";
259 
260  case FrequencyBand::L6:
261  return "L6";
262 
263  default:
264  return "Invalid Frequency Band";
265  }
266 }
267 
268 /**
269  * @brief @ref FrequencyBand stream operator.
270  * @ingroup enum_definitions
271  */
272 inline std::ostream& operator<<(std::ostream& stream, FrequencyBand type) {
273  stream << to_string(type) << " (" << (int)type << ")";
274  return stream;
275 }
276 
277 /** @} */
278 
279 /**
280  * @defgroup freq_band_masks @ref FrequencyBand Bitmask Support
281  * @ingroup config_types
282  *
283  * These values can be used to specify a bitmask for controlling enabled GNSS
284  * frequency bands. The bit locations are equal to the values set by @ref
285  * FrequencyBand.
286  *
287  * For example, the mask 0x22 enables L1 and L5. You can create that mask with
288  * the `FREQUENCY_BAND_MASK_*` constants:
289  * ```cpp
290  * uint32_t mask = FREQUENCY_BAND_MASK_L1 | FREQUENCY_BAND_MASK_L5;
291  * ```
292  *
293  * or by calling the @ref ToBitMask(FrequencyBand) helper function:
294  * ```cpp
295  * uint32_t mask = ToBitMask(FrequencyBand::L1, FrequencyBand::L5);
296  * ```
297  *
298  * @{
299  */
300 
301 static constexpr uint32_t FREQUENCY_BAND_MASK_L1 =
302  (1UL << static_cast<uint8_t>(FrequencyBand::L1));
303 static constexpr uint32_t FREQUENCY_BAND_MASK_L2 =
304  (1UL << static_cast<uint8_t>(FrequencyBand::L2));
305 static constexpr uint32_t FREQUENCY_BAND_MASK_L5 =
306  (1UL << static_cast<uint8_t>(FrequencyBand::L5));
307 static constexpr uint32_t FREQUENCY_BAND_MASK_L6 =
308  (1UL << static_cast<uint8_t>(FrequencyBand::L6));
309 
310 static constexpr uint32_t FREQUENCY_BAND_MASK_ALL = 0xFFFFFFFF;
311 
312 /**
313  * @brief Convert a @ref FrequencyBand to a corresponding frequency control
314  * bitmask value.
315  *
316  * For example:
317  *
318  * ```cpp
319  * uint32_t mask = ToBitMask(FrequencyBand::L1);
320  * ```
321  *
322  * generates the following bitmask:
323  *
324  * ```cpp
325  * uint32_t mask = (1UL << static_cast<uint8_t>(FrequencyBand::L1));
326  * ```
327  *
328  * @param type The desired frequency band.
329  *
330  * @return The corresponding bitmask.
331  */
332 constexpr uint32_t ToBitMask(FrequencyBand type) {
333  return (1U << (static_cast<uint8_t>(type)));
334 }
335 
336 /**
337  * @brief Convert two or more @ref FrequencyBand values to a bitmask.
338  *
339  * For example:
340  *
341  * ```cpp
342  * uint32_t mask = ToBitMask(FrequencyBand::L1, FrequencyBand::L5);
343  * ```
344  *
345  * generates the following bitmask:
346  *
347  * ```cpp
348  * uint32_t mask = (1UL << static_cast<uint8_t>(FrequencyBand::L1)) |
349  * (1UL << static_cast<uint8_t>(FrequencyBand::L5));
350  * ```
351  *
352  * @tparam Args The type of the `others` values (@ref FrequencyBand)
353  * @param first The first value.
354  * @param others One or more additional values.
355  *
356  * @return The corresponding bitmask.
357  */
358 template <typename... Args>
359 constexpr uint32_t ToBitMask(FrequencyBand first, Args... others) {
360  return ToBitMask(first) | ToBitMask(others...);
361 }
362 
363 /** @} */
364 
365 } // namespace messages
366 } // namespace fusion_engine
367 } // namespace point_one
@ MAX_VALUE
static constexpr uint32_t SATELLITE_TYPE_MASK_GLONASS
Definition: signal_defs.h:125
@ GPS
static constexpr uint32_t SATELLITE_TYPE_MASK_GALILEO
Definition: signal_defs.h:129
Library portability helper definitions.
@ UNKNOWN
static constexpr uint32_t SATELLITE_TYPE_MASK_GPS
Definition: signal_defs.h:123
@ MAX_VALUE
static constexpr uint32_t FREQUENCY_BAND_MASK_L5
Definition: signal_defs.h:305
static constexpr uint32_t SATELLITE_TYPE_MASK_BEIDOU
Definition: signal_defs.h:131
static constexpr uint32_t SATELLITE_TYPE_MASK_ALL
Definition: signal_defs.h:142
@ L5
L5 band = 1176.45 MHz (L5) Includes: GPS/QZSS L5, Galileo E5a, BeiDou B2a, IRNSS L5.
@ GALILEO
GNSS signal and frequency type definitions.
Definition: logging.h:36
@ SBAS
static constexpr uint32_t FREQUENCY_BAND_MASK_L2
Definition: signal_defs.h:303
static constexpr uint32_t SATELLITE_TYPE_MASK_QZSS
Definition: signal_defs.h:133
P1_CONSTEXPR_FUNC const char * to_string(ConfigType type)
Get a human-friendly string name for the specified ConfigType.
@ QZSS
static constexpr uint32_t FREQUENCY_BAND_MASK_ALL
Definition: signal_defs.h:310
static constexpr uint32_t SATELLITE_TYPE_MASK_MIXED
Definition: signal_defs.h:135
@ UNKNOWN
@ L6
L2 band = 1262.52 MHz (B3) -> 1278.75 (QZSS L6) Includes: Galileo E6, BeiDou B3, QZSS L6.
static constexpr uint32_t FREQUENCY_BAND_MASK_L6
Definition: signal_defs.h:307
@ LEO
#define P1_CONSTEXPR_FUNC
Definition: portability.h:58
SatelliteType
System/constellation type definitions.
Definition: signal_defs.h:28
static constexpr uint32_t SATELLITE_TYPE_MASK_SBAS
Definition: signal_defs.h:137
FrequencyBand
GNSS frequency band definitions.
Definition: signal_defs.h:211
static constexpr uint32_t SATELLITE_TYPE_MASK_LEO
Definition: signal_defs.h:127
std::ostream & operator<<(std::ostream &stream, ConfigType type)
ConfigType stream operator.
@ MIXED
static constexpr uint32_t SATELLITE_TYPE_MASK_IRNSS
Definition: signal_defs.h:139
@ GLONASS
static constexpr uint32_t FREQUENCY_BAND_MASK_L1
Definition: signal_defs.h:301
@ BEIDOU
@ L1
L1 band = 1561.098 MHz (BeiDou B1) -> 1602.0 (GLONASS G1) Includes: GPS/QZSS L1, Galileo E1 (same as ...
@ IRNSS
constexpr uint32_t ToBitMask(SatelliteType type)
Convert a SatelliteType to a corresponding constellation control bitmask value.
Definition: signal_defs.h:164
@ L2
L2 band = 1202.025 MHz (G3) -> 1248.06 (G2) Includes: GPS L2, Galileo E5b, BeiDou B2I (same as Galile...