Goby3 3.4.0
2026.04.13
Loading...
Searching...
No Matches
driver_base.h
Go to the documentation of this file.
1// Copyright 2009-2025:
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#ifndef GOBY_ACOMMS_MODEMDRIVER_DRIVER_BASE_H
26#define GOBY_ACOMMS_MODEMDRIVER_DRIVER_BASE_H
27
28#include <atomic> // for atomic
29#include <boost/signals2/signal.hpp> // for signal
30#include <iosfwd> // for ofstream
31#include <memory> // for shared_ptr, __shared_p...
32#include <string> // for string
33
34#include "goby/acomms/protobuf/driver_base.pb.h" // for DriverCo...
35
36namespace goby
37{
38namespace util
39{
41} // namespace util
42
43namespace acomms
44{
45namespace protobuf
46{
47class DriverConfig;
48class ModemRaw;
49class ModemTransmission;
50class ModemReport;
51} // namespace protobuf
52
58{
59 public:
61
62
66 virtual void startup(const protobuf::DriverConfig& cfg) = 0;
67
69 virtual void update_cfg(const protobuf::DriverConfig& cfg);
70
72 virtual void shutdown() = 0;
73
77 virtual void do_work() = 0;
78
80
82
83
88
90
91
95 boost::signals2::signal<void(const protobuf::ModemTransmission& message)> signal_receive;
96
100 boost::signals2::signal<void(const protobuf::ModemTransmission& message)>
102
106 boost::signals2::signal<void(protobuf::ModemTransmission* msg)> signal_data_request;
107
111 boost::signals2::signal<void(protobuf::ModemTransmission* msg_request)>
113
117 boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_incoming;
118
122 boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_outgoing;
124
127
129
130
133
135 int driver_order() { return order_; }
136
140 static std::string driver_name(const protobuf::DriverConfig& cfg);
142
143 protected:
145
146
149
151
153
154
158 void modem_write(const std::string& out);
159
164 bool modem_read(std::string* in);
165
171 void modem_start(const protobuf::DriverConfig& cfg, bool modem_connection_expected = true);
172
175
176 const std::string& glog_out_group() const { return glog_out_group_; }
177 const std::string& glog_in_group() const { return glog_in_group_; }
178
180 util::LineBasedInterface& modem() { return *modem_; }
181
183 protected:
184 static std::atomic<int> count_;
185
186 private:
187 void write_raw(const protobuf::ModemRaw& msg, bool rx);
188
189 private:
190 // represents the line based communications interface to the modem
191 std::shared_ptr<util::LineBasedInterface> modem_;
192
193 std::string glog_out_group_;
194 std::string glog_in_group_;
195 bool glog_groups_set_{false};
196
197 std::shared_ptr<std::ofstream> raw_fs_;
198 bool raw_fs_connections_made_{false};
199 int order_;
200
201 protobuf::DriverConfig cfg_;
202};
203} // namespace acomms
204} // namespace goby
205#endif
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition driver_base.h:58
static std::string driver_name(const protobuf::DriverConfig &cfg)
Unique driver name (e.g. UDP_MULTICAST::1 or my_driver_name::2)
static std::atomic< int > count_
boost::signals2::signal< void(const protobuf::ModemTransmission &message)> signal_transmit_result
Called when a transmission is completed.
void modem_write(const std::string &out)
write a line to the serial port.
void modem_start(const protobuf::DriverConfig &cfg, bool modem_connection_expected=true)
start the physical connection to the modem (serial port, TCP, etc.). must be called before ModemDrive...
virtual void report(protobuf::ModemReport *report)
Returns report including modem availability and signal quality (if known)
virtual void shutdown()=0
Shuts down the modem driver.
virtual ~ModemDriverBase()
Public Destructor.
boost::signals2::signal< void(const protobuf::ModemRaw &msg)> signal_raw_incoming
Called after any message is received from the modem by the driver. Used by the MACManager for auto-di...
boost::signals2::signal< void(protobuf::ModemTransmission *msg)> signal_data_request
Called when the modem or modem driver needs data to send. The returned data should be stored in Modem...
virtual void startup(const protobuf::DriverConfig &cfg)=0
Starts the modem driver. Must be called before poll().
const std::string & glog_out_group() const
bool modem_read(std::string *in)
read a line from the serial port, including end-of-line character(s)
boost::signals2::signal< void(const protobuf::ModemTransmission &message)> signal_receive
Called when a binary data transmission is received from the modem.
Definition driver_base.h:95
virtual void do_work()=0
Allows the modem driver to do its work.
const std::string & glog_in_group() const
util::LineBasedInterface & modem()
use for direct access to the modem
void modem_close()
closes the serial port. Use modem_start to reopen the port.
virtual void update_cfg(const protobuf::DriverConfig &cfg)
Update configuration while running (not required to be implemented)
virtual void handle_initiate_transmission(const protobuf::ModemTransmission &m)=0
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
boost::signals2::signal< void(protobuf::ModemTransmission *msg_request)> signal_modify_transmission
Called before the modem driver begins processing a transmission. This allows a third party to modify ...
int driver_order()
Integer for the order in which this driver was started (first driver started is 1,...
boost::signals2::signal< void(const protobuf::ModemRaw &msg)> signal_raw_outgoing
Called after any message is sent from the driver to the modem. Useful for higher level analysis and d...
basic interface class for all the derived serial (and networking mimics) line-based nodes (serial,...
Definition interface.h:62
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg