0.5.0
Loading...
Searching...
No Matches
SatelliteIdentifier.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 SatelliteIdentifier.hpp
10/// @brief Structs identifying a unique satellite
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2022-04-29
13
14#pragma once
15
16#include <cstdint>
17#include <string>
18#include <vector>
19#include <nlohmann/json.hpp>
20using json = nlohmann::json; ///< json namespace
21#include <fmt/format.h>
22
23#include "SatelliteSystem.hpp"
24#include "Frequency.hpp"
25#include "Code.hpp"
26
28
29namespace NAV
30{
31
32/// @brief Identifies a satellite (satellite system and number)
33struct SatId
34{
35 /// @brief Constructor
36 /// @param[in] satSys Satellite system
37 /// @param[in] satNum Number of the satellite
40
41 /// Default constructor
42 SatId() = default;
43
44 /// @brief Constructor from String representation
45 /// @param[in] str SatId as string
46 explicit SatId(const std::string& str)
47 : satSys(SatelliteSystem::fromChar(str.substr(0, 1).front())),
48 satNum(static_cast<uint16_t>(std::stoul(str.substr(1)))) {}
49
50 SatelliteSystem satSys = SatSys_None; ///< Satellite system (GPS, GLONASS, GALILEO, QZSS, BDS, IRNSS, SBAS)
51 uint16_t satNum = 0; ///< Number of the satellite
52
53 /// @brief Equal comparison (needed for unordered_map)
54 /// @param[in] rhs Right hand side of the operator
55 /// @return True if the elements are equal
56 constexpr bool operator==(const SatId& rhs) const { return satSys == rhs.satSys && satNum == rhs.satNum; }
57
58 /// @brief Less than comparison (needed for map)
59 /// @param[in] rhs Right hand side of the operator
60 /// @return True if lhs < rhs
61 constexpr bool operator<(const SatId& rhs) const
62 {
63 return satSys == rhs.satSys ? satNum < rhs.satNum
64 : satSys < rhs.satSys;
65 }
66
67 /// Checks if the satellite is geostationary
68 [[nodiscard]] bool isGeo() const;
69};
70
71/// @brief Identifies a satellite signal (satellite frequency and number)
73{
74 /// @brief Constructor
75 /// @param[in] code Signal code
76 /// @param[in] satNum Number of the satellite
78 : code(code), satNum(satNum) {}
79
80 /// Default constructor
81 SatSigId() = default;
82
83 /// @brief Constructor from String representation
84 /// @param[in] str SatSigId as string
85 explicit SatSigId(const std::string& str)
86 : code(str.substr(0, 3)),
87 satNum(static_cast<uint16_t>(std::stoul(str.substr(4)))) {}
88
89 Code code = Code::None; ///< Code
90 uint16_t satNum = 0; ///< Number of the satellite
91
92 /// @brief Equal comparison (needed for unordered_map)
93 /// @param[in] rhs Right hand side of the operator
94 /// @return True if the elements are equal
95 bool operator==(const SatSigId& rhs) const { return code == rhs.code && satNum == rhs.satNum; }
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 bool operator<(const SatSigId& rhs) const
101 {
102 if (toSatId().satSys == rhs.toSatId().satSys)
103 {
104 if (satNum == rhs.satNum)
105 {
106 return Code::Set(code) < Code::Set(rhs.code);
107 }
108 return satNum < rhs.satNum;
109 }
110 return toSatId().satSys < rhs.toSatId().satSys;
111 }
112
113 /// @brief Returns a satellite identifier for the satellite signal
114 [[nodiscard]] SatId toSatId() const
115 {
116 return { code.getFrequency().getSatSys(), satNum };
117 }
118
119 /// @brief Returns the frequency of the satellite signal
120 [[nodiscard]] Frequency freq() const
121 {
122 return code.getFrequency();
123 }
124};
125
126/// @brief Less than comparison from string representation
127/// @param[in] lhs Left hand side of the operator
128/// @param[in] rhs Right hand side of the operator
129/// @return True if lhs < rhs
130bool lessCompareSatSigId(const std::string& lhs, const std::string& rhs);
131
132/// @brief Converts the provided link into a json object
133/// @param[out] j Json object which gets filled with the info
134/// @param[in] data Data to convert into json
135void to_json(json& j, const SatId& data);
136/// @brief Converts the provided json object into a link object
137/// @param[in] j Json object with the needed values
138/// @param[out] data Object to fill from the json
139void from_json(const json& j, SatId& data);
140
141/// @brief Converts the provided link into a json object
142/// @param[out] j Json object which gets filled with the info
143/// @param[in] data Object to convert into json
144void to_json(json& j, const SatSigId& data);
145/// @brief Converts the provided json object into a link object
146/// @param[in] j Json object with the needed values
147/// @param[out] data Object to fill from the json
148void from_json(const json& j, SatSigId& data);
149
150/// @brief Shows a ComboBox to select satellites
151/// @param[in] label Label to show beside the combo box. This has to be a unique id for ImGui.
152/// @param[in, out] satellites Reference to the SatId vector to select
153/// @param[in] filterSys Enable/Disable GUI elements according to this filter
154/// @param[in] displayOnlyNumber Display only the number, not the system
155bool ShowSatelliteSelector(const char* label, std::vector<SatId>& satellites, SatelliteSystem filterSys = SatSys_All, bool displayOnlyNumber = false);
156
157/// @brief Shows a ComboBox to select a single satellite
158/// @param[in] label Label to show beside the combo box. This has to be a unique id for ImGui.
159/// @param[in, out] satellite Reference to the SatId to select
160/// @param[in] filterSys Enable/Disable GUI elements according to this filter
161/// @param[in] displayOnlyNumber Display only the number, not the system
162bool ShowSatelliteSelector(const char* label, SatId& satellite, SatelliteSystem filterSys = SatSys_All, bool displayOnlyNumber = false);
163
164} // namespace NAV
165
166/// @brief Stream insertion operator overload
167/// @param[in, out] os Output stream object to stream the time into
168/// @param[in] obj Object to print
169/// @return Returns the output stream object in order to chain stream insertions
170std::ostream& operator<<(std::ostream& os, const NAV::SatId& obj);
171
172/// @brief Stream insertion operator overload
173/// @param[in, out] os Output stream object to stream the time into
174/// @param[in] obj Object to print
175/// @return Returns the output stream object in order to chain stream insertions
176std::ostream& operator<<(std::ostream& os, const NAV::SatSigId& obj);
177
178#ifndef DOXYGEN_IGNORE
179
180/// @brief Formatter for SatId
181template<>
182struct fmt::formatter<NAV::SatId>
183{
184 /// @brief Parse function to make the struct formattable
185 /// @param[in] ctx Parser context
186 /// @return Beginning of the context
187 static constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
188 {
189 return ctx.begin();
190 }
191
192 /// @brief Defines how to format SatId structs
193 /// @param[in] satId Struct to format
194 /// @param[in, out] ctx Format context
195 /// @return Output iterator
196 template<typename FormatContext>
197 auto format(const NAV::SatId& satId, FormatContext& ctx) const -> decltype(ctx.out())
198 {
199 return fmt::format_to(ctx.out(), "{0}{1:02d}", char(satId.satSys), satId.satNum);
200 }
201};
202
203/// @brief Formatter for SatSigId
204template<>
205struct fmt::formatter<NAV::SatSigId>
206{
207 /// @brief Parse function to make the struct formattable
208 /// @param[in] ctx Parser context
209 /// @return Beginning of the context
210 static constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
211 {
212 return ctx.begin();
213 }
214
215 /// @brief Defines how to format SatSigId structs
216 /// @param[in] satSigId Struct to format
217 /// @param[in, out] ctx Format context
218 /// @return Output iterator
219 template<typename FormatContext>
220 auto format(const NAV::SatSigId& satSigId, FormatContext& ctx) const
221 {
222 return fmt::format_to(ctx.out(), "{0}-{1:02d}", satSigId.code, satSigId.satNum);
223 }
224};
225
226#endif
227
228namespace std
229{
230/// @brief Hash function for SatId (needed for unordered_map)
231template<>
232struct hash<NAV::SatId>
233{
234 /// @brief Hash function for SatId
235 /// @param[in] f Satellite identifier
236 std::size_t operator()(const NAV::SatId& f) const
237 {
238 auto hash1 = std::hash<NAV::SatelliteSystem_>{}(NAV::SatelliteSystem_(f.satSys));
239 auto hash2 = static_cast<size_t>(f.satNum);
240
241 return hash1 | (hash2 << 10);
242 }
243};
244/// @brief Hash function for SatSigId (needed for unordered_map)
245template<>
246struct hash<NAV::SatSigId>
247{
248 /// @brief Hash function for SatSigId
249 /// @param[in] f Satellite signal identifier
250 std::size_t operator()(const NAV::SatSigId& f) const
251 {
252 auto hash1 = static_cast<size_t>(f.code.getEnumValue());
253 auto hash2 = static_cast<size_t>(f.satNum);
254
255 return hash1 | (hash2 << 8);
256 }
257};
258} // namespace std
Code definitions.
nlohmann::json json
json namespace
Frequency definition for different satellite systems.
Algorithms concerning the STL containers.
std::ostream & operator<<(std::ostream &os, const NAV::SatId &obj)
Stream insertion operator overload.
GNSS Satellite System.
Enumerate for GNSS Codes.
Definition Code.hpp:89
std::bitset< COUNT > Set
Typedef for the bitset with size of COUNT.
Definition Code.hpp:293
@ None
None.
Definition Code.hpp:94
Enum getEnumValue() const
Returns the enum value for the code (only one must be set)
Definition Code.cpp:777
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
bool ShowSatelliteSelector(const char *label, std::vector< SatId > &satellites, SatelliteSystem filterSys, bool displayOnlyNumber)
Shows a ComboBox to select satellites.
bool lessCompareSatSigId(const std::string &lhs, const std::string &rhs)
Less than comparison from string representation.
SatelliteSystem_
Satellite System enumeration.
@ SatSys_None
No Satellite system.
constexpr SatelliteSystem_ SatSys_All
All Systems.
Identifies a satellite (satellite system and number)
SatId(SatelliteSystem satSys, uint16_t satNum)
Constructor.
constexpr bool operator==(const SatId &rhs) const
Equal comparison (needed for unordered_map)
SatId()=default
Default constructor.
bool isGeo() const
Checks if the satellite is geostationary.
SatelliteSystem satSys
Satellite system (GPS, GLONASS, GALILEO, QZSS, BDS, IRNSS, SBAS)
uint16_t satNum
Number of the satellite.
constexpr bool operator<(const SatId &rhs) const
Less than comparison (needed for map)
SatId(const std::string &str)
Constructor from String representation.
Identifies a satellite signal (satellite frequency and number)
SatSigId()=default
Default constructor.
Frequency freq() const
Returns the frequency of the satellite signal.
uint16_t satNum
Number of the satellite.
SatSigId(const std::string &str)
Constructor from String representation.
bool operator<(const SatSigId &rhs) const
Less than comparison (needed for map)
SatSigId(Code code, uint16_t satNum)
Constructor.
bool operator==(const SatSigId &rhs) const
Equal comparison (needed for unordered_map)
SatId toSatId() const
Returns a satellite identifier for the satellite signal.
Satellite System type.
std::size_t operator()(const NAV::SatId &f) const
Hash function for SatId.
std::size_t operator()(const NAV::SatSigId &f) const
Hash function for SatSigId.