INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Core/SatelliteSystem.cpp
Date: 2025-07-19 10:51:51
Exec Total Coverage
Lines: 122 203 60.1%
Functions: 15 21 71.4%
Branches: 126 280 45.0%

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 207 SatelliteSystem SatelliteSystem::fromString(const std::string& typeString)
22 {
23
5/6
✓ Branch 1 taken 165 times.
✓ Branch 2 taken 42 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 165 times.
✓ Branch 6 taken 42 times.
✓ Branch 7 taken 165 times.
207 if (typeString == "GPS" || typeString == "GP")
24 {
25 42 return GPS;
26 }
27
4/8
✓ Branch 1 taken 165 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 165 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 165 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 165 times.
165 if (typeString == "GLONASS" || typeString == "GLO" || typeString == "GL")
28 {
29 return GLO;
30 }
31
6/8
✓ Branch 1 taken 165 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 154 times.
✓ Branch 5 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 154 times.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 154 times.
165 if (typeString == "GALILEO" || typeString == "GAL" || typeString == "GA")
32 {
33 11 return GAL;
34 }
35
6/8
✓ Branch 1 taken 146 times.
✓ Branch 2 taken 8 times.
✓ Branch 4 taken 146 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 146 times.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 146 times.
154 if (typeString == "QZSS" || typeString == "QZS" || typeString == "QZ")
36 {
37 8 return QZSS;
38 }
39
5/6
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 122 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
✓ Branch 6 taken 122 times.
✓ Branch 7 taken 24 times.
146 if (typeString == "BDS" || typeString == "BD")
40 {
41 122 return BDS;
42 }
43
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 24 times.
✗ Branch 10 not taken.
24 if (typeString == "IRNSS" || typeString == "IRN" || typeString == "IR")
44 {
45 24 return IRNSS;
46 }
47 if (typeString == "SBAS" || typeString == "SB")
48 {
49 return SBAS;
50 }
51
52 return SatSys_None;
53 }
54
55 291287 SatelliteSystem SatelliteSystem::fromChar(char typeChar)
56 {
57
8/8
✓ Branch 0 taken 97058 times.
✓ Branch 1 taken 61327 times.
✓ Branch 2 taken 78725 times.
✓ Branch 3 taken 2690 times.
✓ Branch 4 taken 46938 times.
✓ Branch 5 taken 1190 times.
✓ Branch 6 taken 3314 times.
✓ Branch 7 taken 45 times.
291287 switch (typeChar)
58 {
59 97058 case 'G':
60 97058 return GPS;
61 61327 case 'R':
62 61327 return GLO;
63 78725 case 'E':
64 78725 return GAL;
65 2690 case 'J':
66 case 'Q':
67 2690 return QZSS;
68 46938 case 'B':
69 case 'C':
70 46938 return BDS;
71 1190 case 'I':
72 1190 return IRNSS;
73 3314 case 'S':
74 3314 return SBAS;
75 45 default:
76 45 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 38591 SatelliteSystem::operator std::string() const
106 {
107 38591 std::string str;
108
6/10
✓ Branch 1 taken 19289 times.
✓ Branch 2 taken 19302 times.
✓ Branch 4 taken 19289 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 19289 times.
✓ Branch 10 taken 19289 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 19289 times.
✗ Branch 14 not taken.
77169 if (value & GPS) { str += ((!str.empty() ? " | " : "") + std::string("GPS")); }
109
7/10
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 38573 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.
38627 if (value & GLO) { str += ((!str.empty() ? " | " : "") + std::string("GLO")); }
110
7/10
✓ Branch 1 taken 19270 times.
✓ Branch 2 taken 19321 times.
✓ Branch 4 taken 19270 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 19262 times.
✓ Branch 10 taken 19270 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 19270 times.
✗ Branch 14 not taken.
77131 if (value & GAL) { str += ((!str.empty() ? " | " : "") + std::string("GAL")); }
111
6/10
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 38587 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.
38599 if (value & QZSS) { str += ((!str.empty() ? " | " : "") + std::string("QZSS")); }
112
7/10
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 38565 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.
38643 if (value & BDS) { str += ((!str.empty() ? " | " : "") + std::string("BDS")); }
113
1/10
✗ Branch 1 not taken.
✓ Branch 2 taken 38591 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.
38591 if (value & IRNSS) { str += ((!str.empty() ? " | " : "") + std::string("IRNSS")); }
114
6/10
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 38587 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.
38599 if (value & SBAS) { str += ((!str.empty() ? " | " : "") + std::string("SBAS")); }
115
116
6/10
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 38583 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 38583 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 38583 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
77190 return str.empty() ? "None" : str;
117 38591 }
118
119 291321 SatelliteSystem::operator char() const
120 {
121
9/9
✓ Branch 0 taken 108619 times.
✓ Branch 1 taken 53321 times.
✓ Branch 2 taken 85596 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.
291321 switch (value)
122 {
123 108619 case GPS:
124 108619 return 'G';
125 53321 case GLO:
126 53321 return 'R';
127 85596 case GAL:
128 85596 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 45320 TimeSystem SatelliteSystem::GetTimeSystemForSatelliteSystem(SatelliteSystem satSys)
145 {
146
7/9
✓ Branch 1 taken 20123 times.
✓ Branch 2 taken 4158 times.
✓ Branch 3 taken 3554 times.
✓ Branch 4 taken 2380 times.
✓ Branch 5 taken 15084 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
45320 switch (SatelliteSystem_(satSys))
147 {
148 20123 case GPS:
149 20123 return GPST;
150 4158 case GLO:
151 4158 return GLNT;
152 3554 case GAL:
153 3554 return GST;
154 2380 case QZSS:
155 2380 return QZSST;
156 15084 case BDS:
157 15084 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 45320 TimeSystem SatelliteSystem::getTimeSystem() const
169 {
170 45320 return GetTimeSystemForSatelliteSystem(value);
171 }
172
173 6734 std::vector<uint16_t> SatelliteSystem::GetSatellitesForSatelliteSystem(SatelliteSystem satSys)
174 {
175
7/9
✓ Branch 1 taken 962 times.
✓ Branch 2 taken 962 times.
✓ Branch 3 taken 962 times.
✓ Branch 4 taken 962 times.
✓ Branch 5 taken 962 times.
✓ Branch 6 taken 962 times.
✓ Branch 7 taken 962 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6734 switch (SatelliteSystem_(satSys))
176 {
177 962 case GPS:
178
1/2
✓ Branch 1 taken 962 times.
✗ Branch 2 not taken.
2886 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 962 case GLO:
180
1/2
✓ Branch 1 taken 962 times.
✗ Branch 2 not taken.
2886 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 962 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 962 times.
✗ Branch 2 not taken.
2886 33, 34, 35, 36 };
184 962 case QZSS:
185
1/2
✓ Branch 1 taken 962 times.
✗ Branch 2 not taken.
2886 return { 1, 2, 3, 4, 5 };
186 962 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 962 times.
✗ Branch 2 not taken.
2886 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 962 case IRNSS:
190
1/2
✓ Branch 1 taken 962 times.
✗ Branch 2 not taken.
2886 return { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
191 962 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 962 times.
✗ Branch 2 not taken.
2886 };
198 case SatSys_None:
199 break;
200 }
201 return {};
202 }
203
204 6734 std::vector<uint16_t> SatelliteSystem::getSatellites() const
205 {
206
1/2
✓ Branch 2 taken 6734 times.
✗ Branch 3 not taken.
6734 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 204 SatelliteSystem::Enum SatelliteSystem::ToEnumeration(SatelliteSystem satSys)
253 {
254
3/9
✗ Branch 1 not taken.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 34 times.
✗ Branch 9 not taken.
204 switch (SatelliteSystem_(satSys))
255 {
256 case SatSys_None:
257 return Enum_None;
258 130 case GPS:
259 130 return Enum_GPS;
260 40 case GAL:
261 40 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 34 case SBAS:
271 34 return Enum_SBAS;
272 }
273 return Enum_None;
274 }
275
276 204 SatelliteSystem::Enum SatelliteSystem::toEnumeration() const
277 {
278 204 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 297 std::vector<SatelliteSystem> SatelliteSystem::ToVector(SatelliteSystem satSys)
292 {
293 297 std::vector<SatelliteSystem> v;
294
3/4
✓ Branch 1 taken 297 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 2079 times.
✓ Branch 9 taken 297 times.
2376 for (const SatelliteSystem& sys : GetAll())
295 {
296
3/4
✓ Branch 1 taken 552 times.
✓ Branch 2 taken 1527 times.
✓ Branch 4 taken 552 times.
✗ Branch 5 not taken.
2079 if (sys.value & satSys.value) { v.push_back(sys); }
297 297 }
298 297 return v;
299 }
300
301 297 std::vector<SatelliteSystem> SatelliteSystem::toVector() const
302 {
303
1/2
✓ Branch 2 taken 297 times.
✗ Branch 3 not taken.
297 return ToVector(value);
304 }
305
306 12394007 std::vector<SatelliteSystem> SatelliteSystem::GetAll()
307 {
308
1/2
✓ Branch 1 taken 12393408 times.
✗ Branch 2 not taken.
37181422 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 104 void from_json(const json& j, SatelliteSystem& data)
316 {
317
2/4
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
104 data = SatelliteSystem::fromString(j.get<std::string>());
318 104 }
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