INSTINCT Code Coverage Report


Directory: src/
File: Navigation/INS/Units.cpp
Date: 2025-06-02 15:19:59
Exec Total Coverage
Lines: 156 246 63.4%
Functions: 20 30 66.7%
Branches: 90 324 27.8%

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 "Units.hpp"
10
11 #include "util/Logger.hpp"
12
13 namespace NAV::Units
14 {
15
16 void to_json(json& j, const ImuAccelerometerUnits& data)
17 {
18 j = to_string(data);
19 }
20 6 void from_json(const json& j, ImuAccelerometerUnits& data)
21 {
22
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!j.is_string())
23 {
24 LOG_WARN("Could not parse '{}' into ImuAccelerometerUnits. Consider resaving the flow", j.dump());
25 6 return;
26 }
27
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 std::string str = j.get<std::string>();
28
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerUnits::COUNT); i++)
29 {
30 6 auto enumItem = static_cast<ImuAccelerometerUnits>(i);
31
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 if (str == to_string(enumItem))
32 {
33 6 data = enumItem;
34 6 return;
35 }
36 }
37 6 }
38
39 void to_json(json& j, const ImuGyroscopeUnits& data)
40 {
41 j = to_string(data);
42 }
43 6 void from_json(const json& j, ImuGyroscopeUnits& data)
44 {
45
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!j.is_string())
46 {
47 LOG_WARN("Could not parse '{}' into ImuGyroscopeUnits. Consider resaving the flow", j.dump());
48 6 return;
49 }
50
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 std::string str = j.get<std::string>();
51
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeUnits::COUNT); i++)
52 {
53 6 auto enumItem = static_cast<ImuGyroscopeUnits>(i);
54
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 if (str == to_string(enumItem))
55 {
56 6 data = enumItem;
57 6 return;
58 }
59 }
60 6 }
61
62 void to_json(json& j, const ImuAccelerometerNoiseUnits& data)
63 {
64 j = to_string(data);
65 }
66 12 void from_json(const json& j, ImuAccelerometerNoiseUnits& data)
67 {
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (!j.is_string())
69 {
70 LOG_WARN("Could not parse '{}' into ImuAccelerometerNoiseUnits. Consider resaving the flow", j.dump());
71 12 return;
72 }
73
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 std::string str = j.get<std::string>();
74
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerNoiseUnits::COUNT); i++)
75 {
76 12 auto enumItem = static_cast<ImuAccelerometerNoiseUnits>(i);
77
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
12 if (str == to_string(enumItem))
78 {
79 12 data = enumItem;
80 12 return;
81 }
82 }
83 12 }
84
85 void to_json(json& j, const ImuGyroscopeNoiseUnits& data)
86 {
87 j = to_string(data);
88 }
89 12 void from_json(const json& j, ImuGyroscopeNoiseUnits& data)
90 {
91
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (!j.is_string())
92 {
93 LOG_WARN("Could not parse '{}' into ImuGyroscopeNoiseUnits. Consider resaving the flow", j.dump());
94 12 return;
95 }
96
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 std::string str = j.get<std::string>();
97
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeNoiseUnits::COUNT); i++)
98 {
99 12 auto enumItem = static_cast<ImuGyroscopeNoiseUnits>(i);
100
2/4
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
12 if (str == to_string(enumItem))
101 {
102 12 data = enumItem;
103 12 return;
104 }
105 }
106 12 }
107
108 void to_json(json& j, const ImuAccelerometerIRWUnits& data)
109 {
110 j = to_string(data);
111 }
112 6 void from_json(const json& j, ImuAccelerometerIRWUnits& data)
113 {
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!j.is_string())
115 {
116 LOG_WARN("Could not parse '{}' into ImuAccelerometerIRWUnits. Consider resaving the flow", j.dump());
117 6 return;
118 }
119
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 std::string str = j.get<std::string>();
120
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerIRWUnits::COUNT); i++)
121 {
122 6 auto enumItem = static_cast<ImuAccelerometerIRWUnits>(i);
123
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 if (str == to_string(enumItem))
124 {
125 6 data = enumItem;
126 6 return;
127 }
128 }
129 6 }
130
131 void to_json(json& j, const ImuGyroscopeIRWUnits& data)
132 {
133 j = to_string(data);
134 }
135 6 void from_json(const json& j, ImuGyroscopeIRWUnits& data)
136 {
137
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!j.is_string())
138 {
139 LOG_WARN("Could not parse '{}' into ImuGyroscopeIRWUnits. Consider resaving the flow", j.dump());
140 6 return;
141 }
142
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 std::string str = j.get<std::string>();
143
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeIRWUnits::COUNT); i++)
144 {
145 6 auto enumItem = static_cast<ImuGyroscopeIRWUnits>(i);
146
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 if (str == to_string(enumItem))
147 {
148 6 data = enumItem;
149 6 return;
150 }
151 }
152 6 }
153
154 void to_json(json& j, const ImuAccelerometerFilterNoiseUnits& data)
155 {
156 j = to_string(data);
157 }
158 17 void from_json(const json& j, ImuAccelerometerFilterNoiseUnits& data)
159 {
160
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
17 if (!j.is_string())
161 {
162 LOG_WARN("Could not parse '{}' into ImuAccelerometerFilterNoiseUnits. Consider resaving the flow", j.dump());
163 17 return;
164 }
165
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 std::string str = j.get<std::string>();
166
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerFilterNoiseUnits::COUNT); i++)
167 {
168 34 auto enumItem = static_cast<ImuAccelerometerFilterNoiseUnits>(i);
169
3/4
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 17 times.
34 if (str == to_string(enumItem))
170 {
171 17 data = enumItem;
172 17 return;
173 }
174 }
175 17 }
176
177 void to_json(json& j, const ImuGyroscopeFilterNoiseUnits& data)
178 {
179 j = to_string(data);
180 }
181 17 void from_json(const json& j, ImuGyroscopeFilterNoiseUnits& data)
182 {
183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
17 if (!j.is_string())
184 {
185 LOG_WARN("Could not parse '{}' into ImuGyroscopeFilterNoiseUnits. Consider resaving the flow", j.dump());
186 17 return;
187 }
188
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 std::string str = j.get<std::string>();
189
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeFilterNoiseUnits::COUNT); i++)
190 {
191 68 auto enumItem = static_cast<ImuGyroscopeFilterNoiseUnits>(i);
192
3/4
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 51 times.
68 if (str == to_string(enumItem))
193 {
194 17 data = enumItem;
195 17 return;
196 }
197 }
198 17 }
199
200 void to_json(json& j, const ImuAccelerometerFilterBiasUnits& data)
201 {
202 j = to_string(data);
203 }
204 17 void from_json(const json& j, ImuAccelerometerFilterBiasUnits& data)
205 {
206
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
17 if (!j.is_string())
207 {
208 LOG_WARN("Could not parse '{}' into ImuAccelerometerFilterBiasUnits. Consider resaving the flow", j.dump());
209 17 return;
210 }
211
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 std::string str = j.get<std::string>();
212
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerFilterBiasUnits::COUNT); i++)
213 {
214 34 auto enumItem = static_cast<ImuAccelerometerFilterBiasUnits>(i);
215
3/4
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 17 times.
34 if (str == to_string(enumItem))
216 {
217 17 data = enumItem;
218 17 return;
219 }
220 }
221 17 }
222
223 void to_json(json& j, const ImuGyroscopeFilterBiasUnits& data)
224 {
225 j = to_string(data);
226 }
227 17 void from_json(const json& j, ImuGyroscopeFilterBiasUnits& data)
228 {
229
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
17 if (!j.is_string())
230 {
231 LOG_WARN("Could not parse '{}' into ImuGyroscopeFilterBiasUnits. Consider resaving the flow", j.dump());
232 17 return;
233 }
234
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 std::string str = j.get<std::string>();
235
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeFilterBiasUnits::COUNT); i++)
236 {
237 68 auto enumItem = static_cast<ImuGyroscopeFilterBiasUnits>(i);
238
3/4
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 51 times.
68 if (str == to_string(enumItem))
239 {
240 17 data = enumItem;
241 17 return;
242 }
243 }
244 17 }
245
246 } // namespace NAV::Units
247
248 6 std::string NAV::to_string(Units::ImuAccelerometerUnits unit)
249 {
250
1/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 switch (unit)
251 {
252 6 case Units::ImuAccelerometerUnits::m_s2:
253
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 return "m/s^2";
254 case Units::ImuAccelerometerUnits::g:
255 return "g";
256 case Units::ImuAccelerometerUnits::COUNT:
257 break;
258 }
259 return "";
260 }
261
262 6 std::string NAV::to_string(Units::ImuGyroscopeUnits unit)
263 {
264
1/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 switch (unit)
265 {
266 6 case Units::ImuGyroscopeUnits::rad_s:
267
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 return "rad/s";
268 case Units::ImuGyroscopeUnits::deg_s:
269 return "deg/s";
270 case Units::ImuGyroscopeUnits::COUNT:
271 break;
272 }
273 return "";
274 }
275
276 12 std::string NAV::to_string(Units::ImuAccelerometerNoiseUnits unit)
277 {
278
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 switch (unit)
279 {
280 12 case Units::ImuAccelerometerNoiseUnits::m_s2_sqrts:
281
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
24 return "m/s^2/√(s)";
282 case Units::ImuAccelerometerNoiseUnits::m_s2_sqrth:
283 return "m/s^2/√(h)";
284 case Units::ImuAccelerometerNoiseUnits::COUNT:
285 break;
286 }
287 return "";
288 }
289
290 12 std::string NAV::to_string(Units::ImuGyroscopeNoiseUnits unit)
291 {
292
1/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 switch (unit)
293 {
294 12 case Units::ImuGyroscopeNoiseUnits::rad_s_sqrts:
295
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
24 return "rad/s/√(s)";
296 case Units::ImuGyroscopeNoiseUnits::rad_s_sqrth:
297 return "rad/s/√(h)";
298 case Units::ImuGyroscopeNoiseUnits::deg_s_sqrts:
299 return "deg/s/√(s)";
300 case Units::ImuGyroscopeNoiseUnits::deg_s_sqrth:
301 return "deg/s/√(h)";
302 case Units::ImuGyroscopeNoiseUnits::COUNT:
303 break;
304 }
305 return "";
306 }
307
308 6 std::string NAV::to_string(Units::ImuAccelerometerIRWUnits unit)
309 {
310
1/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 switch (unit)
311 {
312 6 case Units::ImuAccelerometerIRWUnits::m_s3_sqrts:
313
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 return "m/s^3/√(s)";
314 case Units::ImuAccelerometerIRWUnits::m_s3_sqrth:
315 return "m/s^3/√(h)";
316 case Units::ImuAccelerometerIRWUnits::COUNT:
317 break;
318 }
319 return "";
320 }
321
322 6 std::string NAV::to_string(Units::ImuGyroscopeIRWUnits unit)
323 {
324
1/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6 switch (unit)
325 {
326 6 case Units::ImuGyroscopeIRWUnits::rad_s2_sqrts:
327
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 return "rad/s^2/√(s)";
328 case Units::ImuGyroscopeIRWUnits::rad_s2_sqrth:
329 return "rad/s^2/√(h)";
330 case Units::ImuGyroscopeIRWUnits::deg_s2_sqrts:
331 return "deg/s^2/√(s)";
332 case Units::ImuGyroscopeIRWUnits::deg_s2_sqrth:
333 return "deg/s^2/√(h)";
334 case Units::ImuGyroscopeIRWUnits::COUNT:
335 break;
336 }
337 return "";
338 }
339
340 34 std::string NAV::to_string(Units::ImuAccelerometerFilterNoiseUnits unit)
341 {
342
2/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
34 switch (unit)
343 {
344 17 case Units::ImuAccelerometerFilterNoiseUnits::m_s2_sqrtHz:
345
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "m/s^2/√(Hz)";
346 17 case Units::ImuAccelerometerFilterNoiseUnits::mg_sqrtHz:
347
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "mg/√(Hz)";
348 case Units::ImuAccelerometerFilterNoiseUnits::COUNT:
349 break;
350 }
351 return "";
352 }
353
354 68 std::string NAV::to_string(Units::ImuGyroscopeFilterNoiseUnits unit)
355 {
356
4/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
68 switch (unit)
357 {
358 17 case Units::ImuGyroscopeFilterNoiseUnits::rad_s_sqrtHz:
359
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "rad/s/√(Hz)";
360 17 case Units::ImuGyroscopeFilterNoiseUnits::rad_hr_sqrtHz:
361
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "rad/hr/√(Hz)";
362 17 case Units::ImuGyroscopeFilterNoiseUnits::deg_s_sqrtHz:
363
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "deg/s/√(Hz)";
364 17 case Units::ImuGyroscopeFilterNoiseUnits::deg_hr_sqrtHz:
365
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "deg/hr/√(Hz)";
366 case Units::ImuGyroscopeFilterNoiseUnits::COUNT:
367 break;
368 }
369 return "";
370 }
371
372 34 std::string NAV::to_string(Units::ImuAccelerometerFilterBiasUnits unit)
373 {
374
2/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
34 switch (unit)
375 {
376 17 case Units::ImuAccelerometerFilterBiasUnits::m_s2:
377
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "m/s^2";
378 17 case Units::ImuAccelerometerFilterBiasUnits::microg:
379
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "µg";
380 case Units::ImuAccelerometerFilterBiasUnits::COUNT:
381 break;
382 }
383 return "";
384 }
385
386 68 std::string NAV::to_string(Units::ImuGyroscopeFilterBiasUnits unit)
387 {
388
4/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
68 switch (unit)
389 {
390 17 case Units::ImuGyroscopeFilterBiasUnits::rad_s:
391
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "1/s";
392 17 case Units::ImuGyroscopeFilterBiasUnits::rad_h:
393
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "1/h";
394 17 case Units::ImuGyroscopeFilterBiasUnits::deg_s:
395
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "°/s";
396 17 case Units::ImuGyroscopeFilterBiasUnits::deg_h:
397
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 return "°/h";
398 case Units::ImuGyroscopeFilterBiasUnits::COUNT:
399 break;
400 }
401 return "";
402 }
403