0.4.1
Loading...
Searching...
No Matches
EmlidSensor.cpp
Go to the documentation of this file.
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
14
16
18namespace nm = NAV::NodeManager;
20
22
25{
26 LOG_TRACE("{}: called", name);
27
28 _onlyRealTime = true;
29 _hasConfig = true;
30 _guiConfigDefaultWindowSize = { 360, 70 };
31
32 // TODO: Update the library to handle different baudrates
34
36}
37
39{
40 LOG_TRACE("{}: called", nameId());
41}
42
44{
45 return "EmlidSensor";
46}
47
48std::string NAV::EmlidSensor::type() const
49{
50 return typeStatic();
51}
52
54{
55 return "Data Provider";
56}
57
59{
60 if (ImGui::InputTextWithHint("SensorPort", "/dev/ttyACM0", &_sensorPort))
61 {
62 LOG_DEBUG("{}: SensorPort changed to {}", nameId(), _sensorPort);
65 }
66 ImGui::SameLine();
67 gui::widgets::HelpMarker("COM port where the sensor is attached to\n"
68 "- \"COM1\" (Windows format for physical and virtual (USB) serial port)\n"
69 "- \"/dev/ttyS1\" (Linux format for physical serial port)\n"
70 "- \"/dev/ttyUSB0\" (Linux format for virtual (USB) serial port)\n"
71 "- \"/dev/tty.usbserial-FTXXXXXX\" (Mac OS X format for virtual (USB) serial port)\n"
72 "- \"/dev/ttyS0\" (CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1)");
73}
74
75[[nodiscard]] json NAV::EmlidSensor::save() const
76{
77 LOG_TRACE("{}: called", nameId());
78
79 json j;
80
81 j["UartSensor"] = UartSensor::save();
82
83 return j;
84}
85
87{
88 LOG_TRACE("{}: called", nameId());
89
90 if (j.contains("UartSensor"))
91 {
92 UartSensor::restore(j.at("UartSensor"));
93 }
94}
95
97{
98 return true;
99}
100
102{
103 LOG_TRACE("{}: called", nameId());
104
105 // connect to the sensor
106 try
107 {
109
110 LOG_DEBUG("{} connected on port {} with baudrate {}", nameId(), _sensorPort, sensorBaudrate());
111 }
112 catch (...)
113 {
114 LOG_ERROR("{} could not connect", nameId());
115 return false;
116 }
117
118 _sensor->registerAsyncPacketReceivedHandler(this, asciiOrBinaryAsyncMessageReceived);
119
120 return true;
121}
122
124{
125 LOG_TRACE("{}: called", nameId());
126
127 if (!isInitialized())
128 {
129 return;
130 }
131
132 if (_sensor->isConnected())
133 {
134 try
135 {
136 _sensor->unregisterAsyncPacketReceivedHandler();
137 }
138 catch (...) // NOLINT(bugprone-empty-catch)
139 {}
140
141 _sensor->disconnect();
142 }
143}
144
145void NAV::EmlidSensor::asciiOrBinaryAsyncMessageReceived(void* userData, uart::protocol::Packet& p, [[maybe_unused]] size_t index)
146{
147 auto* erSensor = static_cast<EmlidSensor*>(userData);
148
149 erSensor->invokeCallbacks(OUTPUT_PORT_INDEX_EMLID_OBS, std::make_shared<UartPacket>(p));
150}
Emlid Sensor Class.
Save/Load the Nodes.
nlohmann::json json
json namespace
Text Help Marker (?) with Tooltip.
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Manages all Nodes.
Keeps track of the current real/simulation time.
UART Packet storage class.
bool initialize() override
Initialize the node.
EmlidSensor()
Default constructor.
std::string type() const override
String representation of the Class Type.
static std::string category()
String representation of the Class Category.
static void asciiOrBinaryAsyncMessageReceived(void *userData, uart::protocol::Packet &p, size_t index)
Callback handler for notifications of new asynchronous data packets received.
void restore(const json &j) override
Restores the node from a json object.
json save() const override
Saves the node into a json object.
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
~EmlidSensor() override
Destructor.
static std::string typeStatic()
String representation of the Class Type.
void guiConfig() override
ImGui config window which is shown on double click.
vendor::emlid::EmlidUartSensor _sensor
Sensor Object.
static constexpr size_t OUTPUT_PORT_INDEX_EMLID_OBS
Flow (EmlidObs)
void deinitialize() override
Deinitialize the node.
bool isInitialized() const
Checks if the node is initialized.
Definition Node.cpp:504
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:395
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
bool _onlyRealTime
Whether the node can run in post-processing or only real-time.
Definition Node.hpp:419
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
static std::string type()
Returns the type of the data class.
static int baudrate2Selection(Baudrate baud)
Returns the guiSelection for the given baudrate.
int _selectedBaudrate
Baudrate for the sensor.
@ BAUDRATE_9600
Baudrate with 9600 symbols per second [Baud].
std::string _sensorPort
void restore(const json &j)
Restores the node from a json object.
Baudrate sensorBaudrate() const
Returns the Baudrate for the element Selected by the GUI.
json save() const
Saves the node into a json object.
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
void HelpMarker(const char *desc, const char *symbol="(?)")
Text Help Marker, e.g. '(?)', with Tooltip.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52