0.5.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
20
33
38
40{
41 return "WiFiObsLogger";
42}
43
44std::string NAV::WiFiObsLogger::type() const
45{
46 return typeStatic();
47}
48
50{
51 return "Data Logger";
52}
53
55{
56 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
57 {
60 }
61
63 {
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
80{
81 LOG_TRACE("{}: called", nameId());
82
83 if (j.contains("FileWriter"))
84 {
85 FileWriter::restore(j.at("FileWriter"));
86 }
87}
88
90{
91 _filestream.flush();
92}
93
95{
96 LOG_TRACE("{}: called", nameId());
97
99 {
100 return false;
101 }
102
104
105 _filestream << "Time [s],GpsCycle,GpsWeek,GpsToW [s],"
106 << "MacAddress,"
107 << "Distance [m],"
108 << "DistanceStd [m]\n";
109
110 return true;
111}
112
114{
115 LOG_TRACE("{}: called", nameId());
116
118}
119
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}
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
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:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:509
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
InputPin * CreateInputPin(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.
Definition Node.cpp:252
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
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
void ApplyChanges()
Signals that there have been changes to the flow.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52