Goby v2
udp_driver.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 UDPModemDriver20120409H
24 #define UDPModemDriver20120409H
25 
26 #include "goby/common/time.h"
27 
28 #include "goby/acomms/modemdriver/driver_base.h"
29 #include "goby/acomms/protobuf/udp_driver.pb.h"
30 
31 #include <boost/asio.hpp>
32 #include <boost/bind.hpp>
33 
34 namespace goby
35 {
36 namespace acomms
37 {
38 class UDPDriver : public ModemDriverBase
39 {
40  public:
41  UDPDriver(boost::asio::io_service* io_service);
42  ~UDPDriver();
43  void startup(const protobuf::DriverConfig& cfg);
44  void shutdown();
45  void do_work();
47 
48  private:
49  void start_send(const google::protobuf::Message& msg);
50  void send_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
51  void start_receive();
52  void receive_complete(const boost::system::error_code& error, std::size_t bytes_transferred);
53  void receive_message(const protobuf::ModemTransmission& m);
54 
55  private:
56  protobuf::DriverConfig driver_cfg_;
57  boost::asio::io_service* io_service_;
58  boost::asio::ip::udp::socket socket_;
59  boost::asio::ip::udp::endpoint receiver_;
60  boost::asio::ip::udp::endpoint sender_;
61  std::vector<char> receive_buffer_;
62  goby::uint32 next_frame_;
63 };
64 } // namespace acomms
65 } // namespace goby
66 #endif
void handle_initiate_transmission(const protobuf::ModemTransmission &m)
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
Definition: udp_driver.cpp:75
google::protobuf::uint32 uint32
an unsigned 32 bit integer
void shutdown()
Shuts down the modem driver.
Definition: udp_driver.cpp:69
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
void do_work()
Allows the modem driver to do its work.
Definition: udp_driver.cpp:98
void startup(const protobuf::DriverConfig &cfg)
Starts the modem driver. Must be called before poll().
Definition: udp_driver.cpp:46