Goby3  3.1.4
2024.02.22
serial_client.h
Go to the documentation of this file.
1 // Copyright 2009-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 // Old interface - replaced for most uses by middleware/io/line_based/serial.h
26 
27 #ifndef GOBY_UTIL_LINEBASEDCOMMS_SERIAL_CLIENT_H
28 #define GOBY_UTIL_LINEBASEDCOMMS_SERIAL_CLIENT_H
29 
30 #include <atomic>
31 #include <memory>
32 #include <string> // for string, operator!=
33 #include <thread>
34 
37 
38 #include "interface.h"
39 
40 namespace goby
41 {
42 namespace util
43 {
46 {
47  public:
53  SerialClient(std::string name = "", unsigned baud = 9600,
54  const std::string& delimiter = "\r\n");
55 
56  ~SerialClient() override;
57 
59  void set_name(const std::string& name) { name_ = name; }
61  void set_baud(unsigned baud) { baud_ = baud; }
62 
64  std::string name() const { return name_; }
65 
67  unsigned baud() const { return baud_; }
68 
70  std::string local_endpoint() override { return name_; }
72  std::string remote_endpoint() override { return ""; }
73 
75  const middleware::protobuf::SerialStatus& read_status() { return status_; }
76 
77  private:
78  void do_start() override;
79  void do_close() override;
80  void do_subscribe() override;
81 
82  private:
83  std::string name_;
84  unsigned baud_;
85 
90 
91  std::atomic<bool> serial_alive_{false};
92  std::unique_ptr<std::thread> serial_thread_;
93 
95 };
96 } // namespace util
97 } // namespace goby
98 #endif
io.pb.h
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::protobuf::SerialCommand
Definition: io.pb.h:705
goby::util::SerialClient::set_name
void set_name(const std::string &name)
set serial port name, e.g. "/dev/ttyS0"
Definition: serial_client.h:59
goby::middleware::io::SerialThreadLineBased
Reads/Writes strings from/to serial port using a line-based (typically ASCII) protocol with a defined...
Definition: serial.h:71
goby::util::SerialClient::send_command
void send_command(const middleware::protobuf::SerialCommand &command)
goby::util::groups::linebasedcomms_in
constexpr goby::middleware::Group linebasedcomms_in
Definition: interface.h:56
serial.h
interface.h
goby::util::SerialClient::baud
unsigned baud() const
baud rate, e.g. 4800
Definition: serial_client.h:67
goby::util::SerialClient::name
std::string name() const
serial port name, e.g. "/dev/ttyS0"
Definition: serial_client.h:64
goby::util::LineBasedCommsThreadStub
Definition: thread_stub.h:36
goby::middleware::protobuf::SerialStatus
Definition: io.pb.h:861
goby::util::SerialClient::remote_endpoint
std::string remote_endpoint() override
who knows where the serial port goes?! (empty string)
Definition: serial_client.h:72
goby::util::LineBasedInterface::delimiter
std::string delimiter() const
Definition: interface.h:107
goby::util::SerialClient
provides a basic client for line by line text based communications over a 8N1 tty (such as an RS-232 ...
Definition: serial_client.h:45
goby::util::groups::linebasedcomms_out
constexpr goby::middleware::Group linebasedcomms_out
Definition: interface.h:57
goby::util::SerialClient::read_status
const middleware::protobuf::SerialStatus & read_status()
Definition: serial_client.h:75
goby::util::SerialClient::local_endpoint
std::string local_endpoint() override
our serial port, e.g. "/dev/ttyUSB1"
Definition: serial_client.h:70
goby::util::SerialClient::~SerialClient
~SerialClient() override
goby::util::LineBasedInterface
basic interface class for all the derived serial (and networking mimics) line-based nodes (serial,...
Definition: interface.h:61
goby::util::SerialClient::SerialClient
SerialClient(std::string name="", unsigned baud=9600, const std::string &delimiter="\r\n")
create a serial client
goby::util::SerialClient::set_baud
void set_baud(unsigned baud)
baud rate, e.g. 4800
Definition: serial_client.h:61
goby::middleware::io::PubSubLayer::INTERTHREAD
@ INTERTHREAD