Goby3  3.1.5a
2024.05.23
udp.h
Go to the documentation of this file.
1 // Copyright 2019-2021:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_MIDDLEWARE_IO_MAVLINK_UDP_H
25 #define GOBY_MIDDLEWARE_IO_MAVLINK_UDP_H
26 
27 #include <iosfwd> // for size_t
28 
29 #include <boost/asio/buffer.hpp> // for buffer
30 #include <boost/asio/ip/udp.hpp> // for udp, udp::endpoint
31 #include <boost/system/error_code.hpp> // for error_code
32 
33 #include "goby/middleware/io/detail/io_interface.h" // for PubSubLayer, Pub...
34 #include "goby/middleware/io/mavlink/common.h" // for IOThreadMAVLink
35 #include "goby/middleware/io/udp_point_to_point.h" // for UDPPointToPointT...
36 
37 namespace goby
38 {
39 namespace middleware
40 {
41 class Group;
42 }
43 } // namespace goby
44 namespace goby
45 {
46 namespace middleware
47 {
48 namespace protobuf
49 {
50 class UDPPointToPointConfig;
51 }
52 } // namespace middleware
53 } // namespace goby
54 
55 namespace goby
56 {
57 namespace middleware
58 {
59 namespace io
60 {
61 template <const goby::middleware::Group& line_in_group,
62  const goby::middleware::Group& line_out_group, PubSubLayer publish_layer,
63  PubSubLayer subscribe_layer, template <class> class ThreadType>
65  IOThreadMAVLink<line_in_group, line_out_group, publish_layer, subscribe_layer,
66  UDPPointToPointThread<line_in_group, line_out_group, publish_layer,
67  subscribe_layer, ThreadType>,
69 
73 template <const goby::middleware::Group& line_in_group,
74  const goby::middleware::Group& line_out_group,
75  PubSubLayer publish_layer = PubSubLayer::INTERPROCESS,
76  PubSubLayer subscribe_layer = PubSubLayer::INTERTHREAD,
77  template <class> class ThreadType = goby::middleware::SimpleThread>
78 class UDPThreadMAVLink : public UDPThreadMAVLinkBase<line_in_group, line_out_group, publish_layer,
79  subscribe_layer, ThreadType>
80 {
81  public:
83  : UDPThreadMAVLinkBase<line_in_group, line_out_group, publish_layer, subscribe_layer,
84  ThreadType>(config)
85  {
86  }
87 
89 
90  private:
91  void async_read() override;
92 
93  private:
94  boost::asio::ip::udp::endpoint sender_endpoint_;
95 };
96 } // namespace io
97 } // namespace middleware
98 } // namespace goby
99 
100 template <const goby::middleware::Group& line_in_group,
101  const goby::middleware::Group& line_out_group,
102  goby::middleware::io::PubSubLayer publish_layer,
103  goby::middleware::io::PubSubLayer subscribe_layer, template <class> class ThreadType>
104 void goby::middleware::io::UDPThreadMAVLink<line_in_group, line_out_group, publish_layer,
105  subscribe_layer, ThreadType>::async_read()
106 {
107  this->mutable_socket().async_receive_from(
108  boost::asio::buffer(this->buffer()), sender_endpoint_,
109  [this](const boost::system::error_code& ec, std::size_t bytes_transferred) {
110  if (!ec && bytes_transferred > 0)
111  {
112  this->try_parse(bytes_transferred);
113  this->async_read();
114  }
115  else
116  {
117  this->handle_read_error(ec);
118  }
119  });
120 }
121 
122 #endif
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::acomms::abc::protobuf::config
extern ::google::protobuf::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::google::protobuf::internal::MessageTypeTraits< ::goby::acomms::abc::protobuf::Config >, 11, false > config
Definition: abc_driver.pb.h:203
udp_point_to_point.h
goby::middleware::SimpleThread
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
Definition: simple_thread.h:43
goby::middleware::io::PubSubLayer
PubSubLayer
Definition: io_transporters.h:38
goby::middleware::io::UDPThreadMAVLinkBase
IOThreadMAVLink< line_in_group, line_out_group, publish_layer, subscribe_layer, UDPPointToPointThread< line_in_group, line_out_group, publish_layer, subscribe_layer, ThreadType >, goby::middleware::protobuf::UDPPointToPointConfig > UDPThreadMAVLinkBase
Definition: udp.h:68
goby::middleware::protobuf::UDPPointToPointConfig
Definition: udp_config.pb.h:224
goby::middleware::Group
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition: group.h:59
io_interface.h
goby::middleware::io::PubSubLayer::INTERPROCESS
@ INTERPROCESS
goby::middleware::io::PubSubLayer::INTERTHREAD
@ INTERTHREAD