0.5.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
18
31
36
38{
39 return "UartDataLogger";
40}
41
42std::string NAV::UartDataLogger::type() const
43{
44 return typeStatic();
45}
46
48{
49 return "Data Logger";
50}
51
53{
54 if (FileWriter::guiConfig(".ubx", { ".ubx" }, size_t(id), nameId()))
55 {
58 }
59}
60
61[[nodiscard]] json NAV::UartDataLogger::save() const
62{
63 LOG_TRACE("{}: called", nameId());
64
65 json j;
66
67 j["FileWriter"] = FileWriter::save();
68
69 return j;
70}
71
73{
74 LOG_TRACE("{}: called", nameId());
75
76 if (j.contains("FileWriter"))
77 {
78 FileWriter::restore(j.at("FileWriter"));
79 }
80}
81
83{
84 _filestream.flush();
85}
86
88{
89 LOG_TRACE("{}: called", nameId());
90
92}
93
100
102{
103 auto obs = std::static_pointer_cast<const UartPacket>(queue.extract_front());
104
105 if (obs->raw.getRawDataLength() > 0)
106 {
107 _filestream.write(reinterpret_cast<const char*>(obs->raw.getRawData().data()), static_cast<std::streamsize>(obs->raw.getRawDataLength()));
108 }
109 else
110 {
111 LOG_ERROR("{}: Tried to write binary, but observation had no binary data.", nameId());
112 }
113}
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
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:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
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
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.
void ApplyChanges()
Signals that there have been changes to the flow.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52