Goby3  3.1.5a
2024.05.23
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:
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 
70  virtual protobuf::FrontSeatState frontseat_state() const = 0;
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 
80  {
82  s.set_state(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);
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
goby::middleware::frontseat::InterfaceBase::do_work
void do_work()
goby::acomms::Direction
Direction
Definition: iridium_driver_common.h:47
goby::middleware::frontseat::InterfaceBase::frontseat_state
virtual protobuf::FrontSeatState frontseat_state() const =0
goby::middleware::frontseat::protobuf::NodeStatus
Definition: frontseat_data.pb.h:227
goby::middleware::frontseat::protobuf::CommandResponse
Definition: frontseat.pb.h:640
goby::middleware::frontseat::InterfaceBase::send_command_to_frontseat
virtual void send_command_to_frontseat(const protobuf::CommandRequest &command)=0
goby::middleware::frontseat::InterfaceBase::FrontSeatLegacyTranslator
friend class goby::apps::moos::FrontSeatLegacyTranslator
Definition: interface.h:111
goby::middleware::frontseat::protobuf::FrontSeatState
FrontSeatState
Definition: frontseat.pb.h:136
goby::middleware::frontseat::protobuf::InterfaceStatus::set_helm_state
void set_helm_state(::goby::middleware::frontseat::protobuf::HelmState value)
Definition: frontseat.pb.h:1235
types.h
goby::middleware::frontseat::protobuf::InterfaceStatus::set_frontseat_error
void set_frontseat_error(::goby::middleware::frontseat::protobuf::FrontSeatError value)
Definition: frontseat.pb.h:1285
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
frontseat.pb.h
goby::middleware::frontseat::InterfaceBase
Definition: interface.h:59
goby::middleware::frontseat::protobuf::InterfaceStatus::set_frontseat_state
void set_frontseat_state(::goby::middleware::frontseat::protobuf::FrontSeatState value)
Definition: frontseat.pb.h:1210
goby::middleware::frontseat::protobuf::InterfaceStatus::set_helm_error
void set_helm_error(::goby::middleware::frontseat::protobuf::HelmError value)
Definition: frontseat.pb.h:1260
goby::middleware::frontseat::InterfaceBase::InterfaceBase
InterfaceBase(protobuf::Config cfg)
goby::middleware::frontseat::InterfaceBase::loop
virtual void loop()=0
goby::middleware::frontseat::protobuf::InterfaceState
InterfaceState
Definition: frontseat.pb.h:114
frontseat_config.pb.h
goby::middleware::frontseat::InterfaceBase::signal_command_response
boost::signals2::signal< void(const protobuf::CommandResponse &data)> signal_command_response
Definition: interface.h:98
goby::middleware::frontseat::InterfaceBase::frontseat_providing_data
virtual bool frontseat_providing_data() const =0
goby::middleware::frontseat::InterfaceBase::helm_state
protobuf::HelmState helm_state() const
Definition: interface.h:74
detail::void
j template void())
Definition: json.hpp:4822
goby::middleware::frontseat::protobuf::InterfaceData
Definition: frontseat.pb.h:795
goby::middleware::frontseat::InterfaceBase::compute_missing
void compute_missing(protobuf::CTDSample *ctd_sample)
goby::middleware::frontseat::InterfaceBase::status
protobuf::InterfaceStatus status()
Definition: interface.h:79
goby::middleware::frontseat::protobuf::CTDSample
Definition: frontseat_data.pb.h:1581
goby::middleware::frontseat::protobuf::Config
Definition: frontseat_config.pb.h:81
goby::middleware::frontseat::InterfaceBase::cfg
const protobuf::Config & cfg() const
Definition: interface.h:103
goby::middleware::frontseat::protobuf::CommandRequest
Definition: frontseat.pb.h:488
goby::middleware::frontseat::InterfaceBase::~InterfaceBase
virtual ~InterfaceBase()=default
goby::middleware::frontseat::protobuf::InterfaceStatus::set_state
void set_state(::goby::middleware::frontseat::protobuf::InterfaceState value)
Definition: frontseat.pb.h:1185
goby::middleware::frontseat::protobuf::HelmState
HelmState
Definition: frontseat.pb.h:157
goby::middleware::frontseat::InterfaceBase::set_helm_state
void set_helm_state(protobuf::HelmState state)
Definition: interface.h:73
goby::middleware::frontseat::InterfaceBase::state
protobuf::InterfaceState state() const
Definition: interface.h:75
goby::middleware::frontseat::InterfaceBase::send_data_to_frontseat
virtual void send_data_to_frontseat(const protobuf::InterfaceData &data)=0
goby::middleware::frontseat::InterfaceBase::send_raw_to_frontseat
virtual void send_raw_to_frontseat(const protobuf::Raw &data)=0
goby::middleware::frontseat::protobuf::ERROR_HELM_NONE
@ ERROR_HELM_NONE
Definition: frontseat.pb.h:178
goby::middleware::frontseat::InterfaceBase::signal_raw_from_frontseat
boost::signals2::signal< void(const protobuf::Raw &data)> signal_raw_from_frontseat
Definition: interface.h:100
geodesy.h
goby::middleware::frontseat::protobuf::FrontSeatError
FrontSeatError
Definition: frontseat.pb.h:197
goby::middleware::frontseat::protobuf::InterfaceStatus
Definition: frontseat.pb.h:334
goby::middleware::frontseat::protobuf::Raw
Definition: frontseat.pb.h:950
goby::util::UTMGeodesy::LatLonPoint
Definition: geodesy.h:39
goby::middleware::frontseat::InterfaceBase::update_utm_datum
void update_utm_datum(goby::util::UTMGeodesy::LatLonPoint datum)
goby::time::MicroTime
boost::units::quantity< MicroTimeUnit, std::int64_t > MicroTime
quantity of microseconds (using int64)
Definition: types.h:39
goby::middleware::frontseat::protobuf::ERROR_FRONTSEAT_NONE
@ ERROR_FRONTSEAT_NONE
Definition: frontseat.pb.h:198
goby::middleware::frontseat::InterfaceBase::signal_raw_to_frontseat
boost::signals2::signal< void(const protobuf::Raw &data)> signal_raw_to_frontseat
Definition: interface.h:101
goby::middleware::frontseat::protobuf::HelmError
HelmError
Definition: frontseat.pb.h:177
goby::middleware::frontseat::InterfaceBase::signal_data_from_frontseat
boost::signals2::signal< void(const protobuf::InterfaceData &data)> signal_data_from_frontseat
Definition: interface.h:99