Goby v2
bluefin.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 BluefinFrontSeat20130220H
24 #define BluefinFrontSeat20130220H
25 
26 #include <boost/bimap.hpp>
27 
28 #include "goby/util/linebasedcomms/nmea_sentence.h"
29 #include "goby/util/linebasedcomms/tcp_client.h"
30 
31 #include "goby/moos/frontseat/frontseat.h"
32 
33 #include "goby/moos/frontseat/bluefin/bluefin.pb.h"
34 #include "goby/moos/frontseat/bluefin/bluefin_config.pb.h"
35 
36 extern "C"
37 {
38  FrontSeatInterfaceBase* frontseat_driver_load(iFrontSeatConfig*);
39 }
40 
42 {
43  public:
45 
46  private: // virtual methods from FrontSeatInterfaceBase
47  void loop();
48 
49  void send_command_to_frontseat(const goby::moos::protobuf::CommandRequest& command);
50  void send_data_to_frontseat(const goby::moos::protobuf::FrontSeatInterfaceData& data);
51  void send_raw_to_frontseat(const goby::moos::protobuf::FrontSeatRaw& data);
52 
53  goby::moos::protobuf::FrontSeatState frontseat_state() const { return frontseat_state_; }
54 
55  bool frontseat_providing_data() const { return frontseat_providing_data_; }
56 
57  private: // internal non-virtual methods
58  void load_nmea_mappings();
59  void initialize_huxley();
60  void append_to_write_queue(const goby::util::NMEASentence& nmea);
61  void remove_from_write_queue();
62 
63  void check_send_heartbeat();
64  void try_send();
65  void try_receive();
66  void write(const goby::util::NMEASentence& nmea);
67  void process_receive(const goby::util::NMEASentence& nmea);
68 
69  void bfack(const goby::util::NMEASentence& nmea);
70  void bfnvr(const goby::util::NMEASentence& nmea);
71  void bfsvs(const goby::util::NMEASentence& nmea);
72  void bfrvl(const goby::util::NMEASentence& nmea);
73  void bfnvg(const goby::util::NMEASentence& nmea);
74  void bfmsc(const goby::util::NMEASentence& nmea);
75  void bfsht(const goby::util::NMEASentence& nmea);
76  void bfmbs(const goby::util::NMEASentence& nmea);
77  void bfboy(const goby::util::NMEASentence& nmea);
78  void bftrm(const goby::util::NMEASentence& nmea);
79  void bfmbe(const goby::util::NMEASentence& nmea);
80  void bftop(const goby::util::NMEASentence& nmea);
81  void bfdvl(const goby::util::NMEASentence& nmea);
82  void bfmis(const goby::util::NMEASentence& nmea);
83  void bfctd(const goby::util::NMEASentence& nmea);
84  void bfctl(const goby::util::NMEASentence& nmea);
85 
86  std::string unix_time2nmea_time(double time);
87 
88  private:
89  const BluefinFrontSeatConfig bf_config_;
91  bool frontseat_providing_data_;
92  double last_frontseat_data_time_;
93  goby::moos::protobuf::FrontSeatState frontseat_state_;
94  double next_connect_attempt_time_;
95 
96  double last_write_time_;
97  std::deque<goby::util::NMEASentence> out_;
98  std::deque<goby::util::NMEASentence> pending_;
99  bool waiting_for_huxley_;
100  unsigned nmea_demerits_;
101  unsigned nmea_present_fail_count_;
102 
103  double last_heartbeat_time_;
104 
105  enum TalkerIDs
106  {
107  TALKER_NOT_DEFINED = 0,
108  BF,
109  BP
110  };
111 
112  enum SentenceIDs
113  {
114  SENTENCE_NOT_DEFINED = 0,
115  MSC,
116  SHT,
117  BDL,
118  SDL,
119  TOP,
120  DVT,
121  VER,
122  NVG,
123  SVS,
124  RCM,
125  RDP,
126  RVL,
127  RBS,
128  MBS,
129  MBE,
130  MIS,
131  ERC,
132  DVL,
133  DV2,
134  IMU,
135  CTD,
136  RNV,
137  PIT,
138  CNV,
139  PLN,
140  ACK,
141  TRM,
142  LOG,
143  STS,
144  DVR,
145  CPS,
146  CPR,
147  TRK,
148  RTC,
149  RGP,
150  RCN,
151  RCA,
152  RCB,
153  RMB,
154  EMB,
155  TMR,
156  ABT,
157  KIL,
158  MSG,
159  RMP,
160  SEM,
161  NPU,
162  CPD,
163  SIL,
164  BOY,
165  SUS,
166  CON,
167  RES,
168  SPD,
169  SAN,
170  GHP,
171  GBP,
172  RNS,
173  RBO,
174  CMA,
175  NVR,
176  TEL,
177  CTL,
178  DCL
179  };
180 
181  std::map<std::string, TalkerIDs> talker_id_map_;
182  boost::bimap<std::string, SentenceIDs> sentence_id_map_;
183  std::map<std::string, std::string> description_map_;
184 
185  // the current status message we're building up
187 
188  // maps command type to outstanding request, if response is requested
189  std::map<goby::moos::protobuf::BluefinExtraCommands::BluefinCommand,
191  outstanding_requests_;
192 
193  // maps status expire time to payload status
194  std::multimap<goby::uint64, goby::moos::protobuf::BluefinExtraData::PayloadStatus>
195  payload_status_;
196 };
197 
198 #endif
provides a basic TCP client for line by line text based communications to a remote TCP server ...
Definition: tcp_client.h:34