Goby v2
iver_driver.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 IverFrontSeat20171117H
24 #define IverFrontSeat20171117H
25 
26 #include <boost/bimap.hpp>
27 #include <boost/units/quantity.hpp>
28 #include <boost/units/systems/angle/degrees.hpp>
29 #include <boost/units/systems/si.hpp>
30 #include <boost/units/systems/si/prefixes.hpp>
31 
32 #include "goby/util/linebasedcomms/serial_client.h"
33 #include "goby/util/primitive_types.h"
34 #include "goby/util/sci.h"
35 
36 #include "goby/moos/frontseat/frontseat.h"
37 #include "goby/moos/frontseat/iver/iver_driver.pb.h"
38 
39 #include "iver_driver_config.pb.h"
40 
41 extern "C"
42 {
43  FrontSeatInterfaceBase* frontseat_driver_load(iFrontSeatConfig*);
44 }
45 
47 {
48  public:
49  IverFrontSeat(const iFrontSeatConfig& cfg);
50 
51  private: // virtual methods from FrontSeatInterfaceBase
52  void loop();
53 
54  void send_command_to_frontseat(const goby::moos::protobuf::CommandRequest& command);
55  void send_data_to_frontseat(const goby::moos::protobuf::FrontSeatInterfaceData& data);
56  void send_raw_to_frontseat(const goby::moos::protobuf::FrontSeatRaw& data);
57  goby::moos::protobuf::FrontSeatState frontseat_state() const;
58  bool frontseat_providing_data() const;
59 
60  private: // internal non-virtual methods
61  void check_connection_state();
62  void try_receive();
63  void process_receive(const std::string& s);
64  void write(const std::string& s);
65 
66  // given a time and date in "NMEA form", returns the value as seconds since the start of the epoch (1970-01-01 00:00:00Z)
67  // NMEA form for time is HHMMSS where "H" is hours, "M" is minutes, "S" is seconds or fractional seconds
68  // NMEA form for date is DDMMYY where "D" is day, "M" is month, "Y" is year
69  boost::units::quantity<boost::units::si::time> nmea_time_to_seconds(double nmea_time,
70  int nmea_date);
71 
72  // given a latitude or longitude in "NMEA form" and the hemisphere character ('N', 'S', 'E' or 'W'), returns the value as decimal degrees
73  // NMEA form is DDDMM.MMMM or DDMM.MMMM where "D" is degrees, and "M" is minutes
74  boost::units::quantity<boost::units::degree::plane_angle> nmea_geo_to_degrees(double nmea_geo,
75  char hemi);
76 
77  // remote helm manual shows input as tenths precision, so we will force that here
78  std::string tenths_precision_str(double d)
79  {
80  std::stringstream ss;
81  ss << std::fixed << std::setprecision(1) << goby::util::unbiased_round(d, 1);
82  return ss.str();
83  }
84 
85 
86  private:
87  const IverFrontSeatConfig iver_config_;
89 
90  boost::shared_ptr<goby::util::SerialClient> ntp_serial_;
91 
92  bool frontseat_providing_data_;
93  double last_frontseat_data_time_;
94  goby::moos::protobuf::FrontSeatState frontseat_state_;
95  goby::moos::protobuf::IverState::IverMissionMode reported_mission_mode_;
96 
98 
100 };
101 
102 #endif
provides a basic client for line by line text based communications over a 8N1 tty (such as an RS-232 ...
Definition: serial_client.h:35