INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataProvider/GNSS/FileReader/UbloxFile.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 61 83 73.5%
Functions: 10 13 76.9%
Branches: 60 142 42.3%

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 "UbloxFile.hpp"
10
11 #include "util/Logger.hpp"
12
13 #include "internal/NodeManager.hpp"
14 namespace nm = NAV::NodeManager;
15 #include "internal/FlowManager.hpp"
16
17 #include "util/Vendor/Ublox/UbloxUtilities.hpp"
18 #include "util/Time/TimeBase.hpp"
19
20 #include "NodeData/GNSS/UbloxObs.hpp"
21
22 114 NAV::UbloxFile::UbloxFile()
23
5/10
✓ 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.
✓ Branch 14 taken 114 times.
✗ Branch 15 not taken.
114 : Node(typeStatic()), _sensor(typeStatic())
24 {
25 LOG_TRACE("{}: called", name);
26
27 114 _hasConfig = true;
28 114 _guiConfigDefaultWindowSize = { 380, 70 };
29
30
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::CreateOutputPin(this, "UbloxObs", Pin::Type::Flow, { NAV::UbloxObs::type() }, &UbloxFile::pollData);
31 228 }
32
33 232 NAV::UbloxFile::~UbloxFile()
34 {
35 LOG_TRACE("{}: called", nameId());
36 232 }
37
38 340 std::string NAV::UbloxFile::typeStatic()
39 {
40
1/2
✓ Branch 1 taken 340 times.
✗ Branch 2 not taken.
680 return "UbloxFile";
41 }
42
43 std::string NAV::UbloxFile::type() const
44 {
45 return typeStatic();
46 }
47
48 112 std::string NAV::UbloxFile::category()
49 {
50
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
224 return "Data Provider";
51 }
52
53 void NAV::UbloxFile::guiConfig()
54 {
55 if (auto res = FileReader::guiConfig(".ubx,.*", { ".ubx" }, size_t(id), nameId()))
56 {
57 LOG_DEBUG("{}: Path changed to {}", nameId(), _path);
58 flow::ApplyChanges();
59 if (res == FileReader::PATH_CHANGED)
60 {
61 doReinitialize();
62 }
63 else
64 {
65 doDeinitialize();
66 }
67 }
68 }
69
70 [[nodiscard]] json NAV::UbloxFile::save() const
71 {
72 LOG_TRACE("{}: called", nameId());
73
74 json j;
75
76 j["FileReader"] = FileReader::save();
77
78 return j;
79 }
80
81 2 void NAV::UbloxFile::restore(json const& j)
82 {
83 LOG_TRACE("{}: called", nameId());
84
85
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (j.contains("FileReader"))
86 {
87 2 FileReader::restore(j.at("FileReader"));
88 }
89 2 }
90
91 2 bool NAV::UbloxFile::initialize()
92 {
93 LOG_TRACE("{}: called", nameId());
94
95 2 _lastObsTime.reset();
96
97 2 return FileReader::initialize();
98 }
99
100 2 void NAV::UbloxFile::deinitialize()
101 {
102 LOG_TRACE("{}: called", nameId());
103
104 2 FileReader::deinitialize();
105 2 }
106
107 4 bool NAV::UbloxFile::resetNode()
108 {
109 4 FileReader::resetReader();
110
111 4 return true;
112 }
113
114 16416 std::shared_ptr<const NAV::NodeData> NAV::UbloxFile::pollData()
115 {
116 16416 uint8_t i = 0;
117 16416 std::unique_ptr<uart::protocol::Packet> packet = nullptr;
118 16416 std::shared_ptr<UbloxObs> obs;
119 while (true)
120 {
121
8/12
✓ Branch 1 taken 5305880 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5305880 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5305880 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 5305880 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5305878 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 5305878 times.
✓ Branch 14 taken 2 times.
5305880 while (!eof() && read(reinterpret_cast<char*>(&i), 1))
122 {
123
1/2
✓ Branch 1 taken 5305878 times.
✗ Branch 2 not taken.
5305878 packet = _sensor.findPacket(i);
124
125
2/2
✓ Branch 1 taken 63698 times.
✓ Branch 2 taken 5242180 times.
5305878 if (packet != nullptr)
126 {
127 63698 break;
128 }
129 }
130
131
6/8
✓ Branch 1 taken 63700 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 63700 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 63698 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 63698 times.
63700 if (!packet || eof())
132 {
133
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
2 LOG_DEBUG("{}: End of file reached.", nameId());
134 2 return nullptr;
135 }
136
137
2/4
✓ Branch 2 taken 63698 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 63698 times.
63698 if (packet->getRawDataLength() == 0)
138 {
139 LOG_TRACE("{}: Packet has empty payload", nameId());
140 return nullptr;
141 }
142
143
1/2
✓ Branch 1 taken 63698 times.
✗ Branch 2 not taken.
63698 obs = std::make_shared<UbloxObs>();
144
4/6
✓ Branch 1 taken 63698 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 63698 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 194 times.
✓ Branch 9 taken 63504 times.
63698 if (!vendor::ublox::decryptUbloxObs(obs, *packet, nameId())) { continue; };
145
3/4
✓ Branch 2 taken 63504 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46854 times.
✓ Branch 5 taken 16650 times.
63504 if (packet->type() != uart::protocol::Packet::Type::TYPE_BINARY) { continue; };
146
147
2/2
✓ Branch 2 taken 3200 times.
✓ Branch 3 taken 13450 times.
16650 if (!obs->insTime.empty())
148 {
149 3200 _lastObsTime = obs->insTime;
150 }
151 else
152 {
153
2/2
✓ Branch 1 taken 13214 times.
✓ Branch 2 taken 236 times.
13450 if (!_lastObsTime.empty())
154 {
155 13214 obs->insTime = _lastObsTime;
156 }
157 else
158 {
159 LOG_DATA("{}: Could not set valid time. Skipping package.", nameId());
160 236 continue;
161 }
162 }
163 16414 break;
164 }
165
166 LOG_DATA("{}: [{}] Packet found [{}][{}]", nameId(), obs->insTime.toYMDHMS(GPST),
167 obs->msgClass, vendor::ublox::getStringFromMsgId(obs->msgClass, obs->msgId));
168
169
1/2
✓ Branch 2 taken 16414 times.
✗ Branch 3 not taken.
16414 invokeCallbacks(OUTPUT_PORT_INDEX_UBLOX_OBS, obs);
170 16414 return obs;
171 16416 }
172
173 2 NAV::FileReader::FileType NAV::UbloxFile::determineFileType()
174 {
175 LOG_TRACE("called for {}", nameId());
176
177
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 auto filestream = std::ifstream(getFilepath());
178
179 2 constexpr uint16_t BUFFER_SIZE = 10;
180
181 2 std::array<char, BUFFER_SIZE> buffer{};
182
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (filestream.good())
183 {
184
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 filestream.read(buffer.data(), BUFFER_SIZE);
185
186
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if ((static_cast<uint8_t>(buffer.at(0)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_1
187 && static_cast<uint8_t>(buffer.at(1)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_2)
188
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 || buffer.at(0) == vendor::ublox::UbloxUartSensor::ASCII_START_CHAR)
189 {
190
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 filestream.close();
191
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
2 LOG_DEBUG("{} has the file type: Binary", nameId());
192 2 return FileType::BINARY;
193 }
194 filestream.close();
195
196 LOG_ERROR("{} could not determine file type", nameId());
197 return FileType::NONE;
198 }
199
200 LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
201 return FileType::NONE;
202 2 }
203