0.4.1
Loading...
Searching...
No Matches
udpSend.hpp
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/// @file udpSend.hpp
10/// @brief Asynchronous data link - sender node
11/// @author M. Maier (marcel.maier@ins.uni-stuttgart.de)
12/// @date 2023-07-19
13
14#pragma once
15
16#ifdef _WIN32
17 // Set the proper SDK version before including boost/Asio
18 #include <SDKDDKVer.h>
19 // Note boost/ASIO includes Windows.h.
20 #include <boost/asio.hpp>
21#else // _WIN32
22 #include <boost/asio.hpp>
23#endif //_WIN32
24
26
28#include <string>
29
30namespace NAV
31{
32/// UDP Client
33class UdpSend : public Node
34{
35 public:
36 /// @brief Default constructor
37 UdpSend();
38 /// @brief Destructor
39 ~UdpSend() override;
40 /// @brief Copy constructor
41 UdpSend(const UdpSend&) = delete;
42 /// @brief Move constructor
43 UdpSend(UdpSend&&) = delete;
44 /// @brief Copy assignment operator
45 UdpSend& operator=(const UdpSend&) = delete;
46 /// @brief Move assignment operator
48
49 /// @brief String representation of the Class Type
50 [[nodiscard]] static std::string typeStatic();
51
52 /// @brief String representation of the Class Type
53 [[nodiscard]] std::string type() const override;
54
55 /// @brief String representation of the Class Category
56 [[nodiscard]] static std::string category();
57
58 /// @brief ImGui config window which is shown on double click
59 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
60 void guiConfig() override;
61
62 /// @brief Saves the node into a json object
63 [[nodiscard]] json save() const override;
64
65 /// @brief Restores the node from a json object
66 /// @param[in] j Json object with the node state
67 void restore(const json& j) override;
68
69 /// @brief Resets the node. Moves the read cursor to the start
70 bool resetNode() override;
71
72 private:
73 constexpr static size_t INPUT_PORT_INDEX_NODE_DATA = 0; ///< @brief Object (NodeData)
74
75 /// @brief Initialize the node
76 bool initialize() override;
77
78 /// @brief Deinitialize the node
79 void deinitialize() override;
80
81 /// @brief Callback when receiving data on a port
82 /// @param[in] queue Queue with all the received data messages
83 /// @param[in] pinIdx Index of the pin the data is received on
84 void receivePosVelAtt(InputPin::NodeDataQueue& queue, size_t pinIdx);
85
86 /// IPv4 address
87 std::array<int, 4> _ip{};
88
89 /// UDP port number
90 int _port = 4567;
91
92 /// Range an IPv4 address can be in [0, 2^8-1]
93 static constexpr std::array<int, 2> IP_LIMITS = { 0, 255 };
94 /// Range a port can be in [0, 2^16-1]
95 static constexpr std::array<int, 2> PORT_LIMITS = { 0, 65535 };
96
97 /// Asynchronous receive fct
98 boost::asio::io_context _io_context;
99 /// Boost udp socket
100 boost::asio::ip::udp::socket _socket;
101 /// Boost udp resolver
102 boost::asio::ip::udp::resolver _resolver;
103 /// Boost udp endpoint
104 boost::asio::ip::udp::resolver::results_type _endpoints;
105};
106} // namespace NAV
nlohmann::json json
json namespace
Node Class.
Position, Velocity and Attitude Storage Class.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
Node(std::string name)
Constructor.
Definition Node.cpp:30
boost::asio::ip::udp::resolver::results_type _endpoints
Boost udp endpoint.
Definition udpSend.hpp:104
UdpSend & operator=(UdpSend &&)=delete
Move assignment operator.
static constexpr size_t INPUT_PORT_INDEX_NODE_DATA
Object (NodeData)
Definition udpSend.hpp:73
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
UdpSend(UdpSend &&)=delete
Move constructor.
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
UdpSend(const UdpSend &)=delete
Copy constructor.
UdpSend & operator=(const UdpSend &)=delete
Copy assignment operator.
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