0.4.1
Loading...
Searching...
No Matches
UbloxSensor.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 "UbloxSensor.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 _sensorPort = "/dev/ttyACM0";
35
37}
38
40{
41 LOG_TRACE("{}: called", nameId());
42}
43
45{
46 return "UbloxSensor";
47}
48
49std::string NAV::UbloxSensor::type() const
50{
51 return typeStatic();
52}
53
55{
56 return "Data Provider";
57}
58
60{
61 if (ImGui::InputTextWithHint("SensorPort", "/dev/ttyACM0", &_sensorPort))
62 {
63 LOG_DEBUG("{}: SensorPort changed to {}", nameId(), _sensorPort);
66 }
67 ImGui::SameLine();
68 gui::widgets::HelpMarker("COM port where the sensor is attached to\n"
69 "- \"COM1\" (Windows format for physical and virtual (USB) serial port)\n"
70 "- \"/dev/ttyS1\" (Linux format for physical serial port)\n"
71 "- \"/dev/ttyUSB0\" (Linux format for virtual (USB) serial port)\n"
72 "- \"/dev/tty.usbserial-FTXXXXXX\" (Mac OS X format for virtual (USB) serial port)\n"
73 "- \"/dev/ttyS0\" (CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1)");
74}
75
76[[nodiscard]] json NAV::UbloxSensor::save() const
77{
78 LOG_TRACE("{}: called", nameId());
79
80 json j;
81
82 j["UartSensor"] = UartSensor::save();
83
84 return j;
85}
86
88{
89 LOG_TRACE("{}: called", nameId());
90
91 if (j.contains("UartSensor"))
92 {
93 UartSensor::restore(j.at("UartSensor"));
94 }
95}
96
98{
99 return true;
100}
101
103{
104 LOG_TRACE("{}: called", nameId());
105
106 // connect to the sensor
107 try
108 {
110
111 LOG_DEBUG("{} connected on port {} with baudrate {}", nameId(), _sensorPort, sensorBaudrate());
112 }
113 catch (...)
114 {
115 LOG_ERROR("{} could not connect", nameId());
116 return false;
117 }
118
119 _sensor->registerAsyncPacketReceivedHandler(this, asciiOrBinaryAsyncMessageReceived);
120
121 return true;
122}
123
125{
126 LOG_TRACE("{}: called", nameId());
127
128 if (!isInitialized())
129 {
130 return;
131 }
132
133 if (_sensor->isConnected())
134 {
135 try
136 {
137 _sensor->unregisterAsyncPacketReceivedHandler();
138 }
139 catch (...) // NOLINT(bugprone-empty-catch)
140 {}
141
142 _sensor->disconnect();
143 }
144}
145
146void NAV::UbloxSensor::asciiOrBinaryAsyncMessageReceived(void* userData, uart::protocol::Packet& p, [[maybe_unused]] size_t index)
147{
148 auto* ubSensor = static_cast<UbloxSensor*>(userData);
149
150 ubSensor->invokeCallbacks(OUTPUT_PORT_INDEX_UBLOX_OBS, std::make_shared<UartPacket>(p));
151}
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.
Ublox Sensor Class.
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.
void deinitialize() override
Deinitialize the node.
~UbloxSensor() override
Destructor.
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
std::string type() const override
String representation of the Class Type.
static std::string category()
String representation of the Class Category.
static constexpr size_t OUTPUT_PORT_INDEX_UBLOX_OBS
Flow (UbloxObs)
json save() const override
Saves the node into a json object.
bool initialize() override
Initialize the node.
vendor::ublox::UbloxUartSensor _sensor
Sensor Object.
void restore(const json &j) override
Restores the node from a json object.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
UbloxSensor()
Default constructor.
static void asciiOrBinaryAsyncMessageReceived(void *userData, uart::protocol::Packet &p, size_t index)
Callback handler for notifications of new asynchronous data packets received.
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