24#ifndef GOBY_MIDDLEWARE_IO_LINE_BASED_SERIAL_H
25#define GOBY_MIDDLEWARE_IO_LINE_BASED_SERIAL_H
30#include <boost/asio/read_until.hpp>
31#include <boost/asio/streambuf.hpp>
32#include <boost/system/error_code.hpp>
67 const goby::middleware::Group& line_in_group,
const goby::middleware::Group& line_out_group,
73 ThreadType, use_indexed_groups>
76 ThreadType, use_indexed_groups>;
83 : Base(config,
index), eol_matcher_(
this->
cfg().end_of_line())
95 boost::asio::streambuf buffer_;
105 bool use_indexed_groups>
107 subscribe_layer, ThreadType,
108 use_indexed_groups>::async_read()
110 boost::asio::async_read_until(
111 this->mutable_serial_port(), buffer_, eol_matcher_,
112 [
this](
const boost::system::error_code& ec, std::size_t bytes_transferred)
114 if (!ec && bytes_transferred > 0)
116 std::string bytes(bytes_transferred, 0);
117 std::istream is(&buffer_);
118 is.read(&bytes[0], bytes_transferred);
119 this->handle_read_success(bytes_transferred, bytes);
124 this->handle_read_error(ec);
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
const Config & cfg() const
Reads/Writes strings from/to serial port using a line-based (typically ASCII) protocol with a defined...
SerialThreadLineBased(const goby::middleware::protobuf::SerialConfig &config, int index=-1)
Constructs the thread.
~SerialThreadLineBased() override
virtual void async_read()=0
Provides a matching function object for the boost::asio::async_read_until based on a std::regex.
Objects implementing the Goby nested middleware.
middleware::SimpleThread< Config, detail::InterProcessTag > SimpleThread
Zeromq-backed SimpleThread. Derives from middleware::SimpleThread using InterProcessTag.
The global namespace for the Goby project.