INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataLogger/WiFi/WiFiObsLogger.cpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 13 71 18.3%
Functions: 4 12 33.3%
Branches: 10 100 10.0%

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 "WiFiObsLogger.hpp"
10
11 #include "NodeData/WiFi/WiFiObs.hpp"
12
13 #include "Navigation/Transformations/Units.hpp"
14
15 #include "util/Logger.hpp"
16
17 #include <iomanip> // std::setprecision
18
19 #include "internal/FlowManager.hpp"
20
21 114 NAV::WiFiObsLogger::WiFiObsLogger()
22
4/8
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 114 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 114 times.
✗ Branch 12 not taken.
114 : Node(typeStatic())
23 {
24 LOG_TRACE("{}: called", name);
25
26 114 _fileType = FileType::ASCII;
27
28 114 _hasConfig = true;
29 114 _guiConfigDefaultWindowSize = { 380, 70 };
30
31
4/8
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 114 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 114 times.
✓ Branch 9 taken 114 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
342 CreateInputPin("writeObservation", Pin::Type::Flow, { WiFiObs::type() }, &WiFiObsLogger::writeObservation);
32 228 }
33
34 228 NAV::WiFiObsLogger::~WiFiObsLogger()
35 {
36 LOG_TRACE("{}: called", nameId());
37 228 }
38
39 228 std::string NAV::WiFiObsLogger::typeStatic()
40 {
41
1/2
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
456 return "WiFiObsLogger";
42 }
43
44 std::string NAV::WiFiObsLogger::type() const
45 {
46 return typeStatic();
47 }
48
49 114 std::string NAV::WiFiObsLogger::category()
50 {
51
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
228 return "Data Logger";
52 }
53
54 void NAV::WiFiObsLogger::guiConfig()
55 {
56 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
57 {
58 flow::ApplyChanges();
59 doDeinitialize();
60 }
61
62 if (CommonLog::ShowOriginInput(nameId().c_str()))
63 {
64 flow::ApplyChanges();
65 }
66 }
67
68 [[nodiscard]] json NAV::WiFiObsLogger::save() const
69 {
70 LOG_TRACE("{}: called", nameId());
71
72 json j;
73
74 j["FileWriter"] = FileWriter::save();
75
76 return j;
77 }
78
79 void NAV::WiFiObsLogger::restore(json const& j)
80 {
81 LOG_TRACE("{}: called", nameId());
82
83 if (j.contains("FileWriter"))
84 {
85 FileWriter::restore(j.at("FileWriter"));
86 }
87 }
88
89 void NAV::WiFiObsLogger::flush()
90 {
91 _filestream.flush();
92 }
93
94 bool NAV::WiFiObsLogger::initialize()
95 {
96 LOG_TRACE("{}: called", nameId());
97
98 if (!FileWriter::initialize())
99 {
100 return false;
101 }
102
103 CommonLog::initialize();
104
105 _filestream << "Time [s],GpsCycle,GpsWeek,GpsToW [s],"
106 << "MacAddress,"
107 << "Distance [m],"
108 << "DistanceStd [m]\n";
109
110 return true;
111 }
112
113 void NAV::WiFiObsLogger::deinitialize()
114 {
115 LOG_TRACE("{}: called", nameId());
116
117 FileWriter::deinitialize();
118 }
119
120 void NAV::WiFiObsLogger::writeObservation(NAV::InputPin::NodeDataQueue& queue, size_t pinIdx)
121 {
122 if ([[maybe_unused]] auto* sourcePin = inputPins[pinIdx].link.getConnectedPin())
123 {
124 constexpr int gpsCyclePrecision = 3;
125 constexpr int gpsTimePrecision = 12;
126 constexpr int valuePrecision = 15;
127
128 auto nodeData = queue.extract_front();
129
130 // -------------------------------------------------------- Time -----------------------------------------------------------
131
132 auto obs = std::static_pointer_cast<const WiFiObs>(nodeData);
133 if (!obs->insTime.empty())
134 {
135 _filestream << std::setprecision(valuePrecision) << std::round(calcTimeIntoRun(obs->insTime) * 1e9) / 1e9;
136 }
137 _filestream << ",";
138 if (!obs->insTime.empty())
139 {
140 _filestream << std::fixed << std::setprecision(gpsCyclePrecision) << obs->insTime.toGPSweekTow().gpsCycle;
141 }
142 _filestream << ",";
143 if (!obs->insTime.empty())
144 {
145 _filestream << std::defaultfloat << std::setprecision(gpsTimePrecision) << obs->insTime.toGPSweekTow().gpsWeek;
146 }
147 _filestream << ",";
148 if (!obs->insTime.empty())
149 {
150 _filestream << std::defaultfloat << std::setprecision(gpsTimePrecision) << obs->insTime.toGPSweekTow().tow;
151 }
152 _filestream << "," << std::setprecision(valuePrecision);
153
154 // ------------------------------------------------------ MacAddress ----------------------------------------------------------
155 if (!obs->macAddress.empty())
156 {
157 _filestream << obs->macAddress;
158 }
159 _filestream << ",";
160
161 // ------------------------------------------------------- Distance -----------------------------------------------------------
162 _filestream << obs->distance;
163 _filestream << ",";
164 // --------------------------------------------------------- Standard deviation ---------------------------------------------------
165 _filestream << obs->distanceStd;
166
167 _filestream << '\n';
168 }
169 }
170