INSTINCT Code Coverage Report


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