Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
15 | #include "SatelliteIdentifier.hpp" | ||
16 | #include "util/Logger.hpp" | ||
17 | |||
18 | namespace NAV | ||
19 | { | ||
20 | |||
21 | 193 | SatelliteSystem SatelliteSystem::fromString(const std::string& typeString) | |
22 | { | ||
23 |
5/6✓ Branch 1 taken 151 times.
✓ Branch 2 taken 42 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 151 times.
✓ Branch 6 taken 42 times.
✓ Branch 7 taken 151 times.
|
193 | if (typeString == "GPS" || typeString == "GP") |
24 | { | ||
25 | 42 | return GPS; | |
26 | } | ||
27 |
4/8✓ Branch 1 taken 151 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 151 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 151 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 151 times.
|
151 | if (typeString == "GLONASS" || typeString == "GLO" || typeString == "GL") |
28 | { | ||
29 | ✗ | return GLO; | |
30 | } | ||
31 |
6/8✓ Branch 1 taken 151 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 141 times.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 141 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 141 times.
|
151 | if (typeString == "GALILEO" || typeString == "GAL" || typeString == "GA") |
32 | { | ||
33 | 10 | return GAL; | |
34 | } | ||
35 |
6/8✓ Branch 1 taken 134 times.
✓ Branch 2 taken 7 times.
✓ Branch 4 taken 134 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 134 times.
✓ Branch 9 taken 7 times.
✓ Branch 10 taken 134 times.
|
141 | if (typeString == "QZSS" || typeString == "QZS" || typeString == "QZ") |
36 | { | ||
37 | 7 | return QZSS; | |
38 | } | ||
39 |
5/6✓ Branch 1 taken 21 times.
✓ Branch 2 taken 113 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
✓ Branch 6 taken 113 times.
✓ Branch 7 taken 21 times.
|
134 | if (typeString == "BDS" || typeString == "BD") |
40 | { | ||
41 | 113 | return BDS; | |
42 | } | ||
43 |
2/8✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 21 times.
✗ Branch 10 not taken.
|
21 | if (typeString == "IRNSS" || typeString == "IRN" || typeString == "IR") |
44 | { | ||
45 | 21 | return IRNSS; | |
46 | } | ||
47 | ✗ | if (typeString == "SBAS" || typeString == "SB") | |
48 | { | ||
49 | ✗ | return SBAS; | |
50 | } | ||
51 | |||
52 | ✗ | return SatSys_None; | |
53 | } | ||
54 | |||
55 | 267488 | SatelliteSystem SatelliteSystem::fromChar(char typeChar) | |
56 | { | ||
57 |
8/8✓ Branch 0 taken 83092 times.
✓ Branch 1 taken 61329 times.
✓ Branch 2 taken 68940 times.
✓ Branch 3 taken 2690 times.
✓ Branch 4 taken 46937 times.
✓ Branch 5 taken 1190 times.
✓ Branch 6 taken 3272 times.
✓ Branch 7 taken 38 times.
|
267488 | switch (typeChar) |
58 | { | ||
59 | 83092 | case 'G': | |
60 | 83092 | return GPS; | |
61 | 61329 | case 'R': | |
62 | 61329 | return GLO; | |
63 | 68940 | case 'E': | |
64 | 68940 | return GAL; | |
65 | 2690 | case 'J': | |
66 | case 'Q': | ||
67 | 2690 | return QZSS; | |
68 | 46937 | case 'B': | |
69 | case 'C': | ||
70 | 46937 | return BDS; | |
71 | 1190 | case 'I': | |
72 | 1190 | return IRNSS; | |
73 | 3272 | case 'S': | |
74 | 3272 | return SBAS; | |
75 | 38 | default: | |
76 | 38 | return SatSys_None; | |
77 | } | ||
78 | } | ||
79 | |||
80 | ✗ | SatelliteSystem SatelliteSystem::fromEnum(SatelliteSystem::Enum enumeration) | |
81 | { | ||
82 | ✗ | switch (enumeration) | |
83 | { | ||
84 | ✗ | case SatelliteSystem::Enum_None: | |
85 | ✗ | return SatSys_None; | |
86 | ✗ | case SatelliteSystem::Enum_GPS: | |
87 | ✗ | return GPS; | |
88 | ✗ | case SatelliteSystem::Enum_GAL: | |
89 | ✗ | return GAL; | |
90 | ✗ | case SatelliteSystem::Enum_GLO: | |
91 | ✗ | return GLO; | |
92 | ✗ | case SatelliteSystem::Enum_BDS: | |
93 | ✗ | return BDS; | |
94 | ✗ | case SatelliteSystem::Enum_QZSS: | |
95 | ✗ | return QZSS; | |
96 | ✗ | case SatelliteSystem::Enum_IRNSS: | |
97 | ✗ | return IRNSS; | |
98 | ✗ | case SatelliteSystem::Enum_SBAS: | |
99 | ✗ | return SBAS; | |
100 | ✗ | default: | |
101 | ✗ | return SatSys_None; | |
102 | } | ||
103 | } | ||
104 | |||
105 | 124 | SatelliteSystem::operator std::string() const | |
106 | { | ||
107 | 124 | std::string str; | |
108 |
6/10✓ Branch 1 taken 56 times.
✓ Branch 2 taken 68 times.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 56 times.
✓ Branch 10 taken 56 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 56 times.
✗ Branch 14 not taken.
|
236 | if (value & GPS) { str += ((!str.empty() ? " | " : "") + std::string("GPS")); } |
109 |
7/10✓ Branch 1 taken 18 times.
✓ Branch 2 taken 106 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 12 times.
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 18 times.
✗ Branch 14 not taken.
|
160 | if (value & GLO) { str += ((!str.empty() ? " | " : "") + std::string("GLO")); } |
110 |
7/10✓ Branch 1 taken 36 times.
✓ Branch 2 taken 88 times.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 28 times.
✓ Branch 10 taken 36 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 36 times.
✗ Branch 14 not taken.
|
196 | if (value & GAL) { str += ((!str.empty() ? " | " : "") + std::string("GAL")); } |
111 |
6/10✓ Branch 1 taken 4 times.
✓ Branch 2 taken 120 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
|
132 | if (value & QZSS) { str += ((!str.empty() ? " | " : "") + std::string("QZSS")); } |
112 |
7/10✓ Branch 1 taken 26 times.
✓ Branch 2 taken 98 times.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 20 times.
✓ Branch 10 taken 26 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 26 times.
✗ Branch 14 not taken.
|
176 | if (value & BDS) { str += ((!str.empty() ? " | " : "") + std::string("BDS")); } |
113 |
1/10✗ Branch 1 not taken.
✓ Branch 2 taken 124 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
124 | if (value & IRNSS) { str += ((!str.empty() ? " | " : "") + std::string("IRNSS")); } |
114 |
6/10✓ Branch 1 taken 4 times.
✓ Branch 2 taken 120 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
|
132 | if (value & SBAS) { str += ((!str.empty() ? " | " : "") + std::string("SBAS")); } |
115 | |||
116 |
6/10✓ Branch 1 taken 8 times.
✓ Branch 2 taken 116 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 116 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 116 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
256 | return str.empty() ? "None" : str; |
117 | 124 | } | |
118 | |||
119 | 280318 | SatelliteSystem::operator char() const | |
120 | { | ||
121 |
9/9✓ Branch 0 taken 89567 times.
✓ Branch 1 taken 53321 times.
✓ Branch 2 taken 93645 times.
✓ Branch 3 taken 1733 times.
✓ Branch 4 taken 39175 times.
✓ Branch 5 taken 1183 times.
✓ Branch 6 taken 1636 times.
✓ Branch 7 taken 36 times.
✓ Branch 8 taken 22 times.
|
280318 | switch (value) |
122 | { | ||
123 | 89567 | case GPS: | |
124 | 89567 | return 'G'; | |
125 | 53321 | case GLO: | |
126 | 53321 | return 'R'; | |
127 | 93645 | case GAL: | |
128 | 93645 | return 'E'; | |
129 | 1733 | case QZSS: | |
130 | 1733 | return 'J'; | |
131 | 39175 | case BDS: | |
132 | 39175 | return 'C'; | |
133 | 1183 | case IRNSS: | |
134 | 1183 | return 'I'; | |
135 | 1636 | case SBAS: | |
136 | 1636 | return 'S'; | |
137 | 36 | case SatSys_None: | |
138 | 36 | return '-'; | |
139 | 22 | default: | |
140 | 22 | return 'M'; | |
141 | } | ||
142 | } | ||
143 | |||
144 | 42202 | TimeSystem SatelliteSystem::GetTimeSystemForSatelliteSystem(SatelliteSystem satSys) | |
145 | { | ||
146 |
7/9✓ Branch 1 taken 18565 times.
✓ Branch 2 taken 4158 times.
✓ Branch 3 taken 3502 times.
✓ Branch 4 taken 2172 times.
✓ Branch 5 taken 13784 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
42202 | switch (SatelliteSystem_(satSys)) |
147 | { | ||
148 | 18565 | case GPS: | |
149 | 18565 | return GPST; | |
150 | 4158 | case GLO: | |
151 | 4158 | return GLNT; | |
152 | 3502 | case GAL: | |
153 | 3502 | return GST; | |
154 | 2172 | case QZSS: | |
155 | 2172 | return QZSST; | |
156 | 13784 | case BDS: | |
157 | 13784 | return BDT; | |
158 | 4 | case IRNSS: | |
159 | 4 | return IRNSST; | |
160 | 18 | case SBAS: | |
161 | 18 | return GPST; | |
162 | ✗ | case SatSys_None: | |
163 | ✗ | break; | |
164 | } | ||
165 | ✗ | return TimeSys_None; | |
166 | } | ||
167 | |||
168 | 42202 | TimeSystem SatelliteSystem::getTimeSystem() const | |
169 | { | ||
170 | 42202 | return GetTimeSystemForSatelliteSystem(value); | |
171 | } | ||
172 | |||
173 | 896 | std::vector<uint16_t> SatelliteSystem::GetSatellitesForSatelliteSystem(SatelliteSystem satSys) | |
174 | { | ||
175 |
7/9✓ Branch 1 taken 128 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 128 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 128 times.
✓ Branch 6 taken 128 times.
✓ Branch 7 taken 128 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
896 | switch (SatelliteSystem_(satSys)) |
176 | { | ||
177 | 128 | case GPS: | |
178 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | 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 | 128 | case GLO: | |
180 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | 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 | 128 | 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 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | 33, 34, 35, 36 }; |
184 | 128 | case QZSS: | |
185 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | return { 1, 2, 3, 4, 5 }; |
186 | 128 | 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 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | 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 | 128 | case IRNSS: | |
190 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | return { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
191 | 128 | 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 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
384 | }; |
198 | ✗ | case SatSys_None: | |
199 | ✗ | break; | |
200 | } | ||
201 | ✗ | return {}; | |
202 | } | ||
203 | |||
204 | 896 | std::vector<uint16_t> SatelliteSystem::getSatellites() const | |
205 | { | ||
206 |
1/2✓ Branch 2 taken 896 times.
✗ Branch 3 not taken.
|
896 | return GetSatellitesForSatelliteSystem(value); |
207 | } | ||
208 | |||
209 | ✗ | std::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 | |||
247 | ✗ | std::optional<std::string> SatelliteSystem::getSatelliteInfo(uint16_t satNum) const | |
248 | { | ||
249 | ✗ | return GetSatelliteInfo(value, satNum); | |
250 | } | ||
251 | |||
252 | ✗ | SatelliteSystem::Enum SatelliteSystem::ToEnumeration(SatelliteSystem satSys) | |
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 | |||
276 | ✗ | SatelliteSystem::Enum SatelliteSystem::toEnumeration() const | |
277 | { | ||
278 | ✗ | return ToEnumeration(*this); | |
279 | } | ||
280 | |||
281 | ✗ | char SatelliteSystem::ToChar(SatelliteSystem satSys) | |
282 | { | ||
283 | ✗ | return char(satSys); | |
284 | } | ||
285 | |||
286 | 70888 | char SatelliteSystem::toChar() const | |
287 | { | ||
288 | 70888 | return char(*this); | |
289 | } | ||
290 | |||
291 | 168 | std::vector<SatelliteSystem> SatelliteSystem::ToVector(SatelliteSystem satSys) | |
292 | { | ||
293 | 168 | std::vector<SatelliteSystem> v; | |
294 |
3/4✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 1176 times.
✓ Branch 9 taken 168 times.
|
1344 | for (const SatelliteSystem& sys : GetAll()) |
295 | { | ||
296 |
3/4✓ Branch 1 taken 294 times.
✓ Branch 2 taken 882 times.
✓ Branch 4 taken 294 times.
✗ Branch 5 not taken.
|
1176 | if (sys.value & satSys.value) { v.push_back(sys); } |
297 | 168 | } | |
298 | 168 | return v; | |
299 | ✗ | } | |
300 | |||
301 | 168 | std::vector<SatelliteSystem> SatelliteSystem::toVector() const | |
302 | { | ||
303 |
1/2✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
|
168 | return ToVector(value); |
304 | } | ||
305 | |||
306 | 4051178 | std::vector<SatelliteSystem> SatelliteSystem::GetAll() | |
307 | { | ||
308 |
1/2✓ Branch 1 taken 4051003 times.
✗ Branch 2 not taken.
|
12153359 | return { GPS, GAL, GLO, BDS, QZSS, IRNSS, SBAS }; |
309 | } | ||
310 | |||
311 | ✗ | void to_json(json& j, const SatelliteSystem& data) | |
312 | { | ||
313 | ✗ | j = std::string(data); | |
314 | ✗ | } | |
315 | 91 | void from_json(const json& j, SatelliteSystem& data) | |
316 | { | ||
317 |
2/4✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 91 times.
✗ Branch 5 not taken.
|
91 | data = SatelliteSystem::fromString(j.get<std::string>()); |
318 | 91 | } | |
319 | |||
320 | ✗ | std::ostream& operator<<(std::ostream& os, const SatelliteSystem& satSys) | |
321 | { | ||
322 | ✗ | os << fmt::format("{}", satSys); | |
323 | ✗ | return os; | |
324 | } | ||
325 | |||
326 | } // namespace NAV | ||
327 |