Goby v2
driver_base.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef DriverBase20091214H
24 #define DriverBase20091214H
25 
26 #include <boost/signals2.hpp>
27 #include <boost/thread.hpp>
28 
29 #include "goby/acomms/acomms_constants.h"
30 #include "goby/acomms/protobuf/driver_base.pb.h"
31 #include "goby/acomms/protobuf/modem_message.pb.h"
32 #include "goby/util/linebasedcomms.h"
33 
34 namespace goby
35 {
36 namespace util
37 {
38 class FlexOstream;
39 }
40 
41 namespace acomms
42 {
48 {
49  public:
51 
52 
56  virtual void startup(const protobuf::DriverConfig& cfg) = 0;
57 
59  virtual void update_cfg(const protobuf::DriverConfig& cfg);
60 
62  virtual void shutdown() = 0;
63 
67  virtual void do_work() = 0;
68 
70 
72 
73  virtual void handle_initiate_transmission(const protobuf::ModemTransmission& m) = 0;
78 
80 
81 
85  boost::signals2::signal<void(const protobuf::ModemTransmission& message)> signal_receive;
86 
90  boost::signals2::signal<void(const protobuf::ModemTransmission& message)>
92 
96  boost::signals2::signal<void(protobuf::ModemTransmission* msg)> signal_data_request;
97 
101  boost::signals2::signal<void(protobuf::ModemTransmission* msg_request)>
103 
107  boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_incoming;
108 
112  boost::signals2::signal<void(const protobuf::ModemRaw& msg)> signal_raw_outgoing;
114 
116  virtual ~ModemDriverBase();
117 
118  int driver_order() { return order_; }
119 
120  protected:
122 
123 
125  ModemDriverBase();
126 
128 
130 
131 
135  void modem_write(const std::string& out);
136 
141  bool modem_read(std::string* in);
142 
148  void modem_start(const protobuf::DriverConfig& cfg);
149 
151  void modem_close();
152 
153  const std::string& glog_out_group() const { return glog_out_group_; }
154  const std::string& glog_in_group() const { return glog_in_group_; }
155 
157  util::LineBasedInterface& modem() { return *modem_; }
158 
160  protected:
161  static int count_;
162 
163  private:
164  void write_raw(const protobuf::ModemRaw& msg, bool rx);
165 
166  private:
167  // represents the line based communications interface to the modem
168  boost::shared_ptr<util::LineBasedInterface> modem_;
169 
170  std::string glog_out_group_;
171  std::string glog_in_group_;
172 
173  boost::shared_ptr<std::ofstream> raw_fs_;
174  bool raw_fs_connections_made_;
175  int order_;
176 };
177 } // namespace acomms
178 } // namespace goby
179 #endif
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:107
boost::signals2::signal< void(const protobuf::ModemTransmission &message)> signal_transmit_result
Called when a transmission is completed.
Definition: driver_base.h:91
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:85
util::LineBasedInterface & modem()
use for direct access to the modem
Definition: driver_base.h:157
The global namespace for the Goby project.
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition: driver_base.h:47
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:112
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:96
basic interface class for all the derived serial (and networking mimics) line-based nodes (serial...
Definition: interface.h:44
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:102