| 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 "WiFiObsFile.hpp" | ||
| 10 | |||
| 11 | #include "util/Logger.hpp" | ||
| 12 | |||
| 13 | #include "util/Time/TimeBase.hpp" | ||
| 14 | |||
| 15 | #include "internal/FlowManager.hpp" | ||
| 16 | |||
| 17 | #include "NodeData/WiFi/WiFiObs.hpp" | ||
| 18 | |||
| 19 | 114 | NAV::WiFiObsFile::WiFiObsFile() | |
| 20 |
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()) |
| 21 | { | ||
| 22 | LOG_TRACE("{}: called", name); | ||
| 23 | |||
| 24 | 114 | _hasConfig = true; | |
| 25 | 114 | _guiConfigDefaultWindowSize = { 488, 248 }; | |
| 26 | |||
| 27 |
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 | CreateOutputPin("WiFiObs", Pin::Type::Flow, { NAV::WiFiObs::type() }, &WiFiObsFile::pollData); |
| 28 | // CreateOutputPin("Header Columns", Pin::Type::Object, { "std::vector<std::string>" }, &_headerColumns); | ||
| 29 | 228 | } | |
| 30 | |||
| 31 | 228 | NAV::WiFiObsFile::~WiFiObsFile() | |
| 32 | { | ||
| 33 | LOG_TRACE("{}: called", nameId()); | ||
| 34 | 228 | } | |
| 35 | |||
| 36 | 228 | std::string NAV::WiFiObsFile::typeStatic() | |
| 37 | { | ||
| 38 |
1/2✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
|
456 | return "WiFiObsFile"; |
| 39 | } | ||
| 40 | |||
| 41 | ✗ | std::string NAV::WiFiObsFile::type() const | |
| 42 | { | ||
| 43 | ✗ | return typeStatic(); | |
| 44 | } | ||
| 45 | |||
| 46 | 114 | std::string NAV::WiFiObsFile::category() | |
| 47 | { | ||
| 48 |
1/2✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
|
228 | return "Data Provider"; |
| 49 | } | ||
| 50 | |||
| 51 | ✗ | void NAV::WiFiObsFile::guiConfig() | |
| 52 | { | ||
| 53 | ✗ | if (auto res = FileReader::guiConfig(".csv,.*", { ".csv" }, size_t(id), nameId())) | |
| 54 | { | ||
| 55 | ✗ | LOG_DEBUG("{}: Path changed to {}", nameId(), _path); | |
| 56 | ✗ | flow::ApplyChanges(); | |
| 57 | ✗ | if (res == FileReader::PATH_CHANGED) | |
| 58 | { | ||
| 59 | ✗ | doReinitialize(); | |
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | ✗ | doDeinitialize(); | |
| 64 | } | ||
| 65 | } | ||
| 66 | ✗ | } | |
| 67 | |||
| 68 | ✗ | [[nodiscard]] json NAV::WiFiObsFile::save() const | |
| 69 | { | ||
| 70 | LOG_TRACE("{}: called", nameId()); | ||
| 71 | |||
| 72 | ✗ | json j; | |
| 73 | |||
| 74 | ✗ | j["FileReader"] = FileReader::save(); | |
| 75 | |||
| 76 | ✗ | return j; | |
| 77 | ✗ | } | |
| 78 | |||
| 79 | ✗ | void NAV::WiFiObsFile::restore(json const& j) | |
| 80 | { | ||
| 81 | LOG_TRACE("{}: called", nameId()); | ||
| 82 | |||
| 83 | ✗ | if (j.contains("FileReader")) | |
| 84 | { | ||
| 85 | ✗ | FileReader::restore(j.at("FileReader")); | |
| 86 | } | ||
| 87 | ✗ | } | |
| 88 | |||
| 89 | ✗ | bool NAV::WiFiObsFile::initialize() | |
| 90 | { | ||
| 91 | LOG_TRACE("{}: called", nameId()); | ||
| 92 | |||
| 93 | ✗ | return FileReader::initialize(); | |
| 94 | } | ||
| 95 | |||
| 96 | ✗ | void NAV::WiFiObsFile::deinitialize() | |
| 97 | { | ||
| 98 | LOG_TRACE("{}: called", nameId()); | ||
| 99 | |||
| 100 | ✗ | FileReader::deinitialize(); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | ✗ | bool NAV::WiFiObsFile::resetNode() | |
| 104 | { | ||
| 105 | ✗ | FileReader::resetReader(); | |
| 106 | |||
| 107 | ✗ | return true; | |
| 108 | } | ||
| 109 | |||
| 110 | ✗ | std::shared_ptr<const NAV::NodeData> NAV::WiFiObsFile::pollData() | |
| 111 | { | ||
| 112 | ✗ | auto obs = std::make_shared<WiFiObs>(); | |
| 113 | |||
| 114 | // Read line | ||
| 115 | ✗ | std::string line; | |
| 116 | ✗ | getline(line); | |
| 117 | // Remove any starting non text characters | ||
| 118 | ✗ | line.erase(line.begin(), std::ranges::find_if(line, [](int ch) { return std::isgraph(ch); })); | |
| 119 | |||
| 120 | ✗ | if (line.empty()) | |
| 121 | { | ||
| 122 | ✗ | return nullptr; | |
| 123 | } | ||
| 124 | |||
| 125 | // Convert line into stream | ||
| 126 | ✗ | std::stringstream lineStream(line); | |
| 127 | ✗ | std::string cell; | |
| 128 | |||
| 129 | ✗ | uint16_t gpsCycle = 0; | |
| 130 | ✗ | uint16_t gpsWeek = 0; | |
| 131 | ✗ | long double gpsToW = 0.0; | |
| 132 | ✗ | InsTime time; | |
| 133 | |||
| 134 | ✗ | bool gpsCycleSet = false; | |
| 135 | ✗ | bool gpsWeekSet = false; | |
| 136 | ✗ | bool gpsToWSet = false; | |
| 137 | ✗ | bool macAddressSet = false; | |
| 138 | ✗ | bool distanceSet = false; | |
| 139 | ✗ | bool distanceStdSet = false; | |
| 140 | |||
| 141 | // Split line at comma | ||
| 142 | ✗ | for (const auto& column : _headerColumns) | |
| 143 | { | ||
| 144 | ✗ | if (std::getline(lineStream, cell, ',')) | |
| 145 | { | ||
| 146 | // Remove any trailing non text characters | ||
| 147 | ✗ | cell.erase(std::ranges::find_if(cell, [](int ch) { return std::iscntrl(ch); }), cell.end()); | |
| 148 | ✗ | if (cell.empty()) | |
| 149 | { | ||
| 150 | ✗ | continue; | |
| 151 | } | ||
| 152 | |||
| 153 | ✗ | if (column == "GpsCycle") | |
| 154 | { | ||
| 155 | ✗ | gpsCycle = static_cast<uint16_t>(std::stoul(cell)); | |
| 156 | ✗ | gpsCycleSet = true; | |
| 157 | } | ||
| 158 | ✗ | else if (column == "GpsWeek") | |
| 159 | { | ||
| 160 | ✗ | gpsWeek = static_cast<uint16_t>(std::stoul(cell)); | |
| 161 | ✗ | gpsWeekSet = true; | |
| 162 | } | ||
| 163 | ✗ | else if (column == "GpsToW [s]") | |
| 164 | { | ||
| 165 | ✗ | gpsToW = std::stold(cell); | |
| 166 | ✗ | gpsToWSet = true; | |
| 167 | } | ||
| 168 | ✗ | else if (column == "MacAddress") | |
| 169 | { | ||
| 170 | ✗ | obs->macAddress = cell; | |
| 171 | ✗ | macAddressSet = true; | |
| 172 | } | ||
| 173 | ✗ | else if (column == "Distance [m]") | |
| 174 | { | ||
| 175 | ✗ | obs->distance = std::stod(cell); | |
| 176 | ✗ | distanceSet = true; | |
| 177 | } | ||
| 178 | ✗ | else if (column == "DistanceStd [m]") | |
| 179 | { | ||
| 180 | ✗ | obs->distanceStd = std::stod(cell); | |
| 181 | ✗ | distanceStdSet = true; | |
| 182 | } | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | ✗ | if (!gpsCycleSet || !gpsWeekSet || !gpsToWSet || !macAddressSet || !distanceSet || !distanceStdSet) | |
| 187 | { | ||
| 188 | ✗ | LOG_ERROR("{}: Not all columns are set", nameId()); | |
| 189 | ✗ | return nullptr; | |
| 190 | } | ||
| 191 | ✗ | time = InsTime(gpsCycle, gpsWeek, gpsToW); | |
| 192 | ✗ | obs->insTime = time; | |
| 193 | ✗ | invokeCallbacks(OUTPUT_PORT_INDEX_WiFiObs_OBS, obs); | |
| 194 | ✗ | return obs; | |
| 195 | ✗ | } | |
| 196 |