INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Core/SatelliteSystem.cpp
Date: 2025-06-02 15:19:59
Exec Total Coverage
Lines: 112 203 55.2%
Functions: 13 21 61.9%
Branches: 123 278 44.2%

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 178 SatelliteSystem SatelliteSystem::fromString(const std::string& typeString)
22 {
23
5/6
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 138 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 138 times.
178 if (typeString == "GPS" || typeString == "GP")
24 {
25 40 return GPS;
26 }
27
4/8
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 138 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 138 times.
138 if (typeString == "GLONASS" || typeString == "GLO" || typeString == "GL")
28 {
29 return GLO;
30 }
31
6/8
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 128 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 128 times.
138 if (typeString == "GALILEO" || typeString == "GAL" || typeString == "GA")
32 {
33 10 return GAL;
34 }
35
6/8
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 122 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 122 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 122 times.
128 if (typeString == "QZSS" || typeString == "QZS" || typeString == "QZ")
36 {
37 6 return QZSS;
38 }
39
5/6
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 104 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✓ Branch 6 taken 104 times.
✓ Branch 7 taken 18 times.
122 if (typeString == "BDS" || typeString == "BD")
40 {
41 104 return BDS;
42 }
43
2/8
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 18 times.
✗ Branch 10 not taken.
18 if (typeString == "IRNSS" || typeString == "IRN" || typeString == "IR")
44 {
45 18 return IRNSS;
46 }
47 if (typeString == "SBAS" || typeString == "SB")
48 {
49 return SBAS;
50 }
51
52 return SatSys_None;
53 }
54
55 266818 SatelliteSystem SatelliteSystem::fromChar(char typeChar)
56 {
57
8/8
✓ Branch 0 taken 82419 times.
✓ Branch 1 taken 61328 times.
✓ Branch 2 taken 68940 times.
✓ Branch 3 taken 2690 times.
✓ Branch 4 taken 46938 times.
✓ Branch 5 taken 1190 times.
✓ Branch 6 taken 3272 times.
✓ Branch 7 taken 41 times.
266818 switch (typeChar)
58 {
59 82419 case 'G':
60 82419 return GPS;
61 61328 case 'R':
62 61328 return GLO;
63 68940 case 'E':
64 68940 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 3272 case 'S':
74 3272 return SBAS;
75 41 default:
76 41 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 42847 TimeSystem SatelliteSystem::GetTimeSystemForSatelliteSystem(SatelliteSystem satSys)
145 {
146
7/9
✓ Branch 1 taken 18861 times.
✓ Branch 2 taken 4158 times.
✓ Branch 3 taken 3502 times.
✓ Branch 4 taken 2220 times.
✓ Branch 5 taken 14084 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
42847 switch (SatelliteSystem_(satSys))
147 {
148 18861 case GPS:
149 18861 return GPST;
150 4158 case GLO:
151 4158 return GLNT;
152 3502 case GAL:
153 3502 return GST;
154 2220 case QZSS:
155 2220 return QZSST;
156 14084 case BDS:
157 14084 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 42847 TimeSystem SatelliteSystem::getTimeSystem() const
169 {
170 42847 return GetTimeSystemForSatelliteSystem(value);
171 }
172
173 882 std::vector<uint16_t> SatelliteSystem::GetSatellitesForSatelliteSystem(SatelliteSystem satSys)
174 {
175
7/9
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 126 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 126 times.
✓ Branch 5 taken 126 times.
✓ Branch 6 taken 126 times.
✓ Branch 7 taken 126 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
882 switch (SatelliteSystem_(satSys))
176 {
177 126 case GPS:
178
1/2
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
378 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 126 case GLO:
180
1/2
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
378 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 126 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 126 times.
✗ Branch 2 not taken.
378 33, 34, 35, 36 };
184 126 case QZSS:
185
1/2
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
378 return { 1, 2, 3, 4, 5 };
186 126 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 126 times.
✗ Branch 2 not taken.
378 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 126 case IRNSS:
190
1/2
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
378 return { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
191 126 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 126 times.
✗ Branch 2 not taken.
378 };
198 case SatSys_None:
199 break;
200 }
201 return {};
202 }
203
204 882 std::vector<uint16_t> SatelliteSystem::getSatellites() const
205 {
206
1/2
✓ Branch 2 taken 882 times.
✗ Branch 3 not taken.
882 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 161 std::vector<SatelliteSystem> SatelliteSystem::ToVector(SatelliteSystem satSys)
292 {
293 161 std::vector<SatelliteSystem> v;
294
3/4
✓ Branch 1 taken 161 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 1127 times.
✓ Branch 9 taken 161 times.
1288 for (const SatelliteSystem& sys : GetAll())
295 {
296
3/4
✓ Branch 1 taken 280 times.
✓ Branch 2 taken 847 times.
✓ Branch 4 taken 280 times.
✗ Branch 5 not taken.
1127 if (sys.value & satSys.value) { v.push_back(sys); }
297 161 }
298 161 return v;
299 }
300
301 161 std::vector<SatelliteSystem> SatelliteSystem::toVector() const
302 {
303
1/2
✓ Branch 2 taken 161 times.
✗ Branch 3 not taken.
161 return ToVector(value);
304 }
305
306 3991646 std::vector<SatelliteSystem> SatelliteSystem::GetAll()
307 {
308
1/2
✓ Branch 1 taken 3990875 times.
✗ Branch 2 not taken.
11974167 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 78 void from_json(const json& j, SatelliteSystem& data)
316 {
317
2/4
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 78 times.
✗ Branch 5 not taken.
78 data = SatelliteSystem::fromString(j.get<std::string>());
318 78 }
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