Goby v2
waveglider_sv2_frontseat_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 WavegliderSV2FrontSeat20150909H
24 #define WavegliderSV2FrontSeat20150909H
25 
26 #include <boost/bimap.hpp>
27 #include <boost/circular_buffer.hpp>
28 #include <dccl.h>
29 
30 #include "goby/util/linebasedcomms/tcp_client.h"
31 
32 #include "goby/moos/frontseat/frontseat.h"
33 
34 #include "waveglider_sv2_frontseat_driver.pb.h"
35 #include "waveglider_sv2_frontseat_driver_config.pb.h"
36 #include "waveglider_sv2_serial_client.h"
37 
38 extern "C"
39 {
40  FrontSeatInterfaceBase* frontseat_driver_load(iFrontSeatConfig*);
41 }
42 
44 {
45  public:
47 
48  private: // virtual methods from FrontSeatInterfaceBase
49  void loop();
50 
51  void send_command_to_frontseat(const goby::moos::protobuf::CommandRequest& command);
52  void send_data_to_frontseat(const goby::moos::protobuf::FrontSeatInterfaceData& data);
53  void send_raw_to_frontseat(const goby::moos::protobuf::FrontSeatRaw& data);
54  goby::moos::protobuf::FrontSeatState frontseat_state() const;
55  bool frontseat_providing_data() const;
56  void handle_sv2_message(const std::string& message);
57  void handle_enumeration_request(const goby::moos::protobuf::SV2RequestEnumerate& msg);
58  void handle_request_status(const goby::moos::protobuf::SV2RequestStatus& request);
59  void
60  handle_request_queued_message(const goby::moos::protobuf::SV2RequestQueuedMessage& request);
61 
62  void check_crc(const std::string& message, uint16_t expected);
63  void add_crc(std::string* message);
64  void encode_and_write(const google::protobuf::Message& message);
65 
66  private: // internal non-virtual methods
67  void check_connection_state();
68 
69  private:
70  const WavegliderSV2FrontSeatConfig waveglider_sv2_config_;
71 
72  bool frontseat_providing_data_;
73  double last_frontseat_data_time_;
74  goby::moos::protobuf::FrontSeatState frontseat_state_;
75 
76  boost::asio::io_service io_;
77  boost::shared_ptr<goby::moos::SV2SerialConnection> serial_;
78 
79  boost::circular_buffer<boost::shared_ptr<goby::moos::protobuf::SV2CommandFollowFixedHeading> >
80  queued_messages_;
81 
82  dccl::Codec dccl_;
83 };
84 
85 #endif