INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataLogger/General/MatrixLogger.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 13 71 18.3%
Functions: 4 12 33.3%
Branches: 8 112 7.1%

Line Branch Exec Source
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 "MatrixLogger.hpp"
10
11 #include "util/Logger.hpp"
12
13 #include <iomanip> // std::setprecision
14 #include "util/Eigen.hpp"
15
16 #include "util/Time/TimeBase.hpp"
17
18 #include "internal/NodeManager.hpp"
19 namespace nm = NAV::NodeManager;
20 #include "internal/FlowManager.hpp"
21
22 112 NAV::MatrixLogger::MatrixLogger()
23
4/8
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 112 times.
✗ Branch 12 not taken.
112 : Node(typeStatic())
24 {
25 LOG_TRACE("{}: called", name);
26
27 112 _fileType = FileType::ASCII;
28
29 112 _hasConfig = true;
30 112 _guiConfigDefaultWindowSize = { 380, 70 };
31
32
2/4
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
224 nm::CreateInputPin(this, "write", Pin::Type::Matrix, { "Eigen::MatrixXd" }, &MatrixLogger::writeMatrix);
33 112 }
34
35 224 NAV::MatrixLogger::~MatrixLogger()
36 {
37 LOG_TRACE("{}: called", nameId());
38 224 }
39
40 224 std::string NAV::MatrixLogger::typeStatic()
41 {
42
1/2
✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
448 return "MatrixLogger";
43 }
44
45 std::string NAV::MatrixLogger::type() const
46 {
47 return typeStatic();
48 }
49
50 112 std::string NAV::MatrixLogger::category()
51 {
52
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
224 return "Data Logger";
53 }
54
55 void NAV::MatrixLogger::guiConfig()
56 {
57 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
58 {
59 flow::ApplyChanges();
60 doDeinitialize();
61 }
62
63 if (CommonLog::ShowOriginInput(nameId().c_str()))
64 {
65 flow::ApplyChanges();
66 }
67 }
68
69 [[nodiscard]] json NAV::MatrixLogger::save() const
70 {
71 LOG_TRACE("{}: called", nameId());
72
73 json j;
74
75 j["FileWriter"] = FileWriter::save();
76
77 return j;
78 }
79
80 void NAV::MatrixLogger::restore(json const& j)
81 {
82 LOG_TRACE("{}: called", nameId());
83
84 if (j.contains("FileWriter"))
85 {
86 FileWriter::restore(j.at("FileWriter"));
87 }
88 }
89
90 void NAV::MatrixLogger::flush()
91 {
92 _filestream.flush();
93 }
94
95 bool NAV::MatrixLogger::initialize()
96 {
97 LOG_TRACE("{}: called", nameId());
98
99 if (!FileWriter::initialize())
100 {
101 return false;
102 }
103
104 CommonLog::initialize();
105
106 _headerWritten = false;
107
108 return true;
109 }
110
111 void NAV::MatrixLogger::deinitialize()
112 {
113 LOG_TRACE("{}: called", nameId());
114
115 FileWriter::deinitialize();
116 }
117
118 void NAV::MatrixLogger::writeMatrix(const InsTime& insTime, size_t pinIdx)
119 {
120 constexpr int gpsCyclePrecision = 3;
121 constexpr int gpsTimePrecision = 12;
122 constexpr int valuePrecision = 12;
123
124 if (!_headerWritten)
125 {
126 _filestream << "Time [s],GpsCycle,GpsWeek,GpsTow [s]";
127 }
128
129 if (auto* sourcePin = inputPins.at(pinIdx).link.getConnectedPin())
130 {
131 // Matrix
132 if (sourcePin->dataIdentifier.front() == "Eigen::MatrixXd")
133 {
134 if (auto value = getInputValue<Eigen::MatrixXd>(INPUT_PORT_INDEX_MATRIX);
135 value && !insTime.empty())
136 {
137 if (!_headerWritten)
138 {
139 for (int row = 0; row < value->v->rows(); row++)
140 {
141 for (int col = 0; col < value->v->cols(); col++)
142 {
143 _filestream << ",[" << row << ";" << col << "]";
144 }
145 }
146 _filestream << std::endl; // NOLINT(performance-avoid-endl)
147 _headerWritten = true;
148 }
149
150 _filestream << std::setprecision(valuePrecision) << std::round(calcTimeIntoRun(insTime) * 1e9) / 1e9;
151 _filestream << "," << std::fixed << std::setprecision(gpsCyclePrecision) << insTime.toGPSweekTow().gpsCycle;
152 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().gpsWeek;
153 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().tow;
154 _filestream << std::setprecision(valuePrecision);
155
156 for (int row = 0; row < value->v->rows(); row++)
157 {
158 for (int col = 0; col < value->v->cols(); col++)
159 {
160 _filestream << "," << (*value->v)(row, col);
161 }
162 }
163 _filestream << "\n";
164 }
165 }
166 else
167 {
168 releaseInputValue(pinIdx);
169 }
170 }
171 }
172