JaiaBot 1.10.0+14+g8dbf2589
JaiaBot micro-AUV software
 
Loading...
Searching...
No Matches
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
44extern "C"
45{
46 const char* goby_driver_name();
47 goby::acomms::ModemDriverBase* goby_make_driver();
48}
49
50namespace boost
51{
52namespace system
53{
54class error_code;
55} // namespace system
56} // namespace boost
57
58namespace goby
59{
60namespace acomms
61{
62namespace protobuf
63{
64class ModemTransmission;
65} // namespace protobuf
66} // namespace acomms
67} // namespace goby
68
69namespace jaiabot
70{
71namespace comms
72{
73class XBeeDriver : public goby::acomms::ModemDriverBase
74{
75 public:
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 // maps hub_id to Peer struct
123 std::map<int, xbee::protobuf::Peer> hub_peers_;
124};
125} // namespace comms
126} // namespace jaiabot
127#endif
void handle_initiate_transmission(const goby::acomms::protobuf::ModemTransmission &m) override
void shutdown() override
void startup(const goby::acomms::protobuf::DriverConfig &cfg) override
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::xbee::protobuf::Config >, 11, false > config
const char * goby_driver_name()
goby::acomms::ModemDriverBase * goby_make_driver()