Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
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"
36#include "nmea_sentence.h"
37
38namespace goby
39{
40namespace util
41{
42namespace gps
43{
45double nmea_geo_to_decimal(std::string nmea_geo_str, char hemi);
46
48{
50 LON
51};
52
54std::pair<std::string, char> decimal_to_nmea_geo(double decimal, CoordType t);
55
56struct 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 {
85 DATE = 9,
88 MODE = 12, // NMEA 2.3 and later
89 NAV_STATUS = 13 // NMEA 4.1 and later
90 };
91
97
98 boost::optional<Status> status;
99
100 constexpr static int min_size = MAG_VARIATION_EW + 1; // MAG_VARIATION_EW + talker
101};
102
103inline bool operator==(const RMC& rmc1, const RMC& rmc2)
104{
105 return rmc1.serialize().message() == rmc2.serialize().message();
106}
107
108inline std::ostream& operator<<(std::ostream& os, const RMC& rmc)
109{
110 return (os << rmc.serialize().message());
111}
112
113struct 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
126 {
128 T = 2
129 };
130 constexpr static int min_size = HEADING + 1; // HEADING + talker
131 constexpr static int size = T + 1;
132};
133
134inline bool operator==(const HDT& hdt1, const HDT& hdt2)
135{
136 return hdt1.serialize().message() == hdt2.serialize().message();
137}
138
139inline std::ostream& operator<<(std::ostream& os, const HDT& hdt)
140{
141 return (os << hdt.serialize().message());
142}
143
144struct 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
166 constexpr static int min_size = NAME + 1; // NAME + talker
167 constexpr static int size = min_size;
168};
169
170inline bool operator==(const WPL& wpl1, const WPL& wpl2)
171{
172 return wpl1.serialize().message() == wpl2.serialize().message();
173}
174
175inline std::ostream& operator<<(std::ostream& os, const WPL& wpl)
176{
177 return (os << wpl.serialize().message());
178}
179
180struct 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
201
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
214inline bool operator==(const RTE& rte1, const RTE& rte2)
215{
216 return rte1.serialize().message() == rte2.serialize().message();
217}
218
219inline 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
std::string message() const
double nmea_geo_to_decimal(std::string nmea_geo_str, char hemi)
Convert NMEA latitude/longitude string plus hemisphere to a decimal degrees value.
bool operator==(const RMC &rmc1, const RMC &rmc2)
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...
The global namespace for the Goby project.
NMEASentence serialize(std::string talker_id="GP") const
void parse(const NMEASentence &sentence)
static constexpr int min_size
HDT(const NMEASentence &sentence)
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > true_heading
static constexpr int size
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > course_over_ground
static constexpr int min_size
RMC(const NMEASentence &sentence)
boost::optional< Status > status
boost::optional< boost::units::quantity< boost::units::si::velocity > > speed_over_ground
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > latitude
void parse(const NMEASentence &sentence)
NMEASentence serialize(std::string talker_id="GP", int num_fields=min_size) const
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > magnetic_variation
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > longitude
boost::optional< goby::time::SystemClock::time_point > time
void parse(const NMEASentence &sentence)
static constexpr int min_size
std::vector< std::string > waypoint_names
NMEASentence serialize(std::string talker_id="EC") const
RTE(const NMEASentence &sentence)
boost::optional< std::string > name
boost::optional< int > current_sentence_index
boost::optional< int > total_number_sentences
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > longitude
NMEASentence serialize(std::string talker_id="EC") const
static constexpr int min_size
boost::optional< boost::units::quantity< boost::units::degree::plane_angle > > latitude
static constexpr int size
void parse(const NMEASentence &sentence)
boost::optional< std::string > name
WPL(const NMEASentence &sentence)