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