INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataProvider/GNSS/FileReader/EmlidFile.cpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 12 77 15.6%
Functions: 4 13 30.8%
Branches: 11 124 8.9%

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 "EmlidFile.hpp"
10
11 #include "util/Logger.hpp"
12
13 #include "internal/FlowManager.hpp"
14
15 #include "util/Vendor/Emlid/EmlidUtilities.hpp"
16 #include "util/Time/TimeBase.hpp"
17
18 #include "NodeData/GNSS/EmlidObs.hpp"
19
20 114 NAV::EmlidFile::EmlidFile()
21
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())
22 {
23 LOG_TRACE("{}: called", name);
24
25 114 _hasConfig = true;
26 114 _guiConfigDefaultWindowSize = { 380, 70 };
27
28
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("EmlidObs", Pin::Type::Flow, { NAV::EmlidObs::type() }, &EmlidFile::pollData);
29 228 }
30
31 228 NAV::EmlidFile::~EmlidFile()
32 {
33 LOG_TRACE("{}: called", nameId());
34 228 }
35
36 342 std::string NAV::EmlidFile::typeStatic()
37 {
38
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
684 return "EmlidFile";
39 }
40
41 ✗ std::string NAV::EmlidFile::type() const
42 {
43 ✗ return typeStatic();
44 }
45
46 114 std::string NAV::EmlidFile::category()
47 {
48
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
228 return "Data Provider";
49 }
50
51 ✗ void NAV::EmlidFile::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::EmlidFile::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::EmlidFile::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::EmlidFile::initialize()
90 {
91 LOG_TRACE("{}: called", nameId());
92
93 ✗ return FileReader::initialize();
94 }
95
96 ✗ void NAV::EmlidFile::deinitialize()
97 {
98 LOG_TRACE("{}: called", nameId());
99
100 ✗ FileReader::deinitialize();
101 ✗ }
102
103 ✗ bool NAV::EmlidFile::resetNode()
104 {
105 ✗ FileReader::resetReader();
106
107 ✗ return true;
108 }
109
110 ✗ std::shared_ptr<const NAV::NodeData> NAV::EmlidFile::pollData()
111 {
112 ✗ uint8_t i = 0;
113 ✗ std::unique_ptr<uart::protocol::Packet> packet = nullptr;
114 ✗ while (!eof() && read(reinterpret_cast<char*>(&i), 1))
115 {
116 ✗ packet = _sensor.findPacket(i);
117
118 ✗ if (packet != nullptr)
119 {
120 ✗ break;
121 }
122 }
123
124 ✗ if (!packet)
125 {
126 ✗ return nullptr;
127 }
128
129 // Check if package is empty
130 ✗ if (packet->getRawDataLength() == 0)
131 {
132 ✗ return nullptr;
133 }
134
135 ✗ auto obs = std::make_shared<EmlidObs>();
136 ✗ vendor::emlid::decryptEmlidObs(obs, *packet);
137
138 ✗ if (obs->insTime.empty())
139 {
140 ✗ if (auto currentTime = util::time::GetCurrentInsTime();
141 ✗ !currentTime.empty())
142 {
143 ✗ obs->insTime = currentTime;
144 }
145 }
146
147 ✗ invokeCallbacks(OUTPUT_PORT_INDEX_EMLID_OBS, obs);
148 ✗ return obs;
149 ✗ }
150
151 ✗ NAV::FileReader::FileType NAV::EmlidFile::determineFileType()
152 {
153 LOG_TRACE("called for {}", nameId());
154
155 ✗ auto filestream = std::ifstream(getFilepath());
156
157 ✗ constexpr uint16_t BUFFER_SIZE = 10;
158
159 ✗ std::array<char, BUFFER_SIZE> buffer{};
160 ✗ if (filestream.good())
161 {
162 ✗ filestream.read(buffer.data(), BUFFER_SIZE);
163
164 ✗ if ((static_cast<uint8_t>(buffer.at(0)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_1
165 ✗ && static_cast<uint8_t>(buffer.at(1)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_2)
166 ✗ || buffer.at(0) == vendor::emlid::EmlidUartSensor::ASCII_START_CHAR)
167 {
168 ✗ filestream.close();
169 ✗ LOG_DEBUG("{} has the file type: Binary", nameId());
170 ✗ return FileType::BINARY;
171 }
172 ✗ filestream.close();
173
174 ✗ LOG_ERROR("{} could not determine file type", nameId());
175 ✗ return FileType::NONE;
176 }
177
178 ✗ LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
179 ✗ return FileType::NONE;
180 ✗ }
181