JaiaBot  1.19.0
JaiaBot micro-AUV software
xbee_driver.h
Go to the documentation of this file.
1 // Copyright 2011-2021:
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_UDP_DRIVER_H
26 #define GOBY_ACOMMS_MODEMDRIVER_UDP_DRIVER_H
27 
28 #include "xbee.h"
29 
30 #include <array> // for array
31 #include <cstddef> // for size_t
32 #include <cstdint> // for uint32_t
33 #include <map> // for multimap
34 #include <memory> // for unique_ptr
35 #include <set> // for set
36 
37 #include "goby/acomms/modemdriver/driver_base.h" // for ModemDriverBase
38 #include "goby/acomms/protobuf/driver_base.pb.h" // for DriverConfig
39 #include "goby/time/steady_clock.h" // for SteadyClock
40 
41 #include "jaiabot/messages/modem_message_extensions.pb.h" // For extensions to ModemTransmission
42 #include "jaiabot/messages/xbee_extensions.pb.h" // For our custom config
43 
44 extern "C"
45 {
46  const char* goby_driver_name();
47  goby::acomms::ModemDriverBase* goby_make_driver();
48 }
49 
50 namespace boost
51 {
52 namespace system
53 {
54 class error_code;
55 } // namespace system
56 } // namespace boost
57 
58 namespace goby
59 {
60 namespace acomms
61 {
62 namespace protobuf
63 {
64 class ModemTransmission;
65 } // namespace protobuf
66 } // namespace acomms
67 } // namespace goby
68 
69 namespace jaiabot
70 {
71 namespace comms
72 {
73 class XBeeDriver : public goby::acomms::ModemDriverBase
74 {
75  public:
76  XBeeDriver();
77  ~XBeeDriver() override;
78 
79  void startup(const goby::acomms::protobuf::DriverConfig& cfg) override;
80  void shutdown() override;
81  void do_work() override;
82  void handle_initiate_transmission(const goby::acomms::protobuf::ModemTransmission& m) override;
83 
84  private:
85  void start_send(const goby::acomms::protobuf::ModemTransmission& msg);
86  void send_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
87  void start_receive();
88  void receive_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
89  void receive_message(const goby::acomms::protobuf::ModemTransmission& m);
90 
91  bool parse_modem_message(std::string in, goby::acomms::protobuf::ModemTransmission* out);
92  void serialize_modem_message(std::string* out,
93  const goby::acomms::protobuf::ModemTransmission& in);
94 
95  const xbee::protobuf::Config& config_extension()
96  {
97  return driver_cfg_.GetExtension(xbee::protobuf::config);
98  }
99 
100  void update_active_hub(int hub_id, goby::acomms::protobuf::ModemTransmission* out);
101  void set_active_hub_peer(int hub_id);
102 
103  bool read_hub_info_file(jaiabot::protobuf::HubInfo& hub_info);
104  bool write_hub_info_file(const jaiabot::protobuf::HubInfo& hub_info);
105 
106  private:
107  goby::acomms::protobuf::DriverConfig driver_cfg_;
108 
109  XBeeDevice device_;
110 
111  // ids we are providing acks for, normally just our modem_id()
112  std::set<unsigned> application_ack_ids_;
113 
114  std::uint32_t next_frame_{0};
115  bool test_comms_{false};
116  std::map<int32_t, goby::time::SteadyClock::time_point> send_time_{};
117  std::size_t number_of_bytes_to_send_{0};
118 
119  bool have_active_hub_{false};
120  int active_hub_id_{-1};
121 
122  // 1
123  int hub_xbee_base_modem_id_{-1};
124 
125  // 1 + number of modems in link*link
126  int hub_xbee_modem_id_{-1};
127 };
128 } // namespace comms
129 } // namespace jaiabot
130 #endif
xbee_extensions.pb.h
goby_make_driver
goby::acomms::ModemDriverBase * goby_make_driver()
jaiabot::comms::XBeeDriver::shutdown
void shutdown() override
jaiabot::comms::XBeeDriver::XBeeDriver
XBeeDriver()
modem_message_extensions.pb.h
goby
Definition: udp_driver.h:59
jaiabot::protobuf::HubInfo
Definition: modem_message_extensions.pb.h:74
jaiabot::comms::XBeeDevice
Definition: xbee.h:83
jaiabot::comms::XBeeDriver::do_work
void do_work() override
xbee.h
boost
Definition: udp_driver.h:51
xbee::protobuf::Config
Definition: xbee_extensions.pb.h:74
xbee::protobuf::config
extern ::google::protobuf::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::google::protobuf::internal::MessageTypeTraits< ::xbee::protobuf::Config >, 11, false > config
Definition: xbee_extensions.pb.h:388
jaiabot::comms::XBeeDriver::startup
void startup(const goby::acomms::protobuf::DriverConfig &cfg) override
jaiabot::comms::XBeeDriver
Definition: xbee_driver.h:73
jaiabot
Definition: config.pb.h:56
jaia::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::jaia::MessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:796
goby_driver_name
const char * goby_driver_name()
jaiabot::comms::XBeeDriver::~XBeeDriver
~XBeeDriver() override
jaiabot::comms::XBeeDriver::handle_initiate_transmission
void handle_initiate_transmission(const goby::acomms::protobuf::ModemTransmission &m) override