0.5.0
Loading...
Searching...
No Matches
SatelliteSystem.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9/// @file SatelliteSystem.hpp
10/// @brief GNSS Satellite System
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2022-04-22
13
14#pragma once
15
16#include <cstdint>
17#include <string>
18#include <vector>
19#include <fmt/format.h>
20
21#include <nlohmann/json.hpp>
22using json = nlohmann::json; ///< json namespace
23
25
26namespace NAV
27{
28
29/// @brief Satellite System enumeration
30enum SatelliteSystem_ : uint64_t
31{ // clang-format off
32 SatSys_None = 0x0000'0000'0000'0000, ///< No Satellite system
33 GPS = 0x0000'0000'0000'00FF, ///< Global Positioning System
34 GAL = 0x0000'0000'0000'FF00, ///< Galileo
35 GLO = 0x0000'0000'00FF'0000, ///< Globalnaja nawigazionnaja sputnikowaja sistema (GLONASS)
36 BDS = 0x0000'0000'FF00'0000, ///< Beidou
37 QZSS = 0x0000'00FF'0000'0000, ///< Quasi-Zenith Satellite System
38 IRNSS = 0x0000'FF00'0000'0000, ///< Indian Regional Navigation Satellite System
39 SBAS = 0x00FF'0000'0000'0000, ///< Satellite Based Augmentation System
40}; // clang-format on
41
42/// @brief Satellite System type
44{
45 /// @brief Satellite System enumeration with continuous range. Not usable as a mask
46 enum Enum : uint8_t
47 {
48 Enum_GPS, ///< Global Positioning System
49 Enum_GAL, ///< Galileo
50 Enum_GLO, ///< Globalnaja nawigazionnaja sputnikowaja sistema (GLONASS)
51 Enum_BDS, ///< Beidou
52 Enum_QZSS, ///< Quasi-Zenith Satellite System
53 Enum_IRNSS, ///< Indian Regional Navigation Satellite System
54 Enum_SBAS, ///< Satellite Based Augmentation System
55 Enum_COUNT, ///< Count variable
56 Enum_None, ///< No Satellite system
57 };
58
59 /// @brief Default Constructor
60 constexpr SatelliteSystem() = default;
61
62 /// @brief Implicit Constructor from Value type
63 /// @param[in] type Value type to construct from
64 constexpr SatelliteSystem(SatelliteSystem_ type) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
65 : value(type)
66 {}
67
68 /// @brief Implicit Constructor from Enum type
69 /// @param[in] enumeration Enum type to construct from
70 SatelliteSystem(Enum enumeration) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
71 : value(SatelliteSystem::fromEnum(enumeration))
72 {}
73
74 /// @brief Construct new object from std::string
75 /// @param[in] typeString String representation of the satellite system
76 static SatelliteSystem fromString(const std::string& typeString);
77
78 /// @brief Construct new object from char
79 /// @param[in] typeChar Character representation of the satellite system
80 static SatelliteSystem fromChar(char typeChar);
81
82 /// @brief Constructs a new object from continuous enumeration
83 /// @param[in] enumeration Continuous enumeration of the satellite system
84 static SatelliteSystem fromEnum(Enum enumeration);
85
86 /// @brief Assignment operator from Value type
87 /// @param[in] v Value type to construct from
88 /// @return The Type type from the value type
90 {
91 value = v;
92 return *this;
93 }
94
95 friend constexpr bool operator==(const SatelliteSystem& lhs, const SatelliteSystem& rhs);
96
97 /// @brief Less than comparison (needed for map)
98 /// @param[in] rhs Right hand side of the operator
99 /// @return True if lhs < rhs
100 constexpr bool operator<(const SatelliteSystem& rhs) const { return value < rhs.value; }
101
102 /// @brief Allow switch(SatelliteSystem_(type)) and comparisons
103 constexpr explicit operator SatelliteSystem_() const { return value; }
104 /// @brief Prevent usage: if(...)
105 constexpr explicit operator bool() = delete;
106
107 /// @brief int conversion operator
108 /// @return A int representation of the type
109 constexpr explicit operator uint64_t() const { return uint64_t(value); }
110
111 /// @brief std::string conversion operator
112 /// @return A std::string representation of the type
113 explicit operator std::string() const;
114
115 /// @brief char conversion operator
116 /// @return A char representation of the type
117 explicit operator char() const;
118
119 /// @brief Get the Time System of the specified Satellite System
120 /// @param[in] satSys Satellite System to get the time system for
122
123 /// @brief Get the Time System of this Satellite System
124 [[nodiscard]] TimeSystem getTimeSystem() const;
125
126 /// @brief Get a list of satellites in the constellation
127 /// @param[in] satSys Satellite System to get the list for
128 static std::vector<uint16_t> GetSatellitesForSatelliteSystem(SatelliteSystem satSys);
129
130 /// @brief Get a list of satellites in the constellation
131 [[nodiscard]] std::vector<uint16_t> getSatellites() const;
132
133 /// @brief Get additional information about the satellite if available
134 /// @param[in] satSys Satellite System
135 /// @param[in] satNum Satellite Number
136 /// @return Optional String of additional information
137 static std::optional<std::string> GetSatelliteInfo(SatelliteSystem satSys, uint16_t satNum);
138
139 /// @brief Get additional information about the satellite if available
140 /// @param[in] satNum Satellite Number
141 /// @return Optional String of additional information
142 [[nodiscard]] std::optional<std::string> getSatelliteInfo(uint16_t satNum) const;
143
144 /// @brief Get the continuous enumeration of the specified Satellite System
145 /// @param[in] satSys Satellite System to get the continuous enumeration for
146 static Enum ToEnumeration(SatelliteSystem satSys);
147
148 /// @brief Returns a continuous enumeration of the object
149 [[nodiscard]] Enum toEnumeration() const;
150
151 /// @brief Get char representation of the specified Satellite System
152 /// @param[in] satSys Satellite System to get the continuous enumeration for
153 static char ToChar(SatelliteSystem satSys);
154
155 /// @brief Returns the char representation of the object
156 [[nodiscard]] char toChar() const;
157
158 /// @brief Get a vector representation of the specified Satellite Systems
159 /// @param[in] satSys Satellite System to get the vector for
160 static std::vector<SatelliteSystem> ToVector(SatelliteSystem satSys);
161
162 /// @brief Get a vector representation of the specified Satellite Systems
163 [[nodiscard]] std::vector<SatelliteSystem> toVector() const;
164
165 /// @brief Returns a list with all possible satellite systems
166 static std::vector<SatelliteSystem> GetAll();
167
168 private:
169 /// @brief Internal value
171};
172
173// #########################################################################################################################################
174
175/// @brief Converts the provided link into a json object
176/// @param[out] j Json object which gets filled with the info
177/// @param[in] data Data to convert into json
178void to_json(json& j, const SatelliteSystem& data);
179/// @brief Converts the provided json object into a link object
180/// @param[in] j Json object with the needed values
181/// @param[out] data Object to fill from the json
182void from_json(const json& j, SatelliteSystem& data);
183
184// #########################################################################################################################################
185
186/// @brief Allows combining flags of the SatelliteSystem enum.
187/// @param[in] lhs Left-hand side enum value.
188/// @param[in] rhs Right-hand side enum value.
189/// @return The binary ORed value.
191{
192 return SatelliteSystem_(uint64_t(lhs) | uint64_t(rhs));
193}
194/// @brief Allows combining flags of the SatelliteSystem enum.
195/// @param[in] lhs Left-hand side enum value.
196/// @param[in] rhs Right-hand side enum value.
197/// @return The binary ORed value.
202/// @brief Allows combining flags of the SatelliteSystem enum.
203/// @param[in] lhs Left-hand side enum value.
204/// @param[in] rhs Right-hand side enum value.
205/// @return The binary ORed value.
207{
208 return lhs | SatelliteSystem_(rhs);
209}
210/// @brief Allows combining flags of the SatelliteSystem enum.
211/// @param[in] lhs Left-hand side enum value.
212/// @param[in] rhs Right-hand side enum value.
213/// @return The binary ORed value.
215{
216 return SatelliteSystem_(lhs) | rhs;
217}
218
219/// @brief Allows combining flags of the SatelliteSystem enum.
220/// @param[in] lhs Left-hand side enum value.
221/// @param[in] rhs Right-hand side enum value.
222/// @return The binary ORed value.
224{
225 lhs = lhs | rhs;
226 return lhs;
227}
228/// @brief Allows combining flags of the SatelliteSystem enum.
229/// @param[in] lhs Left-hand side enum value.
230/// @param[in] rhs Right-hand side enum value.
231/// @return The binary ORed value.
233{
234 lhs = lhs | rhs;
235 return lhs;
236}
237/// @brief Allows combining flags of the SatelliteSystem enum.
238/// @param[in] lhs Left-hand side enum value.
239/// @param[in] rhs Right-hand side enum value.
240/// @return The binary ORed value.
242{
243 lhs = lhs | SatelliteSystem_(rhs);
244 return lhs;
245}
246/// @brief Allows combining flags of the SatelliteSystem enum.
247/// @param[in] lhs Left-hand side enum value.
248/// @param[in] rhs Right-hand side enum value.
249/// @return The binary ORed value.
251{
252 lhs = lhs | rhs;
253 return lhs;
254}
255
256/// @brief Allows combining flags of the SatelliteSystem enum.
257/// @param[in] lhs Left-hand side enum value.
258/// @param[in] rhs Right-hand side enum value.
259/// @return The binary ANDed value.
261{
262 return SatelliteSystem_(uint64_t(lhs) & uint64_t(rhs));
263}
264/// @brief Allows combining flags of the SatelliteSystem enum.
265/// @param[in] lhs Left-hand side enum value.
266/// @param[in] rhs Right-hand side enum value.
267/// @return The binary ANDed value.
269{
270 return SatelliteSystem_(lhs) & SatelliteSystem_(rhs);
271}
272/// @brief Allows combining flags of the SatelliteSystem enum.
273/// @param[in] lhs Left-hand side enum value.
274/// @param[in] rhs Right-hand side enum value.
275/// @return The binary ANDed value.
277{
278 return SatelliteSystem_(lhs) & rhs;
279}
280/// @brief Allows combining flags of the SatelliteSystem enum.
281/// @param[in] lhs Left-hand side enum value.
282/// @param[in] rhs Right-hand side enum value.
283/// @return The binary ANDed value.
285{
286 return lhs & SatelliteSystem_(rhs);
287}
288
289/// @brief Allows combining flags of the SatelliteSystem enum.
290/// @param[in] lhs Left-hand side enum value.
291/// @param[in] rhs Right-hand side enum value.
292/// @return The binary ANDed value.
294{
295 lhs = lhs & rhs;
296 return lhs;
297}
298/// @brief Allows combining flags of the SatelliteSystem enum.
299/// @param[in] lhs Left-hand side enum value.
300/// @param[in] rhs Right-hand side enum value.
301/// @return The binary ANDed value.
303{
304 lhs = lhs & rhs;
305 return lhs;
306}
307/// @brief Allows combining flags of the SatelliteSystem enum.
308/// @param[in] lhs Left-hand side enum value.
309/// @param[in] rhs Right-hand side enum value.
310/// @return The binary ANDed value.
312{
313 lhs = lhs & SatelliteSystem_(rhs);
314 return lhs;
315}
316/// @brief Allows combining flags of the SatelliteSystem enum.
317/// @param[in] lhs Left-hand side enum value.
318/// @param[in] rhs Right-hand side enum value.
319/// @return The binary ANDed value.
321{
322 lhs = lhs & rhs;
323 return lhs;
324}
325
326/// @brief Allows negating flags of the SatelliteSystem enum.
327/// @param[in] rhs Right-hand side enum value.
328/// @return The binary NEGed value.
330{
331 return SatelliteSystem_(~uint64_t(rhs));
332}
333/// @brief Allows negating flags of the SatelliteSystem enum.
334/// @param[in] rhs Right-hand side enum value.
335/// @return The binary NEGed value.
337{
338 return SatelliteSystem_(~uint64_t(rhs));
339}
340
341// #########################################################################################################################################
342
343/// @brief Equal compares values
344/// @param[in] lhs Left-hand side of the operator
345/// @param[in] rhs Right-hand side of the operator
346/// @return Whether the comparison was successful
347constexpr bool operator==(const SatelliteSystem& lhs, const SatelliteSystem& rhs) { return lhs.value == rhs.value; }
348/// @brief Equal compares values
349/// @param[in] lhs Left-hand side of the operator
350/// @param[in] rhs Right-hand side of the operator
351/// @return Whether the comparison was successful
352constexpr bool operator==(const SatelliteSystem& lhs, const SatelliteSystem_& rhs) { return lhs == SatelliteSystem(rhs); }
353/// @brief Equal compares values
354/// @param[in] lhs Left-hand side of the operator
355/// @param[in] rhs Right-hand side of the operator
356/// @return Whether the comparison was successful
357constexpr bool operator==(const SatelliteSystem_& lhs, const SatelliteSystem& rhs) { return SatelliteSystem(lhs) == rhs; }
358
359/// @brief Inequal compares values
360/// @param[in] lhs Left-hand side of the operator
361/// @param[in] rhs Right-hand side of the operator
362/// @return Whether the comparison was successful
363constexpr bool operator!=(const SatelliteSystem& lhs, const SatelliteSystem& rhs) { return !(lhs == rhs); }
364/// @brief Inequal compares values
365/// @param[in] lhs Left-hand side of the operator
366/// @param[in] rhs Right-hand side of the operator
367/// @return Whether the comparison was successful
368constexpr bool operator!=(const SatelliteSystem& lhs, const SatelliteSystem_& rhs) { return !(lhs == rhs); }
369/// @brief Inequal compares values
370/// @param[in] lhs Left-hand side of the operator
371/// @param[in] rhs Right-hand side of the operator
372/// @return Whether the comparison was successful
373constexpr bool operator!=(const SatelliteSystem_& lhs, const SatelliteSystem& rhs) { return !(lhs == rhs); }
374
375/// @brief Stream insertion operator overload
376/// @param[in, out] os Output stream object to stream the time into
377/// @param[in] satSys Object to print
378/// @return Returns the output stream object in order to chain stream insertions
379std::ostream& operator<<(std::ostream& os, const SatelliteSystem& satSys);
380
381/// All Systems
383
384} // namespace NAV
385
386namespace std
387{
388/// @brief Hash function for SatelliteSystem (needed for unordered_map)
389template<>
390struct hash<NAV::SatelliteSystem_>
391{
392 /// @brief Hash function for SatelliteSystem
393 /// @param[in] satSys Satellite system
394 std::size_t operator()(const NAV::SatelliteSystem_& satSys) const
395 {
396 using namespace NAV; // NOLINT(google-build-using-namespace)
397 switch (satSys)
398 {
399 case SatSys_None:
400 return 1;
401 case GPS:
402 return 100;
403 case GAL:
404 return 200;
405 case GLO:
406 return 300;
407 case BDS:
408 return 400;
409 case QZSS:
410 return 500;
411 case IRNSS:
412 return 600;
413 case SBAS:
414 return 700;
415 }
416 return 0;
417 }
418};
419/// @brief Hash function for SatelliteSystem (needed for unordered_map)
420template<>
421struct hash<NAV::SatelliteSystem>
422{
423 /// @brief Hash function for SatelliteSystem
424 /// @param[in] satSys Satellite system
425 std::size_t operator()(const NAV::SatelliteSystem& satSys) const
426 {
427 return std::hash<NAV::SatelliteSystem_>()(NAV::SatelliteSystem_(satSys));
428 }
429};
430} // namespace std
431
432#ifndef DOXYGEN_IGNORE
433
434/// @brief Formatter for SatelliteSystem
435template<>
436struct fmt::formatter<NAV::SatelliteSystem> : fmt::formatter<std::string>
437{
438 /// @brief Defines how to format SatelliteSystem structs
439 /// @param[in] satSys Struct to format
440 /// @param[in, out] ctx Format context
441 /// @return Output iterator
442 template<typename FormatContext>
443 auto format(const NAV::SatelliteSystem& satSys, FormatContext& ctx) const
444 {
445 return fmt::formatter<std::string>::format(std::string(satSys), ctx);
446 }
447};
448
449#endif
nlohmann::json json
json namespace
Time System defintions.
Time System defintions.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
constexpr Frequency_ operator~(Frequency_ rhs)
Allows negating flags of the Frequency enum.
constexpr Frequency_ & operator&=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
Code operator&(const Code &lhs, const Code &rhs)
Definition Code.cpp:808
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
constexpr Frequency_ & operator|=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
constexpr bool operator!=(const Node::Kind &lhs, const Node::Kind &rhs)
Inequal compares Node::Kind values.
Definition Node.hpp:506
constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Definition Node.hpp:501
Code operator|(const Code &lhs, const Code &rhs)
Definition Code.cpp:784
std::ostream & operator<<(std::ostream &os, const SatelliteSystem &satSys)
Stream insertion operator overload.
SatelliteSystem_
Satellite System enumeration.
@ GPS
Global Positioning System.
@ QZSS
Quasi-Zenith Satellite System.
@ GLO
Globalnaja nawigazionnaja sputnikowaja sistema (GLONASS)
@ GAL
Galileo.
@ SBAS
Satellite Based Augmentation System.
@ BDS
Beidou.
@ SatSys_None
No Satellite system.
@ IRNSS
Indian Regional Navigation Satellite System.
constexpr SatelliteSystem_ SatSys_All
All Systems.
Satellite System type.
TimeSystem getTimeSystem() const
Get the Time System of this Satellite System.
char toChar() const
Returns the char representation of the object.
static SatelliteSystem fromEnum(Enum enumeration)
Constructs a new object from continuous enumeration.
static SatelliteSystem fromString(const std::string &typeString)
Construct new object from std::string.
static SatelliteSystem fromChar(char typeChar)
Construct new object from char.
constexpr bool operator<(const SatelliteSystem &rhs) const
Less than comparison (needed for map)
static std::vector< SatelliteSystem > ToVector(SatelliteSystem satSys)
Get a vector representation of the specified Satellite Systems.
constexpr SatelliteSystem & operator=(SatelliteSystem_ v)
Assignment operator from Value type.
constexpr SatelliteSystem()=default
Default Constructor.
static std::vector< uint16_t > GetSatellitesForSatelliteSystem(SatelliteSystem satSys)
Get a list of satellites in the constellation.
std::optional< std::string > getSatelliteInfo(uint16_t satNum) const
Get additional information about the satellite if available.
static TimeSystem GetTimeSystemForSatelliteSystem(SatelliteSystem satSys)
Get the Time System of the specified Satellite System.
static std::vector< SatelliteSystem > GetAll()
Returns a list with all possible satellite systems.
SatelliteSystem(Enum enumeration)
Implicit Constructor from Enum type.
static char ToChar(SatelliteSystem satSys)
Get char representation of the specified Satellite System.
SatelliteSystem_ value
Internal value.
friend constexpr bool operator==(const SatelliteSystem &lhs, const SatelliteSystem &rhs)
Equal compares values.
constexpr SatelliteSystem(SatelliteSystem_ type)
Implicit Constructor from Value type.
static std::optional< std::string > GetSatelliteInfo(SatelliteSystem satSys, uint16_t satNum)
Get additional information about the satellite if available.
std::vector< SatelliteSystem > toVector() const
Get a vector representation of the specified Satellite Systems.
Enum
Satellite System enumeration with continuous range. Not usable as a mask.
@ Enum_GPS
Global Positioning System.
@ Enum_None
No Satellite system.
@ Enum_GLO
Globalnaja nawigazionnaja sputnikowaja sistema (GLONASS)
@ Enum_IRNSS
Indian Regional Navigation Satellite System.
@ Enum_QZSS
Quasi-Zenith Satellite System.
@ Enum_SBAS
Satellite Based Augmentation System.
@ Enum_COUNT
Count variable.
Enum toEnumeration() const
Returns a continuous enumeration of the object.
static Enum ToEnumeration(SatelliteSystem satSys)
Get the continuous enumeration of the specified Satellite System.
std::vector< uint16_t > getSatellites() const
Get a list of satellites in the constellation.
std::size_t operator()(const NAV::SatelliteSystem &satSys) const
Hash function for SatelliteSystem.
std::size_t operator()(const NAV::SatelliteSystem_ &satSys) const
Hash function for SatelliteSystem.