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_COBS_SERIAL_H
25#define GOBY_MIDDLEWARE_IO_COBS_SERIAL_H
26
27#include <istream> // for istream, bas...
28#include <string> // for string
29
30#include <boost/asio/read_until.hpp> // for async_read_u...
31#include <boost/asio/streambuf.hpp> // for streambuf
32#include <boost/system/error_code.hpp> // for error_code
33
35#include "goby/middleware/io/detail/io_interface.h" // for PubSubLayer
36#include "goby/middleware/io/detail/serial_interface.h" // for SerialThread
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{
66template <const goby::middleware::Group& line_in_group,
67 const goby::middleware::Group& line_out_group,
69 PubSubLayer subscribe_layer = PubSubLayer::INTERTHREAD,
70 template <class> class ThreadType = goby::zeromq::SimpleThread,
71 bool use_indexed_groups = false>
73 : public detail::SerialThread<line_in_group, line_out_group, publish_layer, subscribe_layer,
74 ThreadType, use_indexed_groups>
75{
76 using Base = detail::SerialThread<line_in_group, line_out_group, publish_layer, subscribe_layer,
77 ThreadType, use_indexed_groups>;
78
79 public:
84 : Base(config, index)
85 {
86 }
87
89
90 template <class Thread>
91 friend void cobs_async_write(Thread* this_thread,
92 std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg);
93
94 template <class Thread, class ThreadBase>
95 friend void cobs_async_read(Thread* this_thread, std::shared_ptr<ThreadBase> self);
96
97 private:
98 void async_read() override { cobs_async_read(this); }
99
100 void async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg) override
101 {
102 cobs_async_write(this, io_msg);
103 }
104
105 private:
106 boost::asio::streambuf buffer_;
107};
108} // namespace io
109} // namespace middleware
110} // namespace goby
111
112#endif
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition group.h:60
Represents a thread of execution within the Goby middleware, interleaving periodic events (loop()) wi...
Definition thread.h:61
Reads/Writes strings from/to serial port using a line-based (typically ASCII) protocol with a defined...
Definition serial.h:75
SerialThreadCOBS(const goby::middleware::protobuf::SerialConfig &config, int index=-1)
Constructs the thread.
Definition serial.h:83
friend void cobs_async_write(Thread *this_thread, std::shared_ptr< const goby::middleware::protobuf::IOData > io_msg)
Definition common.h:44
friend void cobs_async_read(Thread *this_thread, std::shared_ptr< ThreadBase > self)
Definition common.h:90
middleware::SimpleThread< Config, detail::InterProcessTag > SimpleThread
Zeromq-backed SimpleThread. Derives from middleware::SimpleThread using InterProcessTag.
The global namespace for the Goby project.