0.3.0
Loading...
Searching...
No Matches
SatelliteSystem.cpp
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#include "SatelliteSystem.hpp"
10#include <algorithm>
11#include <cstdint>
12#include <optional>
13#include <unordered_set>
14
16#include "util/Logger.hpp"
17
18namespace NAV
19{
20
21SatelliteSystem SatelliteSystem::fromString(const std::string& typeString)
22{
23 if (typeString == "GPS" || typeString == "GP")
24 {
25 return GPS;
26 }
27 if (typeString == "GLONASS" || typeString == "GLO" || typeString == "GL")
28 {
29 return GLO;
30 }
31 if (typeString == "GALILEO" || typeString == "GAL" || typeString == "GA")
32 {
33 return GAL;
34 }
35 if (typeString == "QZSS" || typeString == "QZS" || typeString == "QZ")
36 {
37 return QZSS;
38 }
39 if (typeString == "BDS" || typeString == "BD")
40 {
41 return BDS;
42 }
43 if (typeString == "IRNSS" || typeString == "IRN" || typeString == "IR")
44 {
45 return IRNSS;
46 }
47 if (typeString == "SBAS" || typeString == "SB")
48 {
49 return SBAS;
50 }
51
52 return SatSys_None;
53}
54
56{
57 switch (typeChar)
58 {
59 case 'G':
60 return GPS;
61 case 'R':
62 return GLO;
63 case 'E':
64 return GAL;
65 case 'J':
66 case 'Q':
67 return QZSS;
68 case 'B':
69 case 'C':
70 return BDS;
71 case 'I':
72 return IRNSS;
73 case 'S':
74 return SBAS;
75 default:
76 return SatSys_None;
77 }
78}
79
81{
82 switch (enumeration)
83 {
85 return SatSys_None;
87 return GPS;
89 return GAL;
91 return GLO;
93 return BDS;
95 return QZSS;
97 return IRNSS;
99 return SBAS;
100 default:
101 return SatSys_None;
102 }
103}
104
105SatelliteSystem::operator std::string() const
106{
107 std::string str;
108 if (value & GPS) { str += ((!str.empty() ? " | " : "") + std::string("GPS")); }
109 if (value & GLO) { str += ((!str.empty() ? " | " : "") + std::string("GLO")); }
110 if (value & GAL) { str += ((!str.empty() ? " | " : "") + std::string("GAL")); }
111 if (value & QZSS) { str += ((!str.empty() ? " | " : "") + std::string("QZSS")); }
112 if (value & BDS) { str += ((!str.empty() ? " | " : "") + std::string("BDS")); }
113 if (value & IRNSS) { str += ((!str.empty() ? " | " : "") + std::string("IRNSS")); }
114 if (value & SBAS) { str += ((!str.empty() ? " | " : "") + std::string("SBAS")); }
115
116 return str.empty() ? "None" : str;
117}
118
119SatelliteSystem::operator char() const
120{
121 switch (value)
122 {
123 case GPS:
124 return 'G';
125 case GLO:
126 return 'R';
127 case GAL:
128 return 'E';
129 case QZSS:
130 return 'J';
131 case BDS:
132 return 'C';
133 case IRNSS:
134 return 'I';
135 case SBAS:
136 return 'S';
137 case SatSys_None:
138 return '-';
139 default:
140 return 'M';
141 }
142}
143
145{
146 switch (SatelliteSystem_(satSys))
147 {
148 case GPS:
149 return GPST;
150 case GLO:
151 return GLNT;
152 case GAL:
153 return GST;
154 case QZSS:
155 return QZSST;
156 case BDS:
157 return BDT;
158 case IRNSS:
159 return IRNSST;
160 case SBAS:
161 return GPST;
162 case SatSys_None:
163 break;
164 }
165 return TimeSys_None;
166}
167
172
174{
175 switch (SatelliteSystem_(satSys))
176 {
177 case GPS:
178 return { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 };
179 case GLO:
180 return { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
181 case GAL:
182 return { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
183 33, 34, 35, 36 };
184 case QZSS:
185 return { 1, 2, 3, 4, 5 };
186 case BDS:
187 return { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
188 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62 };
189 case IRNSS:
190 return { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
191 case SBAS:
192 return {
193 120, 234, 236, // EGNOS
194 131, 133, 135, 138, // WAAS
195 129, 137, // MSAS
196 127, 128, 132, // GAGAN
197 };
198 case SatSys_None:
199 break;
200 }
201 return {};
202}
203
204std::vector<uint16_t> SatelliteSystem::getSatellites() const
205{
207}
208
209std::optional<std::string> SatelliteSystem::GetSatelliteInfo(SatelliteSystem satSys, uint16_t satNum)
210{
211 switch (SatelliteSystem_(satSys))
212 {
213 case GPS:
214 break;
215 case GLO:
216 break;
217 case GAL:
218 break;
219 case QZSS:
220 if (SatId(satSys, satNum).isGeo()) { return "GEO"; }
221 else { return "QZO"; }
222 break;
223 case BDS:
224 if (SatId(satSys, satNum).isGeo()) { return "GEO"; }
225 else if (std::unordered_set<uint16_t> sats = {
226 6, 7, 8, 9, 10,
227 13, 16, 31, 38,
228 39, 40, 56 };
229 sats.contains(satNum)) { return "IGSO"; }
230 else { return "MEO"; }
231 case IRNSS:
232 if (SatId(satSys, satNum).isGeo()) { return "GEO"; }
233 else { return "IGSO"; }
234 break;
235 case SBAS:
236 if (satNum == 120 || satNum == 234 || satNum == 236) { return "EGNOS"; }
237 if (satNum == 131 || satNum == 133 || satNum == 135 || satNum == 138) { return "WAAS"; }
238 if (satNum == 129 || satNum == 137) { return "MSAS"; }
239 if (satNum == 127 || satNum == 128 || satNum == 132) { return "GAGAN"; }
240 break;
241 case SatSys_None:
242 break;
243 }
244 return std::nullopt;
245}
246
247std::optional<std::string> SatelliteSystem::getSatelliteInfo(uint16_t satNum) const
248{
249 return GetSatelliteInfo(value, satNum);
250}
251
253{
254 switch (SatelliteSystem_(satSys))
255 {
256 case SatSys_None:
257 return Enum_None;
258 case GPS:
259 return Enum_GPS;
260 case GAL:
261 return Enum_GAL;
262 case GLO:
263 return Enum_GLO;
264 case BDS:
265 return Enum_BDS;
266 case QZSS:
267 return Enum_QZSS;
268 case IRNSS:
269 return Enum_IRNSS;
270 case SBAS:
271 return Enum_SBAS;
272 }
273 return Enum_None;
274}
275
280
282{
283 return char(satSys);
284}
285
287{
288 return char(*this);
289}
290
291std::vector<SatelliteSystem> SatelliteSystem::ToVector(SatelliteSystem satSys)
292{
293 std::vector<SatelliteSystem> v;
294 for (const SatelliteSystem& sys : GetAll())
295 {
296 if (sys.value & satSys.value) { v.push_back(sys); }
297 }
298 return v;
299}
300
301std::vector<SatelliteSystem> SatelliteSystem::toVector() const
302{
303 return ToVector(value);
304}
305
306std::vector<SatelliteSystem> SatelliteSystem::GetAll()
307{
308 return { GPS, GAL, GLO, BDS, QZSS, IRNSS, SBAS };
309}
310
311void to_json(json& j, const SatelliteSystem& data)
312{
313 j = std::string(data);
314}
315void from_json(const json& j, SatelliteSystem& data)
316{
317 data = SatelliteSystem::fromString(j.get<std::string>());
318}
319
320std::ostream& operator<<(std::ostream& os, const SatelliteSystem& satSys)
321{
322 os << fmt::format("{}", satSys);
323 return os;
324}
325
326} // namespace NAV
nlohmann::json json
json namespace
Utility class for logging to console and file.
Structs identifying a unique satellite.
GNSS Satellite System.
Time System defintions.
@ IRNSST
Indian Regional Navigation Satellite System Time.
@ GST
Galileo System Time.
@ BDT
BeiDou Time.
@ GLNT
GLONASS Time (GLONASST)
@ TimeSys_None
No Time system.
@ QZSST
Quasi-Zenith Satellite System Time.
@ GPST
GPS Time.
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
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.
Identifies a satellite (satellite system and number)
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.
static std::vector< SatelliteSystem > ToVector(SatelliteSystem satSys)
Get a vector representation of the specified Satellite Systems.
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.
static char ToChar(SatelliteSystem satSys)
Get char representation of the specified Satellite System.
SatelliteSystem_ value
Internal value.
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 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.