Goby3 3.2.3
2025.05.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 <boost/smart_ptr/shared_ptr.hpp> // for shared_ptr
31#include <iosfwd> // for ofstream
32#include <memory> // for shared_ptr, __shared_p...
33#include <string> // for string
34
35#include "goby/acomms/protobuf/driver_base.pb.h" // for DriverCo...
36
37namespace goby
38{
39namespace util
40{
42} // namespace util
43
44namespace acomms
45{
46namespace protobuf
47{
48class DriverConfig;
49class ModemRaw;
50class ModemTransmission;
51class ModemReport;
52} // namespace protobuf
53
59{
60 public:
62
63
67 virtual void startup(const protobuf::DriverConfig& cfg) = 0;
68
70 virtual void update_cfg(const protobuf::DriverConfig& cfg);
71
73 virtual void shutdown() = 0;
74
78 virtual void do_work() = 0;
79
81
83
84
89
91
92
96 boost::signals2::signal<void(const protobuf::ModemTransmission& message)> signal_receive;
97
101 boost::signals2::signal<void(const protobuf::ModemTransmission& message)>
103
107 boost::signals2::signal<void(protobuf::ModemTransmission* msg)> signal_data_request;
108
112 boost::signals2::signal<void(protobuf::ModemTransmission* msg_request)>
114
118 boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_incoming;
119
123 boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_outgoing;
125
128
130
131
134
136 int driver_order() { return order_; }
137
141 static std::string driver_name(const protobuf::DriverConfig& cfg);
143
144 protected:
146
147
150
152
154
155
159 void modem_write(const std::string& out);
160
165 bool modem_read(std::string* in);
166
172 void modem_start(const protobuf::DriverConfig& cfg, bool modem_connection_expected = true);
173
176
177 const std::string& glog_out_group() const { return glog_out_group_; }
178 const std::string& glog_in_group() const { return glog_in_group_; }
179
181 util::LineBasedInterface& modem() { return *modem_; }
182
184 protected:
185 static std::atomic<int> count_;
186
187 private:
188 void write_raw(const protobuf::ModemRaw& msg, bool rx);
189
190 private:
191 // represents the line based communications interface to the modem
192 std::shared_ptr<util::LineBasedInterface> modem_;
193
194 std::string glog_out_group_;
195 std::string glog_in_group_;
196 bool glog_groups_set_{false};
197
198 std::shared_ptr<std::ofstream> raw_fs_;
199 bool raw_fs_connections_made_{false};
200 int order_;
201
202 protobuf::DriverConfig cfg_;
203};
204} // namespace acomms
205} // namespace goby
206#endif
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition driver_base.h:59
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:96
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