0.3.0
Loading...
Searching...
No Matches
SatelliteIdentifier.cpp
Go to the documentation of this file.
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
10
11#include <imgui.h>
12#include <unordered_set>
13#include <algorithm>
17#include <fmt/core.h>
18#include <fmt/ranges.h>
19
20namespace NAV
21{
22
23bool SatId::isGeo() const
24{
25 if (satSys == QZSS)
26 {
27 if (satNum == 3) { return true; }
28 }
29 else if (satSys == BDS)
30 {
31 if (satNum <= 5 || (satNum >= 59 && satNum <= 63)) { return true; }
32 }
33 else if (satSys == IRNSS)
34 {
35 if (std::unordered_set<uint16_t> sats = { 3, 6, 7 };
36 sats.contains(satNum)) { return true; }
37 }
38 return false;
39}
40
41bool 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
59void to_json(json& j, const SatId& data)
60{
61 j = json{
62 { "sys", data.satSys },
63 { "num", data.satNum },
64 };
65}
66void from_json(const json& j, SatId& data)
67{
68 j.at("sys").get_to(data.satSys);
69 j.at("num").get_to(data.satNum);
70}
71
72void to_json(json& j, const SatSigId& data)
73{
74 j = json{
75 { "code", data.code },
76 { "num", data.satNum },
77 };
78}
79void 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
85bool 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
155bool 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
176std::ostream& operator<<(std::ostream& os, const NAV::SatId& obj)
177{
178 return os << fmt::format("{}", obj);
179}
180
181std::ostream& operator<<(std::ostream& os, const NAV::SatSigId& obj)
182{
183 return os << fmt::format("{}", obj);
184}
BDS Ephemeris information.
nlohmann::json json
json namespace
QZSS Ephemeris information.
std::ostream & operator<<(std::ostream &os, const NAV::SatId &obj)
Stream insertion operator overload.
Structs identifying a unique satellite.
GNSS Satellite System.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
bool ShowSatelliteSelector(const char *label, std::vector< SatId > &satellites, SatelliteSystem filterSys, bool displayOnlyNumber)
Shows a ComboBox to select satellites.
bool lessCompareSatSigId(const std::string &lhs, const std::string &rhs)
Less than comparison from string representation.
SatelliteSystem_
Satellite System enumeration.
@ QZSS
Quasi-Zenith Satellite System.
@ BDS
Beidou.
@ IRNSS
Indian Regional Navigation Satellite System.
Identifies a satellite (satellite system and number)
bool isGeo() const
Checks if the satellite is geostationary.
SatelliteSystem satSys
Satellite system (GPS, GLONASS, GALILEO, QZSS, BDS, IRNSS, SBAS)
uint16_t satNum
Number of the satellite.
Identifies a satellite signal (satellite frequency and number)
uint16_t satNum
Number of the satellite.
Satellite System type.
static SatelliteSystem fromChar(char typeChar)
Construct new object from char.