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