0.4.1
Loading...
Searching...
No Matches
WiFiObsLogger.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 "WiFiObsLogger.hpp"
10
12
14
15#include "util/Logger.hpp"
16
17#include <iomanip> // std::setprecision
18
20namespace nm = NAV::NodeManager;
22
24 : Node(typeStatic())
25{
26 LOG_TRACE("{}: called", name);
27
29
30 _hasConfig = true;
31 _guiConfigDefaultWindowSize = { 380, 70 };
32
34}
35
40
42{
43 return "WiFiObsLogger";
44}
45
46std::string NAV::WiFiObsLogger::type() const
47{
48 return typeStatic();
49}
50
52{
53 return "Data Logger";
54}
55
57{
58 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
59 {
62 }
63
65 {
67 }
68}
69
70[[nodiscard]] json NAV::WiFiObsLogger::save() const
71{
72 LOG_TRACE("{}: called", nameId());
73
74 json j;
75
76 j["FileWriter"] = FileWriter::save();
77
78 return j;
79}
80
82{
83 LOG_TRACE("{}: called", nameId());
84
85 if (j.contains("FileWriter"))
86 {
87 FileWriter::restore(j.at("FileWriter"));
88 }
89}
90
92{
93 _filestream.flush();
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
101 {
102 return false;
103 }
104
106
107 _filestream << "Time [s],GpsCycle,GpsWeek,GpsToW [s],"
108 << "MacAddress,"
109 << "Distance [m],"
110 << "DistanceStd [m]\n";
111
112 return true;
113}
114
116{
117 LOG_TRACE("{}: called", nameId());
118
120}
121
123{
124 if ([[maybe_unused]] auto* sourcePin = inputPins[pinIdx].link.getConnectedPin())
125 {
126 constexpr int gpsCyclePrecision = 3;
127 constexpr int gpsTimePrecision = 12;
128 constexpr int valuePrecision = 15;
129
130 auto nodeData = queue.extract_front();
131
132 // -------------------------------------------------------- Time -----------------------------------------------------------
133
134 auto obs = std::static_pointer_cast<const WiFiObs>(nodeData);
135 if (!obs->insTime.empty())
136 {
137 _filestream << std::setprecision(valuePrecision) << std::round(calcTimeIntoRun(obs->insTime) * 1e9) / 1e9;
138 }
139 _filestream << ",";
140 if (!obs->insTime.empty())
141 {
142 _filestream << std::fixed << std::setprecision(gpsCyclePrecision) << obs->insTime.toGPSweekTow().gpsCycle;
143 }
144 _filestream << ",";
145 if (!obs->insTime.empty())
146 {
147 _filestream << std::defaultfloat << std::setprecision(gpsTimePrecision) << obs->insTime.toGPSweekTow().gpsWeek;
148 }
149 _filestream << ",";
150 if (!obs->insTime.empty())
151 {
152 _filestream << std::defaultfloat << std::setprecision(gpsTimePrecision) << obs->insTime.toGPSweekTow().tow;
153 }
154 _filestream << "," << std::setprecision(valuePrecision);
155
156 // ------------------------------------------------------ MacAddress ----------------------------------------------------------
157 if (!obs->macAddress.empty())
158 {
159 _filestream << obs->macAddress;
160 }
161 _filestream << ",";
162
163 // ------------------------------------------------------- Distance -----------------------------------------------------------
164 _filestream << obs->distance;
165 _filestream << ",";
166 // --------------------------------------------------------- Standard deviation ---------------------------------------------------
167 _filestream << obs->distanceStd;
168
169 _filestream << '\n';
170 }
171}
Save/Load the Nodes.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Manages all Nodes.
Data Logger for WiFi observations.
Espressif Observation Class.
static bool ShowOriginInput(const char *id)
Shows a GUI to input a origin location.
void initialize() const
Initialize the common log variables.
Definition CommonLog.cpp:51
static double calcTimeIntoRun(const InsTime &insTime)
Calculates the relative time into he run.
Definition CommonLog.cpp:70
@ ASCII
Ascii text data.
FileType _fileType
File Type.
void deinitialize()
Deinitialize the file reader.
bool guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
void restore(const json &j)
Restores the node from a json object.
json save() const
Saves the node into a json object.
bool initialize()
Initialize the file reader.
std::ofstream _filestream
File stream to write the file.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:395
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:397
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
bool initialize() override
Initialize the node.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string category()
String representation of the Class Category.
void deinitialize() override
Deinitialize the node.
static std::string typeStatic()
String representation of the Class Type.
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 writeObservation(InputPin::NodeDataQueue &queue, size_t pinIdx)
Write Observation to the file.
~WiFiObsLogger() override
Destructor.
WiFiObsLogger()
Default constructor.
void flush() override
Function called by the flow executer after finishing to flush out remaining data.
json save() const override
Saves the node into a json object.
static std::string type()
Returns the type of the data class.
Definition WiFiObs.hpp:27
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52