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 "WiFiObsFile.hpp" | ||
10 | |||
11 | #include "util/Logger.hpp" | ||
12 | |||
13 | #include "util/Time/TimeBase.hpp" | ||
14 | |||
15 | #include "internal/NodeManager.hpp" | ||
16 | namespace nm = NAV::NodeManager; | ||
17 | #include "internal/FlowManager.hpp" | ||
18 | |||
19 | #include "NodeData/WiFi/WiFiObs.hpp" | ||
20 | |||
21 | 112 | NAV::WiFiObsFile::WiFiObsFile() | |
22 |
3/6✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
|
112 | : Node(typeStatic()) |
23 | { | ||
24 | LOG_TRACE("{}: called", name); | ||
25 | |||
26 | 112 | _hasConfig = true; | |
27 | 112 | _guiConfigDefaultWindowSize = { 488, 248 }; | |
28 | |||
29 |
4/8✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 112 times.
✓ Branch 9 taken 112 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
336 | nm::CreateOutputPin(this, "WiFiObs", Pin::Type::Flow, { NAV::WiFiObs::type() }, &WiFiObsFile::pollData); |
30 | // nm::CreateOutputPin(this, "Header Columns", Pin::Type::Object, { "std::vector<std::string>" }, &_headerColumns); | ||
31 | 224 | } | |
32 | |||
33 | 224 | NAV::WiFiObsFile::~WiFiObsFile() | |
34 | { | ||
35 | LOG_TRACE("{}: called", nameId()); | ||
36 | 224 | } | |
37 | |||
38 | 224 | std::string NAV::WiFiObsFile::typeStatic() | |
39 | { | ||
40 |
1/2✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
|
448 | return "WiFiObsFile"; |
41 | } | ||
42 | |||
43 | ✗ | std::string NAV::WiFiObsFile::type() const | |
44 | { | ||
45 | ✗ | return typeStatic(); | |
46 | } | ||
47 | |||
48 | 112 | std::string NAV::WiFiObsFile::category() | |
49 | { | ||
50 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
224 | return "Data Provider"; |
51 | } | ||
52 | |||
53 | ✗ | void NAV::WiFiObsFile::guiConfig() | |
54 | { | ||
55 | ✗ | if (auto res = FileReader::guiConfig(".csv,.*", { ".csv" }, size_t(id), nameId())) | |
56 | { | ||
57 | ✗ | LOG_DEBUG("{}: Path changed to {}", nameId(), _path); | |
58 | ✗ | flow::ApplyChanges(); | |
59 | ✗ | if (res == FileReader::PATH_CHANGED) | |
60 | { | ||
61 | ✗ | doReinitialize(); | |
62 | } | ||
63 | else | ||
64 | { | ||
65 | ✗ | doDeinitialize(); | |
66 | } | ||
67 | } | ||
68 | ✗ | } | |
69 | |||
70 | ✗ | [[nodiscard]] json NAV::WiFiObsFile::save() const | |
71 | { | ||
72 | LOG_TRACE("{}: called", nameId()); | ||
73 | |||
74 | ✗ | json j; | |
75 | |||
76 | ✗ | j["FileReader"] = FileReader::save(); | |
77 | |||
78 | ✗ | return j; | |
79 | ✗ | } | |
80 | |||
81 | ✗ | void NAV::WiFiObsFile::restore(json const& j) | |
82 | { | ||
83 | LOG_TRACE("{}: called", nameId()); | ||
84 | |||
85 | ✗ | if (j.contains("FileReader")) | |
86 | { | ||
87 | ✗ | FileReader::restore(j.at("FileReader")); | |
88 | } | ||
89 | ✗ | } | |
90 | |||
91 | ✗ | bool NAV::WiFiObsFile::initialize() | |
92 | { | ||
93 | LOG_TRACE("{}: called", nameId()); | ||
94 | |||
95 | ✗ | return FileReader::initialize(); | |
96 | } | ||
97 | |||
98 | ✗ | void NAV::WiFiObsFile::deinitialize() | |
99 | { | ||
100 | LOG_TRACE("{}: called", nameId()); | ||
101 | |||
102 | ✗ | FileReader::deinitialize(); | |
103 | ✗ | } | |
104 | |||
105 | ✗ | bool NAV::WiFiObsFile::resetNode() | |
106 | { | ||
107 | ✗ | FileReader::resetReader(); | |
108 | |||
109 | ✗ | return true; | |
110 | } | ||
111 | |||
112 | ✗ | std::shared_ptr<const NAV::NodeData> NAV::WiFiObsFile::pollData() | |
113 | { | ||
114 | ✗ | auto obs = std::make_shared<WiFiObs>(); | |
115 | |||
116 | // Read line | ||
117 | ✗ | std::string line; | |
118 | ✗ | getline(line); | |
119 | // Remove any starting non text characters | ||
120 | ✗ | line.erase(line.begin(), std::ranges::find_if(line, [](int ch) { return std::isgraph(ch); })); | |
121 | |||
122 | ✗ | if (line.empty()) | |
123 | { | ||
124 | ✗ | return nullptr; | |
125 | } | ||
126 | |||
127 | // Convert line into stream | ||
128 | ✗ | std::stringstream lineStream(line); | |
129 | ✗ | std::string cell; | |
130 | |||
131 | ✗ | uint16_t gpsCycle = 0; | |
132 | ✗ | uint16_t gpsWeek = 0; | |
133 | ✗ | long double gpsToW = 0.0; | |
134 | ✗ | InsTime time; | |
135 | |||
136 | ✗ | bool gpsCycleSet = false; | |
137 | ✗ | bool gpsWeekSet = false; | |
138 | ✗ | bool gpsToWSet = false; | |
139 | ✗ | bool macAddressSet = false; | |
140 | ✗ | bool distanceSet = false; | |
141 | ✗ | bool distanceStdSet = false; | |
142 | |||
143 | // Split line at comma | ||
144 | ✗ | for (const auto& column : _headerColumns) | |
145 | { | ||
146 | ✗ | if (std::getline(lineStream, cell, ',')) | |
147 | { | ||
148 | // Remove any trailing non text characters | ||
149 | ✗ | cell.erase(std::ranges::find_if(cell, [](int ch) { return std::iscntrl(ch); }), cell.end()); | |
150 | ✗ | if (cell.empty()) | |
151 | { | ||
152 | ✗ | continue; | |
153 | } | ||
154 | |||
155 | ✗ | if (column == "GpsCycle") | |
156 | { | ||
157 | ✗ | gpsCycle = static_cast<uint16_t>(std::stoul(cell)); | |
158 | ✗ | gpsCycleSet = true; | |
159 | } | ||
160 | ✗ | else if (column == "GpsWeek") | |
161 | { | ||
162 | ✗ | gpsWeek = static_cast<uint16_t>(std::stoul(cell)); | |
163 | ✗ | gpsWeekSet = true; | |
164 | } | ||
165 | ✗ | else if (column == "GpsToW [s]") | |
166 | { | ||
167 | ✗ | gpsToW = std::stold(cell); | |
168 | ✗ | gpsToWSet = true; | |
169 | } | ||
170 | ✗ | else if (column == "MacAddress") | |
171 | { | ||
172 | ✗ | obs->macAddress = cell; | |
173 | ✗ | macAddressSet = true; | |
174 | } | ||
175 | ✗ | else if (column == "Distance [m]") | |
176 | { | ||
177 | ✗ | obs->distance = std::stod(cell); | |
178 | ✗ | distanceSet = true; | |
179 | } | ||
180 | ✗ | else if (column == "DistanceStd [m]") | |
181 | { | ||
182 | ✗ | obs->distanceStd = std::stod(cell); | |
183 | ✗ | distanceStdSet = true; | |
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | ✗ | if (!gpsCycleSet || !gpsWeekSet || !gpsToWSet || !macAddressSet || !distanceSet || !distanceStdSet) | |
189 | { | ||
190 | ✗ | LOG_ERROR("{}: Not all columns are set", nameId()); | |
191 | ✗ | return nullptr; | |
192 | } | ||
193 | ✗ | time = InsTime(gpsCycle, gpsWeek, gpsToW); | |
194 | ✗ | obs->insTime = time; | |
195 | ✗ | invokeCallbacks(OUTPUT_PORT_INDEX_WiFiObs_OBS, obs); | |
196 | ✗ | return obs; | |
197 | ✗ | } | |
198 |