INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataProvider/GNSS/Sensors/EmlidSensor.cpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 14 56 25.0%
Functions: 4 12 33.3%
Branches: 11 62 17.7%

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 "EmlidSensor.hpp"
10
11 #include "util/Logger.hpp"
12
13 #include "util/Time/TimeBase.hpp"
14
15 #include "internal/gui/widgets/HelpMarker.hpp"
16
17 #include "internal/FlowManager.hpp"
18
19 #include "NodeData/General/UartPacket.hpp"
20
21 114 NAV::EmlidSensor::EmlidSensor()
22
4/8
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 114 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 114 times.
✗ Branch 13 not taken.
114 : Node(typeStatic()), _sensor(typeStatic())
23 {
24 LOG_TRACE("{}: called", name);
25
26 114 _onlyRealTime = true;
27 114 _hasConfig = true;
28 114 _guiConfigDefaultWindowSize = { 360, 70 };
29
30 // TODO: Update the library to handle different baudrates
31
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 _selectedBaudrate = baudrate2Selection(Baudrate::BAUDRATE_9600);
32
33
4/8
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 114 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 114 times.
✓ Branch 10 taken 114 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
456 CreateOutputPin("UartPacket", Pin::Type::Flow, { NAV::UartPacket::type() });
34 228 }
35
36 228 NAV::EmlidSensor::~EmlidSensor()
37 {
38 LOG_TRACE("{}: called", nameId());
39 228 }
40
41 342 std::string NAV::EmlidSensor::typeStatic()
42 {
43
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
684 return "EmlidSensor";
44 }
45
46 std::string NAV::EmlidSensor::type() const
47 {
48 return typeStatic();
49 }
50
51 114 std::string NAV::EmlidSensor::category()
52 {
53
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
228 return "Data Provider";
54 }
55
56 void NAV::EmlidSensor::guiConfig()
57 {
58 if (ImGui::InputTextWithHint("SensorPort", "/dev/ttyACM0", &_sensorPort))
59 {
60 LOG_DEBUG("{}: SensorPort changed to {}", nameId(), _sensorPort);
61 flow::ApplyChanges();
62 doDeinitialize();
63 }
64 ImGui::SameLine();
65 gui::widgets::HelpMarker("COM port where the sensor is attached to\n"
66 "- \"COM1\" (Windows format for physical and virtual (USB) serial port)\n"
67 "- \"/dev/ttyS1\" (Linux format for physical serial port)\n"
68 "- \"/dev/ttyUSB0\" (Linux format for virtual (USB) serial port)\n"
69 "- \"/dev/tty.usbserial-FTXXXXXX\" (Mac OS X format for virtual (USB) serial port)\n"
70 "- \"/dev/ttyS0\" (CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1)");
71 }
72
73 [[nodiscard]] json NAV::EmlidSensor::save() const
74 {
75 LOG_TRACE("{}: called", nameId());
76
77 json j;
78
79 j["UartSensor"] = UartSensor::save();
80
81 return j;
82 }
83
84 void NAV::EmlidSensor::restore(json const& j)
85 {
86 LOG_TRACE("{}: called", nameId());
87
88 if (j.contains("UartSensor"))
89 {
90 UartSensor::restore(j.at("UartSensor"));
91 }
92 }
93
94 bool NAV::EmlidSensor::resetNode()
95 {
96 return true;
97 }
98
99 bool NAV::EmlidSensor::initialize()
100 {
101 LOG_TRACE("{}: called", nameId());
102
103 // connect to the sensor
104 try
105 {
106 _sensor->connect(_sensorPort, sensorBaudrate());
107
108 LOG_DEBUG("{} connected on port {} with baudrate {}", nameId(), _sensorPort, sensorBaudrate());
109 }
110 catch (...)
111 {
112 LOG_ERROR("{} could not connect", nameId());
113 return false;
114 }
115
116 _sensor->registerAsyncPacketReceivedHandler(this, asciiOrBinaryAsyncMessageReceived);
117
118 return true;
119 }
120
121 void NAV::EmlidSensor::deinitialize()
122 {
123 LOG_TRACE("{}: called", nameId());
124
125 if (!isInitialized())
126 {
127 return;
128 }
129
130 if (_sensor->isConnected())
131 {
132 try
133 {
134 _sensor->unregisterAsyncPacketReceivedHandler();
135 }
136 catch (...) // NOLINT(bugprone-empty-catch)
137 {}
138
139 _sensor->disconnect();
140 }
141 }
142
143 void NAV::EmlidSensor::asciiOrBinaryAsyncMessageReceived(void* userData, uart::protocol::Packet& p, [[maybe_unused]] size_t index)
144 {
145 auto* erSensor = static_cast<EmlidSensor*>(userData);
146
147 erSensor->invokeCallbacks(OUTPUT_PORT_INDEX_EMLID_OBS, std::make_shared<UartPacket>(p));
148 }
149