Goby3  3.1.4
2024.02.22
gps_sentence.h
Go to the documentation of this file.
1 // Copyright 2021:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_UTIL_LINEBASEDCOMMS_GPS_SENTENCE_H
25 #define GOBY_UTIL_LINEBASEDCOMMS_GPS_SENTENCE_H
26 
27 #include <boost/format.hpp>
28 #include <boost/optional.hpp>
29 #include <boost/units/base_units/metric/knot.hpp>
30 #include <boost/units/systems/angle/degrees.hpp>
31 #include <boost/units/systems/si.hpp>
32 #include <boost/units/systems/temperature/celsius.hpp>
33 
34 #include "goby/time/convert.h"
35 #include "goby/time/system_clock.h"
36 #include "nmea_sentence.h"
37 
38 namespace goby
39 {
40 namespace util
41 {
42 namespace gps
43 {
45 double nmea_geo_to_decimal(std::string nmea_geo_str, char hemi);
46 
48 {
49  LAT,
51 };
52 
54 std::pair<std::string, char> decimal_to_nmea_geo(double decimal, CoordType t);
55 
56 struct RMC
57 {
58  public:
59  RMC() = default;
60 
61  RMC(const NMEASentence& sentence) { parse(sentence); }
62 
63  void parse(const NMEASentence& sentence);
64  NMEASentence serialize(std::string talker_id = "GP", int num_fields = min_size) const;
65 
66  boost::optional<goby::time::SystemClock::time_point> time;
67 
68  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> latitude;
69  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> longitude;
70  boost::optional<boost::units::quantity<boost::units::si::velocity>> speed_over_ground;
71  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> course_over_ground;
72 
73  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> magnetic_variation;
74 
75  enum Fields
76  {
77  UTC_TIME = 1,
78  VALIDITY = 2,
79  LATITUDE = 3,
81  LONGITUDE = 5,
85  DATE = 9,
88  MODE = 12, // NMEA 2.3 and later
89  NAV_STATUS = 13 // NMEA 4.1 and later
90  };
91 
92  enum Status
93  {
96  };
97 
98  boost::optional<Status> status;
99 
100  constexpr static int min_size = MAG_VARIATION_EW + 1; // MAG_VARIATION_EW + talker
101 };
102 
103 inline bool operator==(const RMC& rmc1, const RMC& rmc2)
104 {
105  return rmc1.serialize().message() == rmc2.serialize().message();
106 }
107 
108 inline std::ostream& operator<<(std::ostream& os, const RMC& rmc)
109 {
110  return (os << rmc.serialize().message());
111 }
112 
113 struct HDT
114 {
115  public:
116  HDT() = default;
117 
118  HDT(const NMEASentence& sentence) { parse(sentence); }
119 
120  void parse(const NMEASentence& sentence);
121  NMEASentence serialize(std::string talker_id = "GP") const;
122 
123  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> true_heading;
124 
125  enum Fields
126  {
127  HEADING = 1,
128  T = 2
129  };
130  constexpr static int min_size = HEADING + 1; // HEADING + talker
131  constexpr static int size = T + 1;
132 };
133 
134 inline bool operator==(const HDT& hdt1, const HDT& hdt2)
135 {
136  return hdt1.serialize().message() == hdt2.serialize().message();
137 }
138 
139 inline std::ostream& operator<<(std::ostream& os, const HDT& hdt)
140 {
141  return (os << hdt.serialize().message());
142 }
143 
144 struct WPL
145 {
146  public:
147  WPL() = default;
148 
149  WPL(const NMEASentence& sentence) { parse(sentence); }
150 
151  void parse(const NMEASentence& sentence);
152  NMEASentence serialize(std::string talker_id = "EC") const;
153 
154  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> latitude;
155  boost::optional<boost::units::quantity<boost::units::degree::plane_angle>> longitude;
156  boost::optional<std::string> name;
157 
158  enum Fields
159  {
160  LATITUDE = 1,
164  NAME = 5
165  };
166  constexpr static int min_size = NAME + 1; // NAME + talker
167  constexpr static int size = min_size;
168 };
169 
170 inline bool operator==(const WPL& wpl1, const WPL& wpl2)
171 {
172  return wpl1.serialize().message() == wpl2.serialize().message();
173 }
174 
175 inline std::ostream& operator<<(std::ostream& os, const WPL& wpl)
176 {
177  return (os << wpl.serialize().message());
178 }
179 
180 struct RTE
181 {
182  public:
183  RTE() = default;
184 
185  RTE(const NMEASentence& sentence) { parse(sentence); }
186 
187  void parse(const NMEASentence& sentence);
188  NMEASentence serialize(std::string talker_id = "EC") const;
189 
190  boost::optional<std::string> name;
191  std::vector<std::string> waypoint_names;
192  boost::optional<int> total_number_sentences;
193  boost::optional<int> current_sentence_index; // starting at 1
195  {
199  };
201 
202  enum Fields
203  {
207  NAME = 4,
209  // then waypoint names until end of sentence
210  };
211  constexpr static int min_size = FIRST_WAYPOINT_NAME + 1; // FIRST_WAYPOINT_NAME + talker
212 };
213 
214 inline bool operator==(const RTE& rte1, const RTE& rte2)
215 {
216  return rte1.serialize().message() == rte2.serialize().message();
217 }
218 
219 inline std::ostream& operator<<(std::ostream& os, const RTE& rte)
220 {
221  return (os << rte.serialize().message());
222 }
223 
224 } // namespace gps
225 } // namespace util
226 } // namespace goby
227 
228 #endif
goby::util::gps::RMC::SPEED_OVER_GROUND
@ SPEED_OVER_GROUND
Definition: gps_sentence.h:83
system_clock.h
goby::util::gps::RTE::TOTAL_NUMBER_SENTENCES
@ TOTAL_NUMBER_SENTENCES
Definition: gps_sentence.h:204
goby::util::gps::decimal_to_nmea_geo
std::pair< std::string, char > decimal_to_nmea_geo(double decimal, CoordType t)
Convert a decimal degrees latitude or longitude into a pair of NMEA string representation and hemisph...
goby::util::gps::HDT::parse
void parse(const NMEASentence &sentence)
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::util::gps::HDT::HEADING
@ HEADING
Definition: gps_sentence.h:127
goby::util::gps::LAT
@ LAT
Definition: gps_sentence.h:49
goby::util::gps::WPL::parse
void parse(const NMEASentence &sentence)
goby::util::gps::WPL::LATITUDE
@ LATITUDE
Definition: gps_sentence.h:160
goby::util::gps::RTE::parse
void parse(const NMEASentence &sentence)
goby::util::gps::RMC::RMC
RMC()=default
goby::util::gps::HDT
Definition: gps_sentence.h:113
goby::util::gps::RMC::MAGNETIC_VARIATION
@ MAGNETIC_VARIATION
Definition: gps_sentence.h:86
goby::util::gps::WPL::longitude
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > longitude
Definition: gps_sentence.h:155
goby::util::gps::RMC::NAV_STATUS
@ NAV_STATUS
Definition: gps_sentence.h:89
goby::util::gps::RTE::min_size
constexpr static int min_size
Definition: gps_sentence.h:211
goby::util::gps::RMC::magnetic_variation
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > magnetic_variation
Definition: gps_sentence.h:73
goby::util::gps::RMC::UTC_TIME
@ UTC_TIME
Definition: gps_sentence.h:77
goby::util::gps::RTE::RTE
RTE(const NMEASentence &sentence)
Definition: gps_sentence.h:185
goby::util::gps::RMC::parse
void parse(const NMEASentence &sentence)
goby::util::gps::RMC::LATITUDE
@ LATITUDE
Definition: gps_sentence.h:79
goby::util::gps::RTE::waypoint_names
std::vector< std::string > waypoint_names
Definition: gps_sentence.h:191
goby::util::gps::RTE::ROUTE_TYPE
@ ROUTE_TYPE
Definition: gps_sentence.h:206
goby::util::gps::RMC::NavigationReceiverWarning
@ NavigationReceiverWarning
Definition: gps_sentence.h:95
goby::util::gps::RMC::min_size
constexpr static int min_size
Definition: gps_sentence.h:100
nmea_sentence.h
goby::util::gps::RMC::LATITUDE_NS
@ LATITUDE_NS
Definition: gps_sentence.h:80
goby::util::gps::RMC::DataValid
@ DataValid
Definition: gps_sentence.h:94
goby::util::gps::HDT::true_heading
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > true_heading
Definition: gps_sentence.h:123
goby::util::gps::HDT::HDT
HDT()=default
goby::util::gps::RMC::speed_over_ground
boost::optional< boost::units::quantity< boost::units::si::velocity > > speed_over_ground
Definition: gps_sentence.h:70
goby::util::gps::WPL::WPL
WPL(const NMEASentence &sentence)
Definition: gps_sentence.h:149
goby::util::gps::RMC::RMC
RMC(const NMEASentence &sentence)
Definition: gps_sentence.h:61
goby::util::gps::RTE::NAME
@ NAME
Definition: gps_sentence.h:207
goby::util::gps::WPL::serialize
NMEASentence serialize(std::string talker_id="EC") const
goby::util::gps::RTE::ROUTE_TYPE__INVALID
@ ROUTE_TYPE__INVALID
Definition: gps_sentence.h:196
goby::util::gps::HDT::min_size
constexpr static int min_size
Definition: gps_sentence.h:130
goby::util::gps::RMC::Status
Status
Definition: gps_sentence.h:92
goby::util::gps::RTE::type
RouteType type
Definition: gps_sentence.h:200
goby::util::gps::RMC::VALIDITY
@ VALIDITY
Definition: gps_sentence.h:78
goby::util::gps::RTE::RouteType
RouteType
Definition: gps_sentence.h:194
goby::util::gps::RMC
Definition: gps_sentence.h:56
goby::util::gps::RTE::RTE
RTE()=default
goby::util::gps::LON
@ LON
Definition: gps_sentence.h:50
goby::util::gps::nmea_geo_to_decimal
double nmea_geo_to_decimal(std::string nmea_geo_str, char hemi)
Convert NMEA latitude/longitude string plus hemisphere to a decimal degrees value.
goby::util::gps::HDT::HDT
HDT(const NMEASentence &sentence)
Definition: gps_sentence.h:118
goby::util::gps::RTE::total_number_sentences
boost::optional< int > total_number_sentences
Definition: gps_sentence.h:192
goby::util::gps::RMC::COURSE_OVER_GROUND
@ COURSE_OVER_GROUND
Definition: gps_sentence.h:84
goby::util::gps::RMC::time
boost::optional< goby::time::SystemClock::time_point > time
Definition: gps_sentence.h:66
goby::util::gps::RMC::LONGITUDE
@ LONGITUDE
Definition: gps_sentence.h:81
goby::util::gps::RTE::CURRENT_SENTENCE_INDEX
@ CURRENT_SENTENCE_INDEX
Definition: gps_sentence.h:205
goby::util::gps::WPL::size
constexpr static int size
Definition: gps_sentence.h:167
convert.h
goby::util::gps::RTE::Fields
Fields
Definition: gps_sentence.h:202
goby::util::gps::RTE::FIRST_WAYPOINT_NAME
@ FIRST_WAYPOINT_NAME
Definition: gps_sentence.h:208
goby::util::gps::RMC::MAG_VARIATION_EW
@ MAG_VARIATION_EW
Definition: gps_sentence.h:87
goby::util::gps::RMC::latitude
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > latitude
Definition: gps_sentence.h:68
goby::util::gps::operator<<
std::ostream & operator<<(std::ostream &os, const RMC &rmc)
Definition: gps_sentence.h:108
goby::util::gps::HDT::Fields
Fields
Definition: gps_sentence.h:125
goby::util::gps::RMC::DATE
@ DATE
Definition: gps_sentence.h:85
goby::util::gps::RMC::LONGITUDE_EW
@ LONGITUDE_EW
Definition: gps_sentence.h:82
goby::util::gps::HDT::size
constexpr static int size
Definition: gps_sentence.h:131
goby::util::gps::WPL
Definition: gps_sentence.h:144
goby::util::gps::WPL::LONGITUDE
@ LONGITUDE
Definition: gps_sentence.h:162
goby::util::gps::WPL::name
boost::optional< std::string > name
Definition: gps_sentence.h:156
goby::util::gps::RTE::name
boost::optional< std::string > name
Definition: gps_sentence.h:190
goby::util::gps::RMC::status
boost::optional< Status > status
Definition: gps_sentence.h:98
goby::util::gps::WPL::LONGITUDE_EW
@ LONGITUDE_EW
Definition: gps_sentence.h:163
goby::util::gps::WPL::latitude
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > latitude
Definition: gps_sentence.h:154
goby::util::gps::RTE::serialize
NMEASentence serialize(std::string talker_id="EC") const
goby::util::gps::WPL::NAME
@ NAME
Definition: gps_sentence.h:164
goby::util::gps::WPL::WPL
WPL()=default
goby::util::gps::WPL::LATITUDE_NS
@ LATITUDE_NS
Definition: gps_sentence.h:161
goby::util::gps::RMC::serialize
NMEASentence serialize(std::string talker_id="GP", int num_fields=min_size) const
goby::util::gps::RTE::ROUTE_TYPE__COMPLETE
@ ROUTE_TYPE__COMPLETE
Definition: gps_sentence.h:197
goby::util::gps::operator==
bool operator==(const RMC &rmc1, const RMC &rmc2)
Definition: gps_sentence.h:103
goby::util::gps::RTE::current_sentence_index
boost::optional< int > current_sentence_index
Definition: gps_sentence.h:193
goby::util::gps::RMC::Fields
Fields
Definition: gps_sentence.h:75
goby::util::gps::RTE
Definition: gps_sentence.h:180
goby::util::gps::RTE::ROUTE_TYPE__WORKING_ROUTE
@ ROUTE_TYPE__WORKING_ROUTE
Definition: gps_sentence.h:198
goby::util::gps::CoordType
CoordType
Definition: gps_sentence.h:47
goby::util::gps::HDT::serialize
NMEASentence serialize(std::string talker_id="GP") const
goby::util::gps::RMC::course_over_ground
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > course_over_ground
Definition: gps_sentence.h:71
goby::util::gps::RMC::longitude
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > longitude
Definition: gps_sentence.h:69
goby::util::NMEASentence::message
std::string message() const
goby::util::NMEASentence
Definition: nmea_sentence.h:51
goby::util::gps::WPL::min_size
constexpr static int min_size
Definition: gps_sentence.h:166
goby::util::gps::WPL::Fields
Fields
Definition: gps_sentence.h:158
goby::util::gps::HDT::T
@ T
Definition: gps_sentence.h:128
goby::util::gps::RMC::MODE
@ MODE
Definition: gps_sentence.h:88