Goby3  3.1.5a
2024.05.23
driver_base.h
Go to the documentation of this file.
1 // Copyright 2009-2023:
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 
37 namespace goby
38 {
39 namespace util
40 {
41 class LineBasedInterface;
42 } // namespace util
43 
44 namespace acomms
45 {
46 namespace protobuf
47 {
48 class DriverConfig;
49 class ModemRaw;
50 class ModemTransmission;
51 class 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 
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 
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 
127  virtual ~ModemDriverBase();
128 
130 
131 
133  virtual void report(protobuf::ModemReport* report);
134 
136  int driver_order() { return order_; }
137 
141  static std::string driver_name(const protobuf::DriverConfig& cfg);
143 
144  protected:
146 
147 
149  ModemDriverBase();
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 
175  void modem_close();
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
goby::acomms::protobuf::DriverConfig
Definition: driver_base.pb.h:123
goby::acomms::protobuf::ModemTransmission
Definition: modem_message.pb.h:166
goby::acomms::ModemDriverBase::signal_raw_incoming
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...
Definition: driver_base.h:118
goby::acomms::ModemDriverBase::report
virtual void report(protobuf::ModemReport *report)
Returns report including modem availability and signal quality (if known)
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::acomms::ModemDriverBase::glog_out_group
const std::string & glog_out_group() const
Definition: driver_base.h:177
goby::acomms::ModemDriverBase::signal_raw_outgoing
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...
Definition: driver_base.h:123
goby::acomms::ModemDriverBase::signal_data_request
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...
Definition: driver_base.h:107
goby::acomms::protobuf::ModemReport
Definition: modem_message.pb.h:673
goby::acomms::ModemDriverBase::modem_write
void modem_write(const std::string &out)
write a line to the serial port.
goby::acomms::ModemDriverBase::signal_modify_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 ...
Definition: driver_base.h:113
detail::void
j template void())
Definition: json.hpp:4822
goby::acomms::ModemDriverBase::ModemDriverBase
ModemDriverBase()
Constructor.
goby::acomms::ModemDriverBase::modem
util::LineBasedInterface & modem()
use for direct access to the modem
Definition: driver_base.h:181
goby::acomms::ModemDriverBase::signal_receive
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
goby::acomms::ModemDriverBase::shutdown
virtual void shutdown()=0
Shuts down the modem driver.
goby::acomms::ModemDriverBase::signal_transmit_result
boost::signals2::signal< void(const protobuf::ModemTransmission &message)> signal_transmit_result
Called when a transmission is completed.
Definition: driver_base.h:102
goby::acomms::ModemDriverBase::startup
virtual void startup(const protobuf::DriverConfig &cfg)=0
Starts the modem driver. Must be called before poll().
driver_base.pb.h
goby::acomms::ModemDriverBase::modem_read
bool modem_read(std::string *in)
read a line from the serial port, including end-of-line character(s)
goby::acomms::ModemDriverBase::update_cfg
virtual void update_cfg(const protobuf::DriverConfig &cfg)
Update configuration while running (not required to be implemented)
goby::acomms::ModemDriverBase::~ModemDriverBase
virtual ~ModemDriverBase()
Public Destructor.
goby::acomms::ModemDriverBase::count_
static std::atomic< int > count_
Definition: driver_base.h:185
goby::acomms::ModemDriverBase::glog_in_group
const std::string & glog_in_group() const
Definition: driver_base.h:178
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::acomms::ModemDriverBase::modem_start
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...
goby::acomms::ModemDriverBase::modem_close
void modem_close()
closes the serial port. Use modem_start to reopen the port.
goby::acomms::ModemDriverBase::do_work
virtual void do_work()=0
Allows the modem driver to do its work.
goby::acomms::protobuf::ModemRaw
Definition: modem_message.pb.h:533
goby::acomms::ModemDriverBase::driver_order
int driver_order()
Integer for the order in which this driver was started (first driver started is 1,...
Definition: driver_base.h:136
goby::acomms::ModemDriverBase
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition: driver_base.h:58
goby::acomms::ModemDriverBase::handle_initiate_transmission
virtual void handle_initiate_transmission(const protobuf::ModemTransmission &m)=0
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
goby::middleware::acomms::groups::rx
constexpr Group rx
Definition: groups.h:45
goby::acomms::ModemDriverBase::driver_name
static std::string driver_name(const protobuf::DriverConfig &cfg)
Unique driver name (e.g. UDP_MULTICAST::1 or my_driver_name::2)
goby::util::LineBasedInterface
basic interface class for all the derived serial (and networking mimics) line-based nodes (serial,...
Definition: interface.h:61