| 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 "UartDataLogger.hpp" | ||
| 10 | |||
| 11 | #include "NodeData/General/UartPacket.hpp" | ||
| 12 | |||
| 13 | #include "util/Logger.hpp" | ||
| 14 | |||
| 15 | #include <iomanip> // std::setprecision | ||
| 16 | |||
| 17 | #include "internal/NodeManager.hpp" | ||
| 18 | namespace nm = NAV::NodeManager; | ||
| 19 | #include "internal/FlowManager.hpp" | ||
| 20 | |||
| 21 | 114 | NAV::UartDataLogger::UartDataLogger() | |
| 22 |
3/6✓ 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.
|
114 | : Node(typeStatic()) |
| 23 | { | ||
| 24 | LOG_TRACE("{}: called", name); | ||
| 25 | |||
| 26 | 114 | _fileType = FileType::BINARY; | |
| 27 | |||
| 28 | 114 | _hasConfig = true; | |
| 29 | 114 | _guiConfigDefaultWindowSize = { 380, 70 }; | |
| 30 | |||
| 31 |
4/8✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 114 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 114 times.
✓ Branch 9 taken 114 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
342 | nm::CreateInputPin(this, "writeObservation", Pin::Type::Flow, { NAV::UartPacket::type() }, &UartDataLogger::writeObservation); |
| 32 | 228 | } | |
| 33 | |||
| 34 | 228 | NAV::UartDataLogger::~UartDataLogger() | |
| 35 | { | ||
| 36 | LOG_TRACE("{}: called", nameId()); | ||
| 37 | 228 | } | |
| 38 | |||
| 39 | 228 | std::string NAV::UartDataLogger::typeStatic() | |
| 40 | { | ||
| 41 |
1/2✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
|
456 | return "UartDataLogger"; |
| 42 | } | ||
| 43 | |||
| 44 | ✗ | std::string NAV::UartDataLogger::type() const | |
| 45 | { | ||
| 46 | ✗ | return typeStatic(); | |
| 47 | } | ||
| 48 | |||
| 49 | 114 | std::string NAV::UartDataLogger::category() | |
| 50 | { | ||
| 51 |
1/2✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
|
228 | return "Data Logger"; |
| 52 | } | ||
| 53 | |||
| 54 | ✗ | void NAV::UartDataLogger::guiConfig() | |
| 55 | { | ||
| 56 | ✗ | if (FileWriter::guiConfig(".ubx", { ".ubx" }, size_t(id), nameId())) | |
| 57 | { | ||
| 58 | ✗ | flow::ApplyChanges(); | |
| 59 | ✗ | doDeinitialize(); | |
| 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 | |||
| 74 | ✗ | void NAV::UartDataLogger::restore(json const& j) | |
| 75 | { | ||
| 76 | LOG_TRACE("{}: called", nameId()); | ||
| 77 | |||
| 78 | ✗ | if (j.contains("FileWriter")) | |
| 79 | { | ||
| 80 | ✗ | FileWriter::restore(j.at("FileWriter")); | |
| 81 | } | ||
| 82 | ✗ | } | |
| 83 | |||
| 84 | ✗ | void NAV::UartDataLogger::flush() | |
| 85 | { | ||
| 86 | ✗ | _filestream.flush(); | |
| 87 | ✗ | } | |
| 88 | |||
| 89 | ✗ | bool NAV::UartDataLogger::initialize() | |
| 90 | { | ||
| 91 | LOG_TRACE("{}: called", nameId()); | ||
| 92 | |||
| 93 | ✗ | return FileWriter::initialize(); | |
| 94 | } | ||
| 95 | |||
| 96 | ✗ | void NAV::UartDataLogger::deinitialize() | |
| 97 | { | ||
| 98 | LOG_TRACE("{}: called", nameId()); | ||
| 99 | |||
| 100 | ✗ | FileWriter::deinitialize(); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | ✗ | void NAV::UartDataLogger::writeObservation(NAV::InputPin::NodeDataQueue& queue, size_t /* pinIdx */) | |
| 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 | ✗ | } | |
| 116 |