0.3.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
13
14#pragma once
15
16#include <cstdint>
17#include <string>
18#include <vector>
19#include <nlohmann/json.hpp>
20using json = nlohmann::json;
21#include <fmt/format.h>
22
23#include "SatelliteSystem.hpp"
24#include "Frequency.hpp"
25#include "Code.hpp"
26
28
29namespace NAV
30{
31
33struct SatId
34{
40
42 SatId() = default;
43
45 uint16_t satNum = 0;
46
50 constexpr bool operator==(const SatId& rhs) const { return satSys == rhs.satSys && satNum == rhs.satNum; }
51
55 constexpr bool operator<(const SatId& rhs) const
56 {
57 return satSys == rhs.satSys ? satNum < rhs.satNum
58 : satSys < rhs.satSys;
59 }
60
62 [[nodiscard]] bool isGeo() const;
63};
64
67{
72 : code(code), satNum(satNum) {}
73
75 SatSigId() = default;
76
78 uint16_t satNum = 0;
79
83 bool operator==(const SatSigId& rhs) const { return code == rhs.code && satNum == rhs.satNum; }
84
88 bool operator<(const SatSigId& rhs) const
89 {
90 if (toSatId().satSys == rhs.toSatId().satSys)
91 {
92 if (satNum == rhs.satNum)
93 {
94 return Code::Set(code) < Code::Set(rhs.code);
95 }
96 return satNum < rhs.satNum;
97 }
98 return toSatId().satSys < rhs.toSatId().satSys;
99 }
100
102 [[nodiscard]] SatId toSatId() const
103 {
104 return { code.getFrequency().getSatSys(), satNum };
105 }
106
108 [[nodiscard]] Frequency freq() const
109 {
110 return code.getFrequency();
111 }
112};
113
118bool lessCompareSatSigId(const std::string& lhs, const std::string& rhs);
119
123void to_json(json& j, const SatId& data);
127void from_json(const json& j, SatId& data);
128
132void to_json(json& j, const SatSigId& data);
136void from_json(const json& j, SatSigId& data);
137
143bool ShowSatelliteSelector(const char* label, std::vector<SatId>& satellites, SatelliteSystem filterSys = SatSys_All, bool displayOnlyNumber = false);
144
150bool ShowSatelliteSelector(const char* label, SatId& satellite, SatelliteSystem filterSys = SatSys_All, bool displayOnlyNumber = false);
151
152} // namespace NAV
153
158std::ostream& operator<<(std::ostream& os, const NAV::SatId& obj);
159
164std::ostream& operator<<(std::ostream& os, const NAV::SatSigId& obj);
165
166#ifndef DOXYGEN_IGNORE
167
169template<>
170struct fmt::formatter<NAV::SatId>
171{
175 static constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
176 {
177 return ctx.begin();
178 }
179
184 template<typename FormatContext>
185 auto format(const NAV::SatId& satId, FormatContext& ctx) const -> decltype(ctx.out())
186 {
187 return fmt::format_to(ctx.out(), "{0}{1:02d}", char(satId.satSys), satId.satNum);
188 }
189};
190
192template<>
193struct fmt::formatter<NAV::SatSigId>
194{
198 static constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
199 {
200 return ctx.begin();
201 }
202
207 template<typename FormatContext>
208 auto format(const NAV::SatSigId& satSigId, FormatContext& ctx) const
209 {
210 return fmt::format_to(ctx.out(), "{0}-{1:02d}", satSigId.code, satSigId.satNum);
211 }
212};
213
214#endif
215
216namespace std
217{
219template<>
220struct hash<NAV::SatId>
221{
224 std::size_t operator()(const NAV::SatId& f) const
225 {
226 auto hash1 = std::hash<NAV::SatelliteSystem_>{}(NAV::SatelliteSystem_(f.satSys));
227 auto hash2 = static_cast<size_t>(f.satNum);
228
229 return hash1 | (hash2 << 10);
230 }
231};
232
233template<>
234struct hash<NAV::SatSigId>
235{
238 std::size_t operator()(const NAV::SatSigId& f) const
239 {
240 auto hash1 = static_cast<size_t>(f.code.getEnumValue());
241 auto hash2 = static_cast<size_t>(f.satNum);
242
243 return hash1 | (hash2 << 8);
244 }
245};
246} // namespace std
Code definitions.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Frequency definition for different satellite systems.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Algorithms concerning the STL containers.
std::ostream & operator<<(std::ostream &os, const NAV::SatId &obj)
Stream insertion operator overload.
bool ShowSatelliteSelector(const char *label, std::vector< SatId > &satellites, SatelliteSystem filterSys=SatSys_All, bool displayOnlyNumber=false)
Shows a ComboBox to select satellites.
bool lessCompareSatSigId(const std::string &lhs, const std::string &rhs)
Less than comparison from string representation.
GNSS Satellite System.
SatelliteSystem_
Satellite System enumeration.
Definition SatelliteSystem.hpp:31
@ SatSys_None
No Satellite system.
Definition SatelliteSystem.hpp:32
constexpr SatelliteSystem_ SatSys_All
All Systems.
Definition SatelliteSystem.hpp:382
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)
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
Identifies a satellite (satellite system and number)
Definition SatelliteIdentifier.hpp:34
SatId(SatelliteSystem satSys, uint16_t satNum)
Constructor.
Definition SatelliteIdentifier.hpp:38
constexpr bool operator==(const SatId &rhs) const
Equal comparison (needed for unordered_map)
Definition SatelliteIdentifier.hpp:50
SatId()=default
Default constructor.
bool isGeo() const
Checks if the satellite is geostationary.
SatelliteSystem satSys
Satellite system (GPS, GLONASS, GALILEO, QZSS, BDS, IRNSS, SBAS)
Definition SatelliteIdentifier.hpp:44
uint16_t satNum
Number of the satellite.
Definition SatelliteIdentifier.hpp:45
constexpr bool operator<(const SatId &rhs) const
Less than comparison (needed for map)
Definition SatelliteIdentifier.hpp:55
Identifies a satellite signal (satellite frequency and number)
Definition SatelliteIdentifier.hpp:67
Code code
Code.
Definition SatelliteIdentifier.hpp:77
SatSigId()=default
Default constructor.
Frequency freq() const
Returns the frequency of the satellite signal.
Definition SatelliteIdentifier.hpp:108
uint16_t satNum
Number of the satellite.
Definition SatelliteIdentifier.hpp:78
bool operator<(const SatSigId &rhs) const
Less than comparison (needed for map)
Definition SatelliteIdentifier.hpp:88
SatSigId(Code code, uint16_t satNum)
Constructor.
Definition SatelliteIdentifier.hpp:71
bool operator==(const SatSigId &rhs) const
Equal comparison (needed for unordered_map)
Definition SatelliteIdentifier.hpp:83
SatId toSatId() const
Returns a satellite identifier for the satellite signal.
Definition SatelliteIdentifier.hpp:102
Satellite System type.
Definition SatelliteSystem.hpp:44
std::size_t operator()(const NAV::SatId &f) const
Hash function for SatId.
Definition SatelliteIdentifier.hpp:224
std::size_t operator()(const NAV::SatSigId &f) const
Hash function for SatSigId.
Definition SatelliteIdentifier.hpp:238