Goby3  3.1.5a
2024.05.23
bluefin.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 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_MIDDLEWARE_FRONTSEAT_BLUEFIN_BLUEFIN_H
26 #define GOBY_MIDDLEWARE_FRONTSEAT_BLUEFIN_BLUEFIN_H
27 
28 #include <deque> // for deque
29 #include <map> // for map
30 #include <string> // for string
31 
32 #include <boost/bimap/bimap.hpp> // for bimap
33 
36 #include "goby/middleware/frontseat/interface.h" // for Int...
37 #include "goby/middleware/protobuf/frontseat.pb.h" // for Fro...
38 #include "goby/middleware/protobuf/frontseat_data.pb.h" // for Nod...
39 #include "goby/time/system_clock.h" // for Sys...
40 #include "goby/time/types.h" // for Mic...
41 #include "goby/util/linebasedcomms/nmea_sentence.h" // for NME...
42 #include "goby/util/linebasedcomms/tcp_client.h" // for TCP...
43 
44 namespace goby
45 {
46 namespace middleware
47 {
48 namespace frontseat
49 {
50 namespace protobuf
51 {
52 class Config;
53 } // namespace protobuf
54 
55 class Bluefin : public InterfaceBase
56 {
57  public:
59 
60  private: // virtual methods from InterfaceBase
61  void loop() override;
62 
63  void send_command_to_frontseat(const protobuf::CommandRequest& command) override;
64  void send_data_to_frontseat(const protobuf::InterfaceData& data) override;
65  void send_raw_to_frontseat(const protobuf::Raw& data) override;
66 
67  protobuf::FrontSeatState frontseat_state() const override { return frontseat_state_; }
68 
69  bool frontseat_providing_data() const override { return frontseat_providing_data_; }
70 
71  private: // internal non-virtual methods
72  void load_nmea_mappings();
73  void initialize_huxley();
74  void append_to_write_queue(const goby::util::NMEASentence& nmea);
75  void remove_from_write_queue();
76 
77  void check_send_heartbeat();
78  void try_send();
79  void try_receive();
80  void write(const goby::util::NMEASentence& nmea);
81  void process_receive(const goby::util::NMEASentence& nmea);
82 
83  void bfack(const goby::util::NMEASentence& nmea);
84  void bfnvr(const goby::util::NMEASentence& nmea);
85  void bfsvs(const goby::util::NMEASentence& nmea);
86  void bfrvl(const goby::util::NMEASentence& nmea);
87  void bfnvg(const goby::util::NMEASentence& nmea);
88  void bfmsc(const goby::util::NMEASentence& nmea);
89  void bfsht(const goby::util::NMEASentence& nmea);
90  void bfmbs(const goby::util::NMEASentence& nmea);
91  void bfboy(const goby::util::NMEASentence& nmea);
92  void bftrm(const goby::util::NMEASentence& nmea);
93  void bfmbe(const goby::util::NMEASentence& nmea);
94  void bftop(const goby::util::NMEASentence& nmea);
95  void bfdvl(const goby::util::NMEASentence& nmea);
96  void bfmis(const goby::util::NMEASentence& nmea);
97  void bfctd(const goby::util::NMEASentence& nmea);
98  void bfctl(const goby::util::NMEASentence& nmea);
99 
100  std::string unix_time2nmea_time(goby::time::SystemClock::time_point time);
101 
102  private:
103  const protobuf::BluefinConfig bf_config_;
105  bool frontseat_providing_data_;
106  goby::time::SystemClock::time_point last_frontseat_data_time_;
107  protobuf::FrontSeatState frontseat_state_;
108  goby::time::SystemClock::time_point next_connect_attempt_time_;
109 
110  goby::time::SystemClock::time_point last_write_time_;
111  std::deque<goby::util::NMEASentence> out_;
112  std::deque<goby::util::NMEASentence> pending_;
113  bool waiting_for_huxley_;
114  unsigned nmea_demerits_;
115  unsigned nmea_present_fail_count_;
116 
117  goby::time::SystemClock::time_point last_heartbeat_time_;
118 
119  enum TalkerIDs
120  {
121  TALKER_NOT_DEFINED = 0,
122  BF,
123  BP
124  };
125 
126  enum SentenceIDs
127  {
128  SENTENCE_NOT_DEFINED = 0,
129  MSC,
130  SHT,
131  BDL,
132  SDL,
133  TOP,
134  DVT,
135  VER,
136  NVG,
137  SVS,
138  RCM,
139  RDP,
140  RVL,
141  RBS,
142  MBS,
143  MBE,
144  MIS,
145  ERC,
146  DVL,
147  DV2,
148  IMU,
149  CTD,
150  RNV,
151  PIT,
152  CNV,
153  PLN,
154  ACK,
155  TRM,
156  LOG,
157  STS,
158  DVR,
159  CPS,
160  CPR,
161  TRK,
162  RTC,
163  RGP,
164  RCN,
165  RCA,
166  RCB,
167  RMB,
168  EMB,
169  TMR,
170  ABT,
171  KIL,
172  MSG,
173  RMP,
174  SEM,
175  NPU,
176  CPD,
177  SIL,
178  BOY,
179  SUS,
180  CON,
181  RES,
182  SPD,
183  SAN,
184  GHP,
185  GBP,
186  RNS,
187  RBO,
188  CMA,
189  NVR,
190  TEL,
191  CTL,
192  DCL,
193  VEL
194  };
195 
196  std::map<std::string, TalkerIDs> talker_id_map_;
197  boost::bimap<std::string, SentenceIDs> sentence_id_map_;
198  std::map<std::string, std::string> description_map_;
199 
200  // the current status message we're building up
201  protobuf::NodeStatus status_;
202 
203  // maps command type to outstanding request, if response is requested
204  std::map<protobuf::BluefinExtraCommands::BluefinCommand, protobuf::CommandRequest>
205  outstanding_requests_;
206 
207  // maps status expire time to payload status
208  std::multimap<goby::time::MicroTime, protobuf::BluefinExtraData::PayloadStatus> payload_status_;
209 
210  // maps speed to rpm value
211  std::map<double, int> speed_to_rpm_;
212 };
213 } // namespace frontseat
214 } // namespace middleware
215 } // namespace goby
216 
217 #endif
goby::middleware::frontseat::protobuf::NodeStatus
Definition: frontseat_data.pb.h:227
system_clock.h
goby::middleware::frontseat::protobuf::FrontSeatState
FrontSeatState
Definition: frontseat.pb.h:136
types.h
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
tcp_client.h
goby::middleware::frontseat::protobuf::BluefinConfig
Definition: bluefin_config.pb.h:247
frontseat.pb.h
goby::middleware::frontseat::InterfaceBase
Definition: interface.h:59
nmea_sentence.h
goby::middleware::frontseat::Bluefin
Definition: bluefin.h:55
frontseat_data.pb.h
goby::middleware::frontseat::Bluefin::Bluefin
Bluefin(const protobuf::Config &cfg)
goby::middleware::frontseat::protobuf::InterfaceData
Definition: frontseat.pb.h:795
bluefin.pb.h
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::time::SystemClock::time_point
std::chrono::time_point< SystemClock > time_point
Definition: system_clock.h:55
goby::middleware::frontseat::protobuf::CommandRequest
Definition: frontseat.pb.h:488
interface.h
goby::util::TCPClient
provides a basic TCP client for line by line text based communications to a remote TCP server
Definition: tcp_client.h:43
boost::units::si::time
unit< time_dimension, si::system > time
Definition: time.hpp:22
goby::middleware::frontseat::protobuf::Raw
Definition: frontseat.pb.h:950
goby::util::NMEASentence
Definition: nmea_sentence.h:51
bluefin_config.pb.h