0.5.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
18
20
23{
24 LOG_TRACE("{}: called", name);
25
26 _onlyRealTime = true;
27 _hasConfig = true;
28 _guiConfigDefaultWindowSize = { 360, 70 };
29
30 // TODO: Update the library to handle different baudrates
32
34}
35
37{
38 LOG_TRACE("{}: called", nameId());
39}
40
42{
43 return "EmlidSensor";
44}
45
46std::string NAV::EmlidSensor::type() const
47{
48 return typeStatic();
49}
50
52{
53 return "Data Provider";
54}
55
57{
58 if (ImGui::InputTextWithHint("SensorPort", "/dev/ttyACM0", &_sensorPort))
59 {
60 LOG_DEBUG("{}: SensorPort changed to {}", nameId(), _sensorPort);
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
85{
86 LOG_TRACE("{}: called", nameId());
87
88 if (j.contains("UartSensor"))
89 {
90 UartSensor::restore(j.at("UartSensor"));
91 }
92}
93
95{
96 return true;
97}
98
100{
101 LOG_TRACE("{}: called", nameId());
102
103 // connect to the sensor
104 try
105 {
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
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
143void 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}
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
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:574
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
OutputPin * CreateOutputPin(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.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
bool _onlyRealTime
Whether the node can run in post-processing or only real-time.
Definition Node.hpp:531
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
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.
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