JaiaBot 2.1.1
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/xbee_extensions.pb.h" // For our custom config
42
43extern "C"
44{
45 const char* goby_driver_name();
46 goby::acomms::ModemDriverBase* goby_make_driver();
47}
48
49namespace boost
50{
51namespace system
52{
53class error_code;
54} // namespace system
55} // namespace boost
56
57namespace goby
58{
59namespace acomms
60{
61namespace protobuf
62{
63class ModemTransmission;
64} // namespace protobuf
65} // namespace acomms
66} // namespace goby
67
68namespace jaiabot
69{
70namespace comms
71{
72class XBeeDriver : public goby::acomms::ModemDriverBase
73{
74 public:
76 ~XBeeDriver() override;
77
78 void startup(const goby::acomms::protobuf::DriverConfig& cfg) override;
79 void shutdown() override;
80 void do_work() override;
81 void handle_initiate_transmission(const goby::acomms::protobuf::ModemTransmission& m) override;
82
83 private:
84 void start_send(const goby::acomms::protobuf::ModemTransmission& msg);
85 void send_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
86 void start_receive();
87 void receive_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
88 void receive_message(const goby::acomms::protobuf::ModemTransmission& m);
89
90 bool parse_modem_message(std::string in, goby::acomms::protobuf::ModemTransmission* out);
91 void serialize_modem_message(std::string* out,
92 const goby::acomms::protobuf::ModemTransmission& in);
93
94 const xbee::protobuf::Config& config_extension()
95 {
96 return driver_cfg_.GetExtension(xbee::protobuf::config);
97 }
98
99 void update_active_hub(int hub_id, goby::acomms::protobuf::ModemTransmission* out);
100 void set_active_hub_peer(int hub_id);
101
102 private:
103 goby::acomms::protobuf::DriverConfig driver_cfg_;
104
105 XBeeDevice device_;
106
107 // ids we are providing acks for, normally just our modem_id()
108 std::set<unsigned> application_ack_ids_;
109
110 std::uint32_t next_frame_{0};
111 bool test_comms_{false};
112 std::map<int32_t, goby::time::SteadyClock::time_point> send_time_{};
113 std::size_t number_of_bytes_to_send_{0};
114
115 // 1
116 int hub_xbee_base_modem_id_{-1};
117
118 // 1 + number of modems in link*link
119 int hub_xbee_modem_id_{-1};
120};
121} // namespace comms
122} // namespace jaiabot
123#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()