0.5.1
Loading...
Searching...
No Matches
WiFiObsFile.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
9#include "WiFiObsFile.hpp"
10
11#include "util/Logger.hpp"
12
14
16
18
20 : Node(typeStatic())
21{
22 LOG_TRACE("{}: called", name);
23
24 _hasConfig = true;
25 _guiConfigDefaultWindowSize = { 488, 248 };
26
28 // CreateOutputPin("Header Columns", Pin::Type::Object, { "std::vector<std::string>" }, &_headerColumns);
29}
30
32{
33 LOG_TRACE("{}: called", nameId());
34}
35
37{
38 return "WiFiObsFile";
39}
40
41std::string NAV::WiFiObsFile::type() const
42{
43 return typeStatic();
44}
45
47{
48 return "Data Provider";
49}
50
52{
53 if (auto res = FileReader::guiConfig(".csv,.*", { ".csv" }, size_t(id), nameId()))
54 {
55 LOG_DEBUG("{}: Path changed to {}", nameId(), _path);
57 if (res == FileReader::PATH_CHANGED)
58 {
60 }
61 else
62 {
64 }
65 }
66}
67
68[[nodiscard]] json NAV::WiFiObsFile::save() const
69{
70 LOG_TRACE("{}: called", nameId());
71
72 json j;
73
74 j["FileReader"] = FileReader::save();
75
76 return j;
77}
78
80{
81 LOG_TRACE("{}: called", nameId());
82
83 if (j.contains("FileReader"))
84 {
85 FileReader::restore(j.at("FileReader"));
86 }
87}
88
90{
91 LOG_TRACE("{}: called", nameId());
92
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
101}
102
104{
106
107 return true;
108}
109
110std::shared_ptr<const NAV::NodeData> NAV::WiFiObsFile::pollData()
111{
112 auto obs = std::make_shared<WiFiObs>();
113
114 // Read line
115 std::string line;
116 getline(line);
117 // Remove any starting non text characters
118 line.erase(line.begin(), std::ranges::find_if(line, [](int ch) { return std::isgraph(ch); }));
119
120 if (line.empty())
121 {
122 return nullptr;
123 }
124
125 // Convert line into stream
126 std::stringstream lineStream(line);
127 std::string cell;
128
129 uint16_t gpsCycle = 0;
130 uint16_t gpsWeek = 0;
131 long double gpsToW = 0.0;
132 InsTime time;
133
134 bool gpsCycleSet = false;
135 bool gpsWeekSet = false;
136 bool gpsToWSet = false;
137 bool macAddressSet = false;
138 bool distanceSet = false;
139 bool distanceStdSet = false;
140
141 // Split line at comma
142 for (const auto& column : _headerColumns)
143 {
144 if (std::getline(lineStream, cell, ','))
145 {
146 // Remove any trailing non text characters
147 cell.erase(std::ranges::find_if(cell, [](int ch) { return std::iscntrl(ch); }), cell.end());
148 if (cell.empty())
149 {
150 continue;
151 }
152
153 if (column == "GpsCycle")
154 {
155 gpsCycle = static_cast<uint16_t>(std::stoul(cell));
156 gpsCycleSet = true;
157 }
158 else if (column == "GpsWeek")
159 {
160 gpsWeek = static_cast<uint16_t>(std::stoul(cell));
161 gpsWeekSet = true;
162 }
163 else if (column == "GpsToW [s]")
164 {
165 gpsToW = std::stold(cell);
166 gpsToWSet = true;
167 }
168 else if (column == "MacAddress")
169 {
170 obs->macAddress = cell;
171 macAddressSet = true;
172 }
173 else if (column == "Distance [m]")
174 {
175 obs->distance = std::stod(cell);
176 distanceSet = true;
177 }
178 else if (column == "DistanceStd [m]")
179 {
180 obs->distanceStd = std::stod(cell);
181 distanceStdSet = true;
182 }
183 }
184 }
185
186 if (!gpsCycleSet || !gpsWeekSet || !gpsToWSet || !macAddressSet || !distanceSet || !distanceStdSet)
187 {
188 LOG_ERROR("{}: Not all columns are set", nameId());
189 return nullptr;
190 }
191 time = InsTime(gpsCycle, gpsWeek, gpsToW);
192 obs->insTime = time;
194 return obs;
195}
Save/Load the Nodes.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Keeps track of the current real/simulation time.
WiFiObs File Reader.
Espressif Observation Class.
bool initialize()
Initialize the file reader.
void restore(const json &j)
Restores the node from a json object.
std::string _path
Path to the file.
@ PATH_CHANGED
The path changed and exists.
std::vector< std::string > _headerColumns
Header Columns of a CSV file.
GuiResult guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
void resetReader()
Moves the read cursor to the start.
auto & getline(std::string &str)
Reads a line from the filestream.
json save() const
Saves the node into a json object.
void deinitialize()
Deinitialize the file reader.
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
OutputPin * CreateOutputPin(const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
Definition Node.cpp:420
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:179
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
static constexpr size_t OUTPUT_PORT_INDEX_WiFiObs_OBS
Flow (WiFiObs)
std::shared_ptr< const NodeData > pollData()
Polls data from the file.
json save() const override
Saves the node into a json object.
void deinitialize() override
Deinitialize the node.
WiFiObsFile()
Default constructor.
bool initialize() override
Initialize the node.
void restore(const json &j) override
Restores the node from a json object.
std::string type() const override
String representation of the Class Type.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
bool resetNode() override
Resets the node. Moves the read cursor to the start.
static std::string category()
String representation of the Class Category.
~WiFiObsFile() override
Destructor.
static std::string type()
Returns the type of the data class.
Definition WiFiObs.hpp:27
void ApplyChanges()
Signals that there have been changes to the flow.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52