0.4.1
Loading...
Searching...
No Matches
CsvLogger.hpp
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/// @file CsvLogger.hpp
10/// @brief Data Logger for CSV files
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2024-06-03
13
14#pragma once
15
19
20namespace NAV
21{
22class NodeData;
23
24/// Data Logger for PosVelAtt observations
25class CsvLogger : public Node, public FileWriter, public CommonLog
26{
27 public:
28 /// @brief Default constructor
29 CsvLogger();
30 /// @brief Destructor
31 ~CsvLogger() override;
32 /// @brief Copy constructor
33 CsvLogger(const CsvLogger&) = delete;
34 /// @brief Move constructor
35 CsvLogger(CsvLogger&&) = delete;
36 /// @brief Copy assignment operator
37 CsvLogger& operator=(const CsvLogger&) = delete;
38 /// @brief Move assignment operator
40
41 /// @brief String representation of the Class Type
42 [[nodiscard]] static std::string typeStatic();
43
44 /// @brief String representation of the Class Type
45 [[nodiscard]] std::string type() const override;
46
47 /// @brief String representation of the Class Category
48 [[nodiscard]] static std::string category();
49
50 /// @brief ImGui config window which is shown on double click
51 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
52 void guiConfig() override;
53
54 /// @brief Saves the node into a json object
55 [[nodiscard]] json save() const override;
56
57 /// @brief Restores the node from a json object
58 /// @param[in] j Json object with the node state
59 void restore(const json& j) override;
60
61 /// @brief Function called by the flow executer after finishing to flush out remaining data
62 void flush() override;
63
64 /// @brief Called when a new link is to be established
65 /// @param[in] startPin Pin where the link starts
66 /// @param[in] endPin Pin where the link ends
67 /// @return True if link is allowed, false if link is rejected
68 bool onCreateLink(OutputPin& startPin, InputPin& endPin) override;
69
70 private:
71 /// @brief Initialize the node
72 bool initialize() override;
73
74 /// @brief Deinitialize the node
75 void deinitialize() override;
76
77 /// @brief Writes the header
78 void writeHeader();
79
80 /// @brief Rewrites the data file with a new size
81 /// @param[in] oldSize Old dynamic size
82 /// @param[in] newSize New dynamic size
83 void rewriteData(size_t oldSize, size_t newSize);
84
85 /// @brief Write Observation to the file
86 /// @param[in] queue Queue with all the received data messages
87 /// @param[in] pinIdx Index of the pin the data is received on
88 void writeObservation(InputPin::NodeDataQueue& queue, size_t pinIdx);
89
90 /// Type last connected
91 std::string _lastConnectedType;
92
93 /// Flag whether the header was written already
94 bool _headerWritten = false;
95
96 /// Dynamic Header
97 std::vector<std::string> _dynamicHeader;
98
99 /// Header which should be logged
100 std::vector<std::pair<std::string, bool>> _headerLogging;
101 /// Amount of headers which are logged
103 /// Regex to search for when selecting
105 /// Default for new headers
107 /// Sort headers in the GUI
109};
110
111} // namespace NAV
Common logging variables like time into run and local positions.
File Writer class.
nlohmann::json json
json namespace
Node Class.
CommonLog(const CommonLog &)=delete
Copy constructor.
void guiConfig() override
ImGui config window which is shown on double click.
Definition CsvLogger.cpp:60
bool _headerLoggingSortGui
Sort headers in the GUI.
static std::string typeStatic()
String representation of the Class Type.
Definition CsvLogger.cpp:45
std::vector< std::pair< std::string, bool > > _headerLogging
Header which should be logged.
bool initialize() override
Initialize the node.
void rewriteData(size_t oldSize, size_t newSize)
Rewrites the data file with a new size.
std::vector< std::string > _dynamicHeader
Dynamic Header.
Definition CsvLogger.hpp:97
bool _headerWritten
Flag whether the header was written already.
Definition CsvLogger.hpp:94
void restore(const json &j) override
Restores the node from a json object.
json save() const override
Saves the node into a json object.
void writeObservation(InputPin::NodeDataQueue &queue, size_t pinIdx)
Write Observation to the file.
CsvLogger(const CsvLogger &)=delete
Copy constructor.
CsvLogger(CsvLogger &&)=delete
Move constructor.
std::string _lastConnectedType
Type last connected.
Definition CsvLogger.hpp:91
bool onCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link is to be established.
std::string type() const override
String representation of the Class Type.
Definition CsvLogger.cpp:50
void writeHeader()
Writes the header.
bool _headerLoggingDefault
Default for new headers.
CsvLogger & operator=(CsvLogger &&)=delete
Move assignment operator.
CsvLogger & operator=(const CsvLogger &)=delete
Copy assignment operator.
void flush() override
Function called by the flow executer after finishing to flush out remaining data.
~CsvLogger() override
Destructor.
Definition CsvLogger.cpp:40
static std::string category()
String representation of the Class Category.
Definition CsvLogger.cpp:55
std::string _headerLoggingRegex
Regex to search for when selecting.
size_t _headerLoggingCount
Amount of headers which are logged.
CsvLogger()
Default constructor.
Definition CsvLogger.cpp:25
void deinitialize() override
Deinitialize the node.
FileWriter(const FileWriter &)=delete
Copy constructor.
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
Parent class for all data transmitted over Flow pins.
Definition NodeData.hpp:28
Node(std::string name)
Constructor.
Definition Node.cpp:30
Output pins of nodes.
Definition Pin.hpp:338