0.4.1
Loading...
Searching...
No Matches
udpSend.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 "udpSend.hpp"
10
12namespace nm = NAV::NodeManager;
14
18
19#include "util/Logger.hpp"
20
22 : Node(typeStatic()), _socket(_io_context, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)), _resolver(_io_context)
23{
24 LOG_TRACE("{}: called", name);
25
26 _hasConfig = true;
27 _guiConfigDefaultWindowSize = { 202, 96 };
28
30}
31
33{
34 LOG_TRACE("{}: called", nameId());
35}
36
38{
39 return "UdpSend";
40}
41
42std::string NAV::UdpSend::type() const
43{
44 return typeStatic();
45}
46
48{
49 return "Data Link";
50}
51
53{
54 ImGui::SetNextItemWidth(150 * gui::NodeEditorApplication::windowFontRatio());
55 if (ImGui::InputInt4L(fmt::format("IPv4##{}", size_t(id)).c_str(), _ip.data(), IP_LIMITS[0], IP_LIMITS[1]))
56 {
58 }
59 ImGui::SetNextItemWidth(150 * gui::NodeEditorApplication::windowFontRatio());
60 if (ImGui::InputIntL(fmt::format("Port##{}", size_t(id)).c_str(), &_port, PORT_LIMITS[0], PORT_LIMITS[1]))
61 {
63 }
64}
65
67{
68 return true;
69}
70
72{
73 LOG_TRACE("{}: called", nameId());
74
75 json j;
76
77 j["ip"] = _ip;
78 j["port"] = _port;
79
80 return j;
81}
82
84{
85 LOG_TRACE("{}: called", nameId());
86 if (j.contains("ip"))
87 {
88 j.at("ip").get_to(_ip);
89 }
90 if (j.contains("port"))
91 {
92 j.at("port").get_to(_port);
93 }
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
100 std::string ipString{};
101 for (size_t i = 0; i < 4; i++)
102 {
103 ipString.append(std::to_string(_ip.at(i)));
104 i < 3 ? ipString.append(".") : ipString.append("");
105 }
106
107 _endpoints = _resolver.resolve(boost::asio::ip::udp::v4(), ipString, std::to_string(_port));
108
109 return true;
110}
111
113{
114 _io_context.stop();
115
116 LOG_TRACE("{}: called", nameId());
117}
118
120{
121 auto posVelAtt = std::make_shared<PosVelAtt>(*std::static_pointer_cast<const PosVelAtt>(queue.extract_front()));
122
123 Eigen::Vector3d posLLA = posVelAtt->lla_position();
124 Eigen::Vector3d vel_n = posVelAtt->n_velocity();
125 Eigen::Vector4d n_Quat_b = { posVelAtt->n_Quat_b().x(), posVelAtt->n_Quat_b().y(), posVelAtt->n_Quat_b().z(), posVelAtt->n_Quat_b().w() };
126 auto timeStamp = posVelAtt->insTime.toGPSweekTow();
127 auto gpsC = timeStamp.gpsCycle;
128 auto gpsW = timeStamp.gpsWeek;
129 auto gpsT = timeStamp.tow;
130
131 std::vector<double> udp_posVelAtt{ posLLA(0), posLLA(1), posLLA(2), vel_n(0), vel_n(1), vel_n(2), n_Quat_b(0), n_Quat_b(1), n_Quat_b(2), n_Quat_b(3), static_cast<double>(gpsC), static_cast<double>(gpsW), static_cast<double>(gpsT) };
132
133 _socket.send_to(boost::asio::buffer(udp_posVelAtt), *_endpoints.begin());
134}
Save/Load the Nodes.
nlohmann::json json
json namespace
Text Help Marker (?) with Tooltip.
Utility class for logging to console and file.
#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.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
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 _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
static std::string type()
Returns the type of the data class.
Definition PosVelAtt.hpp:29
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
boost::asio::ip::udp::resolver::results_type _endpoints
Boost udp endpoint.
Definition udpSend.hpp:104
bool initialize() override
Initialize the node.
Definition udpSend.cpp:96
UdpSend()
Default constructor.
Definition udpSend.cpp:21
static constexpr std::array< int, 2 > IP_LIMITS
Range an IPv4 address can be in [0, 2^8-1].
Definition udpSend.hpp:93
boost::asio::ip::udp::resolver _resolver
Boost udp resolver.
Definition udpSend.hpp:102
bool resetNode() override
Resets the node. Moves the read cursor to the start.
Definition udpSend.cpp:66
void deinitialize() override
Deinitialize the node.
Definition udpSend.cpp:112
static std::string category()
String representation of the Class Category.
Definition udpSend.cpp:47
std::string type() const override
String representation of the Class Type.
Definition udpSend.cpp:42
boost::asio::io_context _io_context
Asynchronous receive fct.
Definition udpSend.hpp:98
void restore(const json &j) override
Restores the node from a json object.
Definition udpSend.cpp:83
void guiConfig() override
ImGui config window which is shown on double click.
Definition udpSend.cpp:52
static std::string typeStatic()
String representation of the Class Type.
Definition udpSend.cpp:37
static constexpr std::array< int, 2 > PORT_LIMITS
Range a port can be in [0, 2^16-1].
Definition udpSend.hpp:95
void receivePosVelAtt(InputPin::NodeDataQueue &queue, size_t pinIdx)
Callback when receiving data on a port.
Definition udpSend.cpp:119
int _port
UDP port number.
Definition udpSend.hpp:90
boost::asio::ip::udp::socket _socket
Boost udp socket.
Definition udpSend.hpp:100
std::array< int, 4 > _ip
IPv4 address.
Definition udpSend.hpp:87
json save() const override
Saves the node into a json object.
Definition udpSend.cpp:71
~UdpSend() override
Destructor.
Definition udpSend.cpp:32
static float windowFontRatio()
Ratio to multiply for GUI window elements.
ImGui extensions.
bool InputIntL(const char *label, int *v, int v_min, int v_max, int step, int step_fast, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for 'int'.
Definition imgui_ex.cpp:242
bool InputInt4L(const char *label, int v[4], int v_min, int v_max, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for an array of 'int[4]'.
Definition imgui_ex.cpp:280
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52
Asynchronous data link - sender node.