Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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
40namespace goby
41{
42namespace 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
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
Reads/Writes strings from/to serial port using a line-based (typically ASCII) protocol with a defined...
Definition serial.h:74
basic interface class for all the derived serial (and networking mimics) line-based nodes (serial,...
Definition interface.h:62
std::string delimiter() const
Definition interface.h:107
provides a basic client for line by line text based communications over a 8N1 tty (such as an RS-232 ...
std::string local_endpoint() override
our serial port, e.g. "/dev/ttyUSB1"
std::string name() const
serial port name, e.g. "/dev/ttyS0"
const middleware::protobuf::SerialStatus & read_status()
unsigned baud() const
baud rate, e.g. 4800
void set_name(const std::string &name)
set serial port name, e.g. "/dev/ttyS0"
void set_baud(unsigned baud)
baud rate, e.g. 4800
SerialClient(std::string name="", unsigned baud=9600, const std::string &delimiter="\r\n")
create a serial client
void send_command(const middleware::protobuf::SerialCommand &command)
std::string remote_endpoint() override
who knows where the serial port goes?! (empty string)
constexpr goby::middleware::Group linebasedcomms_in
Definition interface.h:56
constexpr goby::middleware::Group linebasedcomms_out
Definition interface.h:57
The global namespace for the Goby project.