INSTINCT Code Coverage Report


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