Goby v2
frontseat.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 FrontSeatBase20130220H
24 #define FrontSeatBase20130220H
25 
26 #include <boost/signals2.hpp>
27 
28 #include "goby/common/time.h"
29 
30 #include "goby/moos/moos_geodesy.h"
31 
32 #include "goby/moos/frontseat/frontseat_exception.h"
33 #include "goby/moos/protobuf/frontseat.pb.h"
34 #include "goby/moos/protobuf/frontseat_config.pb.h"
35 
37 {
38  public:
40 
41  virtual ~FrontSeatInterfaceBase() {}
42 
43  virtual void send_command_to_frontseat(const goby::moos::protobuf::CommandRequest& command) = 0;
44  virtual void
45  send_data_to_frontseat(const goby::moos::protobuf::FrontSeatInterfaceData& data) = 0;
46  virtual void send_raw_to_frontseat(const goby::moos::protobuf::FrontSeatRaw& data) = 0;
47 
48  virtual goby::moos::protobuf::FrontSeatState frontseat_state() const = 0;
49  virtual bool frontseat_providing_data() const = 0;
50 
51  void set_helm_state(goby::moos::protobuf::HelmState state) { helm_state_ = state; }
52  goby::moos::protobuf::HelmState helm_state() const { return helm_state_; }
53  goby::moos::protobuf::InterfaceState state() const { return state_; }
54 
55  void do_work();
56 
58  {
60  s.set_state(state_);
61  s.set_frontseat_state(frontseat_state());
62  s.set_helm_state(helm_state_);
63  if (last_helm_error_ != goby::moos::protobuf::ERROR_HELM_NONE)
64  s.set_helm_error(last_helm_error_);
65  if (last_frontseat_error_ != goby::moos::protobuf::ERROR_FRONTSEAT_NONE)
66  s.set_frontseat_error(last_frontseat_error_);
67  return s;
68  }
69 
70  // Called at the AppTick frequency of iFrontSeat
71  // Here is where you can process incoming data
72  virtual void loop() = 0;
73 
74  // Signals that iFrontseat connects to
75  // call this with data from the Frontseat
76  boost::signals2::signal<void(const goby::moos::protobuf::CommandResponse& data)>
77  signal_command_response;
78  boost::signals2::signal<void(const goby::moos::protobuf::FrontSeatInterfaceData& data)>
79  signal_data_from_frontseat;
80  boost::signals2::signal<void(const goby::moos::protobuf::FrontSeatRaw& data)>
81  signal_raw_from_frontseat;
82  boost::signals2::signal<void(const goby::moos::protobuf::FrontSeatRaw& data)>
83  signal_raw_to_frontseat;
84 
85  const iFrontSeatConfig& cfg() const { return cfg_; }
86 
87  void compute_missing(goby::moos::protobuf::CTDSample* ctd_sample);
88  void compute_missing(goby::moos::protobuf::NodeStatus* status);
89 
90  friend class FrontSeatLegacyTranslator; // to access the signal_state_change
91  private:
92  void check_error_states();
93  void check_change_state();
94 
95  // Signals called by FrontSeatInterfaceBase directly. No need to call these
96  // from the Frontseat driver implementation
97  boost::signals2::signal<void(goby::moos::protobuf::InterfaceState state)> signal_state_change;
98 
99  enum Direction
100  {
101  DIRECTION_TO_FRONTSEAT,
102  DIRECTION_FROM_FRONTSEAT
103  };
104 
105  void glog_raw(const goby::moos::protobuf::FrontSeatRaw& data, Direction direction);
106 
107  private:
108  const iFrontSeatConfig& cfg_;
109  goby::moos::protobuf::HelmState helm_state_;
110  goby::moos::protobuf::InterfaceState state_;
111  double start_time_;
112  goby::moos::protobuf::FrontSeatError last_frontseat_error_;
113  goby::moos::protobuf::HelmError last_helm_error_;
114 
115  CMOOSGeodesy geodesy_;
116 
117  std::string glog_out_group_, glog_in_group_;
118 };
119 
120 #endif