INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Core/SatelliteIdentifier.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 13 90 14.4%
Functions: 2 10 20.0%
Branches: 19 162 11.7%

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 "SatelliteIdentifier.hpp"
10
11 #include <imgui.h>
12 #include <unordered_set>
13 #include <algorithm>
14 #include "Navigation/GNSS/Core/SatelliteSystem.hpp"
15 #include "Navigation/GNSS/Satellite/Ephemeris/BDSEphemeris.hpp"
16 #include "Navigation/GNSS/Satellite/Ephemeris/QZSSEphemeris.hpp"
17 #include <fmt/core.h>
18 #include <fmt/ranges.h>
19
20 namespace NAV
21 {
22
23 29425 bool SatId::isGeo() const
24 {
25
2/2
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 28785 times.
29425 if (satSys == QZSS)
26 {
27
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 512 times.
640 if (satNum == 3) { return true; }
28 }
29
2/2
✓ Branch 1 taken 14321 times.
✓ Branch 2 taken 14464 times.
28785 else if (satSys == BDS)
30 {
31
5/6
✓ Branch 0 taken 13631 times.
✓ Branch 1 taken 690 times.
✓ Branch 2 taken 512 times.
✓ Branch 3 taken 13119 times.
✓ Branch 4 taken 512 times.
✗ Branch 5 not taken.
14321 if (satNum <= 5 || (satNum >= 59 && satNum <= 63)) { return true; }
32 }
33
2/2
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 13312 times.
14464 else if (satSys == IRNSS)
34 {
35
1/2
✓ Branch 1 taken 1152 times.
✗ Branch 2 not taken.
2304 if (std::unordered_set<uint16_t> sats = { 3, 6, 7 };
36
5/6
✓ Branch 1 taken 1152 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 384 times.
✓ Branch 4 taken 768 times.
✓ Branch 6 taken 768 times.
✓ Branch 7 taken 384 times.
1152 sats.contains(satNum)) { return true; }
37 }
38 27711 return false;
39 }
40
41 bool lessCompareSatSigId(const std::string& lhs, const std::string& rhs)
42 {
43 auto lhsSatSys = SatelliteSystem::fromChar(lhs.substr(0, 1).at(0));
44 auto rhsSatSys = SatelliteSystem::fromChar(rhs.substr(0, 1).at(0));
45 if (lhsSatSys == rhsSatSys)
46 {
47 auto lhsSatNum = std::stoi(lhs.substr(lhs.size() - 2, 2));
48 auto rhsSatNum = std::stoi(rhs.substr(rhs.size() - 2, 2));
49 if (lhsSatNum == rhsSatNum)
50 {
51 // Code, e.g. G1C-02
52 return lhs.substr(1, 2) < rhs.substr(1, 2);
53 }
54 return lhsSatNum < rhsSatNum;
55 }
56 return lhsSatSys < rhsSatSys;
57 }
58
59 void to_json(json& j, const SatId& data)
60 {
61 j = json{
62 { "sys", data.satSys },
63 { "num", data.satNum },
64 };
65 }
66 91 void from_json(const json& j, SatId& data)
67 {
68 91 j.at("sys").get_to(data.satSys);
69 91 j.at("num").get_to(data.satNum);
70 91 }
71
72 void to_json(json& j, const SatSigId& data)
73 {
74 j = json{
75 { "code", data.code },
76 { "num", data.satNum },
77 };
78 }
79 void from_json(const json& j, SatSigId& data)
80 {
81 j.at("code").get_to(data.code);
82 j.at("num").get_to(data.satNum);
83 }
84
85 bool ShowSatelliteSelector(const char* label, std::vector<SatId>& satellites, SatelliteSystem filterSys, bool displayOnlyNumber)
86 {
87 bool valueChanged = false;
88 std::string preview;
89 if (displayOnlyNumber)
90 {
91 for (size_t i = 0; i < satellites.size(); i++)
92 {
93 if (i != 0) { preview += " | "; }
94 preview += std::to_string(satellites.at(i).satNum);
95 }
96 }
97 else { preview = fmt::format("{}", fmt::join(satellites, ", ")); }
98
99 if (ImGui::BeginCombo(label, preview.c_str()))
100 {
101 if (ImGui::BeginTable(fmt::format("{} Table", label).c_str(), 7, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY))
102 {
103 ImGui::TableSetupScrollFreeze(0, 1);
104 for (uint64_t satSys = 0xFF; satSys < 0xFFUL << (7 * 8); satSys = satSys << 8UL)
105 {
106 ImGui::TableSetupColumn(std::string(SatelliteSystem(SatelliteSystem_(satSys))).c_str());
107 }
108 ImGui::TableHeadersRow();
109
110 ImGui::TableNextRow();
111 for (uint64_t satSys = 0xFF; satSys < 0xFFUL << (7 * 8); satSys = satSys << 8UL)
112 {
113 auto satSystem = SatelliteSystem(SatelliteSystem_(satSys));
114
115 ImGui::TableNextColumn();
116 for (const auto& num : satSystem.getSatellites())
117 {
118 SatId satId{ satSystem, num };
119 auto iter = std::ranges::find(satellites, satId);
120 bool isExcluded = iter != satellites.end();
121 if (!SatelliteSystem_(satSystem & filterSys) || satId.isGeo()) { ImGui::BeginDisabled(); }
122
123 auto satInfo = satSystem.getSatelliteInfo(num);
124
125 if (ImGui::Checkbox(fmt::format("{}{}##{} {}",
126 num,
127 satInfo ? fmt::format(" ({})", *satInfo) : "",
128 satSys,
129 label)
130 .c_str(),
131 &isExcluded))
132 {
133 if (isExcluded)
134 {
135 satellites.push_back(satId);
136 std::sort(satellites.begin(), satellites.end()); // NOLINT(boost-use-ranges,modernize-use-ranges) // ranges::sort is not supported yet
137 }
138 else
139 {
140 satellites.erase(iter);
141 }
142 valueChanged = true;
143 }
144 if (!SatelliteSystem_(satSystem & filterSys) || satId.isGeo()) { ImGui::EndDisabled(); }
145 }
146 }
147
148 ImGui::EndTable();
149 }
150 ImGui::EndCombo();
151 }
152 return valueChanged;
153 }
154
155 bool ShowSatelliteSelector(const char* label, SatId& satellite, SatelliteSystem filterSys, bool displayOnlyNumber)
156 {
157 std::vector<SatId> vec = { satellite };
158
159 if (ShowSatelliteSelector(label, vec, filterSys, displayOnlyNumber))
160 {
161 for (const auto& s : vec)
162 {
163 if (s != satellite)
164 {
165 satellite = s;
166 return true;
167 }
168 }
169 return false;
170 }
171 return false;
172 }
173
174 } // namespace NAV
175
176 std::ostream& operator<<(std::ostream& os, const NAV::SatId& obj)
177 {
178 return os << fmt::format("{}", obj);
179 }
180
181 std::ostream& operator<<(std::ostream& os, const NAV::SatSigId& obj)
182 {
183 return os << fmt::format("{}", obj);
184 }
185