Goby3 3.4.0
2026.04.13
Loading...
Searching...
No Matches
serial.h
Go to the documentation of this file.
1// Copyright 2019-2026:
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_SERIAL_H
25#define GOBY_MIDDLEWARE_IO_MAVLINK_SERIAL_H
26
27#include <iosfwd> // for size_t
28
29#include <boost/asio/buffer.hpp> // for buffer
30#include <boost/asio/completion_condition.hpp> // for transfer_at_...
31#include <boost/asio/read.hpp> // for async_read
32#include <boost/system/error_code.hpp> // for error_code
33
34#include "goby/middleware/io/detail/io_interface.h" // for PubSubLayer
35#include "goby/middleware/io/detail/serial_interface.h" // for SerialThread
36#include "goby/middleware/io/mavlink/common.h" // for IOThreadMAVLink
38
39namespace goby
40{
41namespace middleware
42{
43class Group;
44}
45} // namespace goby
46namespace goby
47{
48namespace middleware
49{
50namespace protobuf
51{
52class SerialConfig;
53}
54} // namespace middleware
55} // namespace goby
56
57namespace goby
58{
59namespace middleware
60{
61namespace io
62{
63template <const goby::middleware::Group& line_in_group,
64 const goby::middleware::Group& line_out_group, PubSubLayer publish_layer,
65 PubSubLayer subscribe_layer, template <class> class ThreadType>
67 line_in_group, line_out_group, publish_layer, subscribe_layer,
70
74template <const goby::middleware::Group& line_in_group,
75 const goby::middleware::Group& line_out_group,
77 PubSubLayer subscribe_layer = PubSubLayer::INTERTHREAD,
78 template <class> class ThreadType = goby::zeromq::SimpleThread>
80 : public SerialThreadMAVLinkBase<line_in_group, line_out_group, publish_layer, subscribe_layer,
81 ThreadType>
82{
83 public:
85 : SerialThreadMAVLinkBase<line_in_group, line_out_group, publish_layer, subscribe_layer,
86 ThreadType>(config)
87 {
88 }
89
91
92 private:
93 void async_read() override;
94};
95} // namespace io
96} // namespace middleware
97} // namespace goby
98
99template <const goby::middleware::Group& line_in_group,
100 const goby::middleware::Group& line_out_group,
102 goby::middleware::io::PubSubLayer subscribe_layer, template <class> class ThreadType>
103void goby::middleware::io::SerialThreadMAVLink<line_in_group, line_out_group, publish_layer,
104 subscribe_layer, ThreadType>::async_read()
105{
106 boost::asio::async_read(
107 this->mutable_serial_port(), boost::asio::buffer(this->buffer()),
108 boost::asio::transfer_at_least(1),
109 [this](const boost::system::error_code& ec, std::size_t bytes_transferred)
110 {
111 if (!ec && bytes_transferred > 0)
112 {
113 this->try_parse(bytes_transferred);
114 this->async_read();
115 }
116 else
117 {
118 this->handle_read_error(ec);
119 }
120 });
121}
122
123#endif
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition group.h:60
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
The global namespace for the Goby project.