0.4.1
Loading...
Searching...
No Matches
UartDataLogger.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 "UartDataLogger.hpp"
10
12
13#include "util/Logger.hpp"
14
15#include <iomanip> // std::setprecision
16
18namespace nm = NAV::NodeManager;
20
33
38
40{
41 return "UartDataLogger";
42}
43
44std::string NAV::UartDataLogger::type() const
45{
46 return typeStatic();
47}
48
50{
51 return "Data Logger";
52}
53
55{
56 if (FileWriter::guiConfig(".ubx", { ".ubx" }, size_t(id), nameId()))
57 {
60 }
61}
62
63[[nodiscard]] json NAV::UartDataLogger::save() const
64{
65 LOG_TRACE("{}: called", nameId());
66
67 json j;
68
69 j["FileWriter"] = FileWriter::save();
70
71 return j;
72}
73
75{
76 LOG_TRACE("{}: called", nameId());
77
78 if (j.contains("FileWriter"))
79 {
80 FileWriter::restore(j.at("FileWriter"));
81 }
82}
83
85{
86 _filestream.flush();
87}
88
90{
91 LOG_TRACE("{}: called", nameId());
92
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
101}
102
104{
105 auto obs = std::static_pointer_cast<const UartPacket>(queue.extract_front());
106
107 if (obs->raw.getRawDataLength() > 0)
108 {
109 _filestream.write(reinterpret_cast<const char*>(obs->raw.getRawData().data()), static_cast<std::streamsize>(obs->raw.getRawDataLength()));
110 }
111 else
112 {
113 LOG_ERROR("{}: Tried to write binary, but observation had no binary data.", nameId());
114 }
115}
Save/Load the Nodes.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#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
Manages all Nodes.
Data Logger for Uart packets.
UART Packet storage class.
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::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
UartDataLogger()
Default constructor.
static std::string category()
String representation of the Class Category.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
json save() const override
Saves the node into a json object.
void flush() override
Function called by the flow executer after finishing to flush out remaining data.
void restore(const json &j) override
Restores the node from a json object.
std::string type() const override
String representation of the Class Type.
bool initialize() override
Initialize the node.
void deinitialize() override
Deinitialize the node.
void writeObservation(InputPin::NodeDataQueue &queue, size_t pinIdx)
Write Observation to the file.
~UartDataLogger() override
Destructor.
static std::string type()
Returns the type of the data class.
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