0.3.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
udpRecv.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
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{
33class UdpRecv : public Node
34{
35 public:
39 ~UdpRecv() override;
41 UdpRecv(const UdpRecv&) = delete;
43 UdpRecv(UdpRecv&&) = delete;
45 UdpRecv& operator=(const UdpRecv&) = delete;
48
50 [[nodiscard]] static std::string typeStatic();
51
53 [[nodiscard]] std::string type() const override;
54
56 [[nodiscard]] static std::string category();
57
60 void guiConfig() override;
61
63 [[nodiscard]] json save() const override;
64
67 void restore(const json& j) override;
68
70 bool resetNode() override;
71
72 private:
73 constexpr static size_t OUTPUT_PORT_INDEX_NODE_DATA = 0;
74
76 bool initialize() override;
77
79 void deinitialize() override;
80
83
85 int _port = 4567;
86
88 static constexpr std::array<int, 2> PORT_LIMITS = { 0, 65535 };
89
91 boost::asio::io_context _io_context;
93 boost::asio::ip::udp::socket _socket;
95 boost::asio::ip::udp::endpoint _sender_endpoint;
96
98 std::thread _recvThread;
99
101 bool _running = false;
103 bool _isStartup = true;
104
106 std::chrono::steady_clock::time_point _startPoint;
107
109 constexpr static unsigned int _maxBytes = 104;
110
112 std::array<double, 13> _data{};
113};
114} // namespace NAV
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Node Class.
Position, Velocity and Attitude Storage Class.
Abstract parent class for all nodes.
Definition Node.hpp:86
UDP Client.
Definition udpRecv.hpp:34
UdpRecv()
Default constructor.
void asyncReceive()
Polls the next data.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
bool initialize() override
Initialize the node.
static constexpr std::array< int, 2 > PORT_LIMITS
Range a port can be in [0, 2^16-1].
Definition udpRecv.hpp:88
~UdpRecv() override
Destructor.
boost::asio::io_context _io_context
Asynchronous receive fct.
Definition udpRecv.hpp:91
UdpRecv(UdpRecv &&)=delete
Move constructor.
bool _isStartup
Startup handler: used in 'initialize()' to differentiate between startup and re-initialization.
Definition udpRecv.hpp:103
bool resetNode() override
Resets the node. Moves the read cursor to the start.
UdpRecv & operator=(const UdpRecv &)=delete
Copy assignment operator.
std::array< double, 13 > _data
Network data stream array.
Definition udpRecv.hpp:112
static std::string category()
String representation of the Class Category.
std::thread _recvThread
Receiver thread.
Definition udpRecv.hpp:98
bool _running
Flag that indicates the running data link.
Definition udpRecv.hpp:101
UdpRecv & operator=(UdpRecv &&)=delete
Move assignment operator.
std::chrono::steady_clock::time_point _startPoint
Time point where the first package has been received.
Definition udpRecv.hpp:106
void restore(const json &j) override
Restores the node from a json object.
static constexpr size_t OUTPUT_PORT_INDEX_NODE_DATA
Object (NodeData)
Definition udpRecv.hpp:73
UdpRecv(const UdpRecv &)=delete
Copy constructor.
json save() const override
Saves the node into a json object.
std::string type() const override
String representation of the Class Type.
boost::asio::ip::udp::socket _socket
Boost udp socket.
Definition udpRecv.hpp:93
static constexpr unsigned int _maxBytes
Network data stream maximum buffer size in [bytes].
Definition udpRecv.hpp:109
int _port
UDP port number.
Definition udpRecv.hpp:85
void deinitialize() override
Deinitialize the node.
boost::asio::ip::udp::endpoint _sender_endpoint
Boost udp endpoint.
Definition udpRecv.hpp:95