Goby3  3.1.5
2024.05.14
interface.h
Go to the documentation of this file.
1 // Copyright 2013-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 // Henrik Schmidt <henrik@mit.edu>
8 //
9 //
10 // This file is part of the Goby Underwater Autonomy Project Libraries
11 // ("The Goby Libraries").
12 //
13 // The Goby Libraries are free software: you can redistribute them and/or modify
14 // them under the terms of the GNU Lesser General Public License as published by
15 // the Free Software Foundation, either version 2.1 of the License, or
16 // (at your option) any later version.
17 //
18 // The Goby Libraries are distributed in the hope that they will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef GOBY_MIDDLEWARE_FRONTSEAT_INTERFACE_H
27 #define GOBY_MIDDLEWARE_FRONTSEAT_INTERFACE_H
28 
29 #include <memory> // for unique_ptr
30 #include <string> // for string
31 
32 #include <boost/signals2/signal.hpp> // for signal
33 #include <boost/smart_ptr/shared_ptr.hpp> // for shared_ptr
34 
35 #include "goby/middleware/protobuf/frontseat.pb.h" // for InterfaceS...
37 #include "goby/time/types.h" // for MicroTime
38 #include "goby/util/geodesy.h" // for UTMGeodesy
39 
40 namespace goby
41 {
42 namespace apps
43 {
44 namespace moos
45 {
46 class FrontSeatLegacyTranslator;
47 }
48 } // namespace apps
49 namespace middleware
50 {
51 namespace frontseat
52 {
53 namespace protobuf
54 {
55 class CTDSample;
56 class NodeStatus;
57 } // namespace protobuf
58 
60 {
61  public:
62  InterfaceBase(protobuf::Config cfg);
63 
64  virtual ~InterfaceBase() = default;
65 
66  virtual void send_command_to_frontseat(const protobuf::CommandRequest& command) = 0;
67  virtual void send_data_to_frontseat(const protobuf::InterfaceData& data) = 0;
68  virtual void send_raw_to_frontseat(const protobuf::Raw& data) = 0;
69 
71  virtual bool frontseat_providing_data() const = 0;
72 
73  void set_helm_state(protobuf::HelmState state) { helm_state_ = state; }
74  protobuf::HelmState helm_state() const { return helm_state_; }
75  protobuf::InterfaceState state() const { return state_; }
76 
77  void do_work();
78 
79  protobuf::InterfaceStatus status()
80  {
81  protobuf::InterfaceStatus s;
82  s.set_state(state_);
83  s.set_frontseat_state(frontseat_state());
84  s.set_helm_state(helm_state_);
85  if (last_helm_error_ != protobuf::ERROR_HELM_NONE)
86  s.set_helm_error(last_helm_error_);
87  if (last_frontseat_error_ != protobuf::ERROR_FRONTSEAT_NONE)
88  s.set_frontseat_error(last_frontseat_error_);
89  return s;
90  }
91 
92  // Called at the AppTick frequency of iFrontSeat
93  // Here is where you can process incoming data
94  virtual void loop() = 0;
95 
96  // Signals that iFrontseat connects to
97  // call this with data from the Frontseat
98  boost::signals2::signal<void(const protobuf::CommandResponse& data)> signal_command_response;
99  boost::signals2::signal<void(const protobuf::InterfaceData& data)> signal_data_from_frontseat;
100  boost::signals2::signal<void(const protobuf::Raw& data)> signal_raw_from_frontseat;
101  boost::signals2::signal<void(const protobuf::Raw& data)> signal_raw_to_frontseat;
102 
103  const protobuf::Config& cfg() const { return cfg_; }
104 
105  void compute_missing(protobuf::CTDSample* ctd_sample);
106  void compute_missing(protobuf::NodeStatus* status);
107 
108  // Dynamic UTM update
110 
111  friend class goby::apps::moos::FrontSeatLegacyTranslator; // to access the signal_state_change
112  private:
113  void check_error_states();
114  void check_change_state();
115 
116  // Signals called by InterfaceBase directly. No need to call these
117  // from the Frontseat driver implementation
118  boost::signals2::signal<void(protobuf::InterfaceState state)> signal_state_change;
119 
120  enum Direction
121  {
122  DIRECTION_TO_FRONTSEAT,
123  DIRECTION_FROM_FRONTSEAT
124  };
125 
126  void glog_raw(const protobuf::Raw& data, Direction direction);
127 
128  private:
129  protobuf::Config cfg_;
130  protobuf::HelmState helm_state_;
132  goby::time::MicroTime start_time_;
133  protobuf::FrontSeatError last_frontseat_error_;
134  protobuf::HelmError last_helm_error_;
135 
136  std::unique_ptr<goby::util::UTMGeodesy> geodesy_;
137 
138 
139  std::string glog_out_group_, glog_in_group_;
140 };
141 } // namespace frontseat
142 } // namespace middleware
143 } // namespace goby
144 
145 #endif
protobuf::InterfaceState state() const
Definition: interface.h:75
boost::signals2::signal< void(const protobuf::Raw &data)> signal_raw_to_frontseat
Definition: interface.h:101
boost::signals2::signal< void(const protobuf::InterfaceData &data)> signal_data_from_frontseat
Definition: interface.h:99
protobuf::HelmState helm_state() const
Definition: interface.h:74
friend class goby::apps::moos::FrontSeatLegacyTranslator
Definition: interface.h:111
void compute_missing(protobuf::CTDSample *ctd_sample)
virtual void send_data_to_frontseat(const protobuf::InterfaceData &data)=0
boost::signals2::signal< void(const protobuf::CommandResponse &data)> signal_command_response
Definition: interface.h:98
virtual void send_raw_to_frontseat(const protobuf::Raw &data)=0
protobuf::InterfaceStatus status()
Definition: interface.h:79
const protobuf::Config & cfg() const
Definition: interface.h:103
boost::signals2::signal< void(const protobuf::Raw &data)> signal_raw_from_frontseat
Definition: interface.h:100
virtual bool frontseat_providing_data() const =0
virtual void send_command_to_frontseat(const protobuf::CommandRequest &command)=0
void set_helm_state(protobuf::HelmState state)
Definition: interface.h:73
void compute_missing(protobuf::NodeStatus *status)
void update_utm_datum(goby::util::UTMGeodesy::LatLonPoint datum)
virtual protobuf::FrontSeatState frontseat_state() const =0
boost::units::quantity< MicroTimeUnit, std::int64_t > MicroTime
quantity of microseconds (using int64)
Definition: types.h:39
The global namespace for the Goby project.