Goby3  3.1.5a
2024.05.23
iridium_shore_driver.h
Go to the documentation of this file.
1 // Copyright 2015-2023:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_ACOMMS_MODEMDRIVER_IRIDIUM_SHORE_DRIVER_H
25 #define GOBY_ACOMMS_MODEMDRIVER_IRIDIUM_SHORE_DRIVER_H
26 
27 #include <cstdint> // for uint32_t
28 #include <map> // for map
29 #include <memory> // for shared_ptr
30 #include <string> // for string
31 
32 #include <boost/asio/io_service.hpp> // for io_service
33 #include <boost/bimap.hpp>
34 #include <boost/circular_buffer.hpp> // for circular_b...
35 
36 #include "goby/acomms/modemdriver/driver_base.h" // for ModemDrive...
37 #include "goby/acomms/protobuf/driver_base.pb.h" // for DriverConfig
38 #include "goby/acomms/protobuf/iridium_driver.pb.h" // for MessageTyp...
39 #include "goby/acomms/protobuf/iridium_shore_driver.pb.h" // for ShoreConfig
40 #include "goby/acomms/protobuf/modem_message.pb.h" // for ModemTrans...
41 
42 namespace goby
43 {
44 namespace acomms
45 {
46 class OnCallBase;
47 class RUDICSConnection;
48 class RUDICSServer;
49 namespace directip
50 {
51 class SBDServer;
52 } // namespace directip
53 namespace iridium
54 {
55 namespace protobuf
56 {
57 class DirectIPMOHeader;
58 class DirectIPMOPayload;
60 } // namespace protobuf
61 } // namespace iridium
62 
64 {
65  public:
67  ~IridiumShoreDriver() override;
68  void startup(const protobuf::DriverConfig& cfg) override;
69 
70  void modem_init();
71 
72  void shutdown() override;
73  void do_work() override;
74 
77 
78  private:
79  typedef unsigned ModemId;
80 
81  void receive(const protobuf::ModemTransmission& msg);
82  void send(const protobuf::ModemTransmission& msg);
83 
84  void decode_mo(iridium::protobuf::DirectIPMOPreHeader* pre_header,
86  iridium::protobuf::DirectIPMOPayload* body, const std::string& data);
87 
88  void receive_sbd_mo();
89  void receive_sbd_mo_data(const std::string& data, protobuf::ModemTransmission* modem_msg);
90 
91  void send_sbd_mt(const std::string& bytes, const std::string& imei);
92 
93  void rudics_send(const std::string& data, ModemId id);
94  void rudics_disconnect(const std::shared_ptr<RUDICSConnection>& connection);
95  void rudics_line(const std::string& line, const std::shared_ptr<RUDICSConnection>& connection);
96  void rudics_connect(const std::shared_ptr<RUDICSConnection>& connection);
97 
98  const iridium::protobuf::Config& iridium_driver_cfg() const
99  {
100  return driver_cfg_.GetExtension(iridium::protobuf::config);
101  }
102 
103  const iridium::protobuf::ShoreConfig& iridium_shore_driver_cfg() const
104  {
105  return driver_cfg_.GetExtension(iridium::protobuf::shore_config);
106  }
107 
108  // in iridium_shore_driver_sbd_directip.cpp
109  void startup_sbd_directip(const protobuf::DriverConfig& cfg);
110  void receive_sbd_mo_directip();
111  void send_sbd_mt_directip(const std::string& bytes, const std::string& imei);
112 
113  // in iridium_shore_driver_sbd_rockblock.cpp
114  void startup_sbd_rockblock(const protobuf::DriverConfig& cfg);
115  void receive_sbd_mo_rockblock();
116  void send_sbd_mt_rockblock(const std::string& bytes, const std::string& imei);
117 
118  private:
119  protobuf::DriverConfig driver_cfg_;
120 
121  protobuf::ModemTransmission rudics_mac_msg_;
122 
123  std::uint32_t next_frame_{0};
124 
125  struct RemoteNode
126  {
127  enum
128  {
129  DATA_BUFFER_CAPACITY = 30
130  };
131  RemoteNode() : data_out(DATA_BUFFER_CAPACITY) {}
132 
133  std::shared_ptr<OnCallBase> on_call;
134  boost::circular_buffer<protobuf::ModemTransmission> data_out;
135  };
136 
137  std::map<ModemId, RemoteNode> remote_;
138 
139  std::unique_ptr<boost::asio::io_service> rudics_io_;
140  std::unique_ptr<RUDICSServer> rudics_server_;
141  std::unique_ptr<boost::asio::io_service> sbd_io_;
142  std::unique_ptr<directip::SBDServer> directip_mo_sbd_server_;
143 
144  // maps remote modem to connection
145  boost::bimap<ModemId, std::shared_ptr<RUDICSConnection>> clients_;
146 
147  using IMEI = std::string;
148  std::map<ModemId, IMEI> modem_id_to_imei_;
149 
150  struct RockblockHTTPMessage
151  {
152  enum class MessageState
153  {
154  HEADER,
155  BODY,
156  COMPLETE
157  };
158  MessageState state{MessageState::HEADER};
159  std::map<std::string, std::string> header;
160  std::string body;
161  };
162 
163  std::unique_ptr<RockblockHTTPMessage> rb_msg_;
164 };
165 } // namespace acomms
166 } // namespace goby
167 #endif
goby::acomms::protobuf::DriverConfig
Definition: driver_base.pb.h:123
goby::acomms::protobuf::ModemTransmission
Definition: modem_message.pb.h:166
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::acomms::IridiumShoreDriver
Definition: iridium_shore_driver.h:63
goby::acomms::IridiumShoreDriver::do_work
void do_work() override
Allows the modem driver to do its work.
goby::acomms::IridiumShoreDriver::modem_init
void modem_init()
goby::acomms::IridiumShoreDriver::~IridiumShoreDriver
~IridiumShoreDriver() override
goby::acomms::directip::SBDServer
Definition: iridium_shore_sbd_directip.h:259
modem_message.pb.h
goby::acomms::iridium::protobuf::DirectIPMOHeader
Definition: iridium_sbd_directip.pb.h:222
goby::acomms::iridium::protobuf::ShoreConfig
Definition: iridium_shore_driver.pb.h:436
driver_base.h
goby::acomms::iridium::protobuf::config
extern ::google::protobuf::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::google::protobuf::internal::MessageTypeTraits< ::goby::acomms::iridium::protobuf::Config >, 11, false > config
Definition: iridium_driver.pb.h:1512
driver_base.pb.h
goby::acomms::IridiumShoreDriver::startup
void startup(const protobuf::DriverConfig &cfg) override
Starts the modem driver. Must be called before poll().
goby::acomms::IridiumShoreDriver::process_transmission
void process_transmission(protobuf::ModemTransmission msg)
goby::acomms::iridium::protobuf::DirectIPMOPreHeader
Definition: iridium_sbd_directip.pb.h:95
goby::acomms::iridium::protobuf::Config
Definition: iridium_driver.pb.h:327
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::IridiumShoreDriver::IridiumShoreDriver
IridiumShoreDriver()
goby::acomms::IridiumShoreDriver::shutdown
void shutdown() override
Shuts down the modem driver.
iridium_driver.pb.h
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::iridium::protobuf::DirectIPMOPayload
Definition: iridium_sbd_directip.pb.h:417
goby::acomms::iridium::protobuf::shore_config
extern ::google::protobuf::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::google::protobuf::internal::MessageTypeTraits< ::goby::acomms::iridium::protobuf::ShoreConfig >, 11, false > shore_config
Definition: iridium_shore_driver.pb.h:668
iridium_shore_driver.pb.h
goby::acomms::IridiumShoreDriver::handle_initiate_transmission
void handle_initiate_transmission(const protobuf::ModemTransmission &m) override
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...