| 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 | 179545 | bool SatId::isGeo() const | |
| 24 | { | ||
| 25 |
2/2✓ Branch 1 taken 4810 times.
✓ Branch 2 taken 174735 times.
|
179545 | if (satSys == QZSS) |
| 26 | { | ||
| 27 |
2/2✓ Branch 0 taken 962 times.
✓ Branch 1 taken 3848 times.
|
4810 | if (satNum == 3) { return true; } |
| 28 | } | ||
| 29 |
2/2✓ Branch 1 taken 66029 times.
✓ Branch 2 taken 108706 times.
|
174735 | else if (satSys == BDS) |
| 30 | { | ||
| 31 |
5/6✓ Branch 0 taken 61169 times.
✓ Branch 1 taken 4860 times.
✓ Branch 2 taken 3848 times.
✓ Branch 3 taken 57321 times.
✓ Branch 4 taken 3848 times.
✗ Branch 5 not taken.
|
66029 | if (satNum <= 5 || (satNum >= 59 && satNum <= 63)) { return true; } |
| 32 | } | ||
| 33 |
2/2✓ Branch 1 taken 8658 times.
✓ Branch 2 taken 100048 times.
|
108706 | else if (satSys == IRNSS) |
| 34 | { | ||
| 35 |
1/2✓ Branch 1 taken 8658 times.
✗ Branch 2 not taken.
|
17316 | if (std::unordered_set<uint16_t> sats = { 3, 6, 7 }; |
| 36 |
5/6✓ Branch 1 taken 8658 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2886 times.
✓ Branch 4 taken 5772 times.
✓ Branch 6 taken 5772 times.
✓ Branch 7 taken 2886 times.
|
8658 | sats.contains(satNum)) { return true; } |
| 37 | } | ||
| 38 | 166989 | 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 | 104 | void from_json(const json& j, SatId& data) | |
| 67 | { | ||
| 68 | 104 | j.at("sys").get_to(data.satSys); | |
| 69 | 104 | j.at("num").get_to(data.satNum); | |
| 70 | 104 | } | |
| 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 < static_cast<uint64_t>(0xFF) << (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 < static_cast<uint64_t>(0xFF) << (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 |