0.4.1
Loading...
Searching...
No Matches
Observation.cpp
Go to the documentation of this file.
1#include "Observation.hpp"
2#include <array>
3#include <cstddef>
4#include <unordered_set>
5
7
8namespace NAV
9{
10
11size_t Observations::countObservations(const SatSigId& satSigId, const GnssObs::ObservationType& obsType) const
12{
13 if (!signals.contains(satSigId)) { return 0; }
14
15 const auto& recvObs = signals.at(satSigId).recvObs;
16 return static_cast<size_t>(std::ranges::count_if(recvObs, [&obsType](const auto& obs) {
17 return obs.second->obs.contains(obsType);
18 }));
19}
20
21void Observations::recalcObservableCounts([[maybe_unused]] const std::string& nameId)
22{
23 std::array<std::unordered_set<SatId>, GnssObs::ObservationType_COUNT> nMeasUniqueSat;
24 systems.clear();
25 satellites.clear();
26 nObservables.fill(0);
28
29 for (const auto& [satSigId, sigObs] : signals)
30 {
31 auto satId = satSigId.toSatId();
32 satellites.insert(satId);
33 systems.insert(satId.satSys);
34
35 const auto& recvObs = sigObs.recvObs.begin();
36 for (const auto& obs : recvObs->second->obs)
37 {
38 auto obsType = static_cast<size_t>(obs.first);
39 nObservables.at(obsType)++;
40 nMeasUniqueSat.at(obsType).insert(satId);
41 }
42 }
43
44 for (size_t obsType = 0; obsType < GnssObs::ObservationType_COUNT; obsType++)
45 {
46 nObservablesUniqueSatellite.at(obsType) = nMeasUniqueSat.at(obsType).size();
47 }
48
49#if LOG_LEVEL <= LOG_LEVEL_DATA
50 LOG_DATA("{}: systems: [{}]", nameId, fmt::join(systems, ", "));
51 LOG_DATA("{}: satellites: [{}]", nameId, fmt::join(satellites, ", "));
52 std::string observables;
53 std::string observablesUnique;
54 for (size_t obsType = 0; obsType < GnssObs::ObservationType_COUNT; obsType++)
55 {
56 observables += fmt::format("{} {}", nObservables.at(obsType), static_cast<GnssObs::ObservationType>(obsType));
57 observablesUnique += fmt::format("{} {} [{}]", nObservablesUniqueSatellite.at(obsType),
58 static_cast<GnssObs::ObservationType>(obsType), fmt::join(nMeasUniqueSat.at(obsType), ", "));
59 if (obsType < GnssObs::ObservationType_COUNT - 1)
60 {
61 observables += ", ";
62 observablesUnique += ", ";
63 }
64 }
65 LOG_DATA("{}: nObservables: {}", nameId, observables);
66 LOG_DATA("{}: nObservablesUniqueSatellite: {}", nameId, observablesUnique);
67#endif
68}
69
70bool Observations::removeSignal(const SatSigId& satSigId, [[maybe_unused]] const std::string& nameId)
71{
72 bool somethingRemoved = false;
73 if (signals.contains(satSigId))
74 {
75 LOG_DATA("{}: Erasing signal [{}]", nameId, satSigId);
76 signals.erase(satSigId);
77 somethingRemoved = true;
78 }
79 if (somethingRemoved) { recalcObservableCounts(nameId); }
80 return somethingRemoved;
81}
82
83bool Observations::removeSignal(const SatSigId& satSigId, const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
84{
85 bool somethingRemoved = false;
86 if (signals.contains(satSigId))
87 {
88 LOG_DATA("{}: Erasing signal [{}][{}]", nameId, satSigId, obsType);
89 size_t emptyReceiver = 0;
90 for (auto& recvObs : signals.at(satSigId).recvObs)
91 {
92 if (recvObs.second->obs.contains(obsType))
93 {
94 recvObs.second->obs.erase(obsType);
95 }
96 if (recvObs.second->obs.empty()) { emptyReceiver++; }
97 }
98 if (emptyReceiver == signals.at(satSigId).recvObs.size())
99 {
100 signals.erase(satSigId);
101 }
102 somethingRemoved = true;
103 }
104 if (somethingRemoved) { recalcObservableCounts(nameId); }
105 return somethingRemoved;
106}
107
108bool Observations::removeSatellite(const SatId& satId, [[maybe_unused]] const std::string& nameId)
109{
110 std::vector<SatSigId> toRemove;
111 for (const auto& signal : signals)
112 {
113 if (signal.first.toSatId() == satId)
114 {
115 toRemove.push_back(signal.first);
116 }
117 }
118 for (const auto& satSigId : toRemove)
119 {
120 LOG_DATA("{}: Erasing signal [{}]", nameId, satSigId);
121 signals.erase(satSigId);
122 }
123 if (!toRemove.empty()) { recalcObservableCounts(nameId); }
124 return !toRemove.empty();
125}
126
127bool Observations::removeMeasurementsFor(const Code& code, const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
128{
129 LOG_DATA("{}: Searching observations to remove on [{}][{}]", nameId, code, obsType);
130 bool somethingRemoved = false;
131 for (auto& [satSigId, sigObs] : signals)
132 {
133 if (satSigId.code != code) { continue; }
134
135 for (size_t i = 0; i < sigObs.recvObs.size(); i++)
136 {
137 if (!sigObs.recvObs.contains(i)) { continue; }
138 auto& recvObs = sigObs.recvObs.at(i);
139 if (recvObs->obs.contains(obsType))
140 {
141 recvObs->obs.erase(obsType);
142 LOG_DATA("{}: Erasing observation [{}][{}] of receiver '{}'", nameId, satSigId, obsType, i);
143 somethingRemoved = true;
144 }
145 }
146 }
147 if (somethingRemoved) { recalcObservableCounts(nameId); }
148 return somethingRemoved;
149}
150
151bool Observations::removeObsType(const GnssObs::ObservationType& obsType, [[maybe_unused]] const std::string& nameId)
152{
153 LOG_DATA("{}: Searching observations to remove on [{}]", nameId, obsType);
154 bool somethingRemoved = false;
155 for (auto& [satSigId, sigObs] : signals)
156 {
157 for (size_t i = 0; i < sigObs.recvObs.size(); i++)
158 {
159 if (!sigObs.recvObs.contains(i)) { continue; }
160 auto& recvObs = sigObs.recvObs.at(i);
161 if (recvObs->obs.contains(obsType))
162 {
163 recvObs->obs.erase(obsType);
164 LOG_DATA("{}: Erasing observation [{}][{}] of receiver '{}'", nameId, satSigId, obsType, i);
165 somethingRemoved = true;
166 }
167 }
168 }
169 if (somethingRemoved) { recalcObservableCounts(nameId); }
170 return somethingRemoved;
171}
172
173} // namespace NAV
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Observation data used for calculations.
Structs identifying a unique satellite.
Enumerate for GNSS Codes.
Definition Code.hpp:89
ObservationType
Observation types.
Definition GnssObs.hpp:37
@ ObservationType_COUNT
Count.
Definition GnssObs.hpp:41
size_t countObservations(const SatSigId &satSigId, const GnssObs::ObservationType &obsType) const
Counts how many observations for the specified signal ant type exist.
bool removeSignal(const SatSigId &satSigId, const std::string &nameId)
Remove the signal from the observations.
std::set< SatelliteSystem > systems
Satellite systems used.
bool removeMeasurementsFor(const Code &code, const GnssObs::ObservationType &obsType, const std::string &nameId)
Remove all measurements for the provided code and observation type.
std::array< size_t, GnssObs::ObservationType_COUNT > nObservables
Number of observables.
void recalcObservableCounts(const std::string &nameId)
Calculates/Recalculates the number of observables.
bool removeSatellite(const SatId &satId, const std::string &nameId)
Remove all signals of the satellite.
std::unordered_set< SatId > satellites
Satellites used.
std::array< size_t, GnssObs::ObservationType_COUNT > nObservablesUniqueSatellite
Number of observables (counted once for each satellite)
unordered_map< SatSigId, SignalObservation > signals
Observations and calculated data for each signal.
bool removeObsType(const GnssObs::ObservationType &obsType, const std::string &nameId)
Remove all measurements for the provided observation type.
Identifies a satellite (satellite system and number)
Identifies a satellite signal (satellite frequency and number)