1 #include <marnav/nmea/gga.hpp>
4 #include <marnav/nmea/io.hpp>
10 constexpr sentence_id
gga::ID
;
11 constexpr const char * gga::TAG
;
14 : sentence(ID
, TAG
, talker::global_positioning_system
)
18 gga::gga(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
19 : sentence(ID
, TAG
, talk
)
21 if (std::distance(first
, last
) != 14)
22 throw std::invalid_argument
{"invalid number of fields in gga"};
24 utils::optional
<unit::distance
> altitude_unit
;
25 utils::optional
<unit::distance
> geodial_separation_unit
;
27 read(*(first
+ 0), time_
);
28 read(*(first
+ 1), lat_
);
29 read(*(first
+ 2), lat_hem_
);
30 read(*(first
+ 3), lon_
);
31 read(*(first
+ 4), lon_hem_
);
32 read(*(first
+ 5), quality_indicator_
);
33 read(*(first
+ 6), n_satellites_
);
34 read(*(first
+ 7), hor_dilution_
);
35 read(*(first
+ 8), altitude_
);
36 read(*(first
+ 9), altitude_unit
);
37 read(*(first
+ 10), geodial_separation_
);
38 read(*(first
+ 11), geodial_separation_unit
);
39 read(*(first
+ 12), dgps_age_
);
40 read(*(first
+ 13), dgps_ref_
);
42 check_value(altitude_unit
, {unit::distance::meter
}, "altitude unit");
43 check_value(geodial_separation_unit
, {unit::distance::meter
}, "geodial separation unit");
45 // instead of reading data into temporary lat/lon, let's correct values afterwards
46 lat_
= correct_hemisphere(lat_
, lat_hem_
);
47 lon_
= correct_hemisphere(lon_
, lon_hem_
);
50 utils::optional
<geo::longitude
> gga::get_lon() const
52 return (lon_
&& lon_hem_
) ? lon_
: utils::optional
<geo::longitude
>{};
55 utils::optional
<geo::latitude
> gga::get_lat() const
57 return (lat_
&& lat_hem_
) ? lat_
: utils::optional
<geo::latitude
>{};
60 void gga::set_lat(const geo::latitude
& t
)
63 lat_hem_
= convert_hemisphere(t
);
66 void gga::set_lon(const geo::longitude
& t
)
69 lon_hem_
= convert_hemisphere(t
);
72 utils::optional
<units::length
> gga::get_altitude() const
79 utils::optional
<units::length
> gga::get_geodial_separation() const
81 if (!geodial_separation_
)
83 return {*geodial_separation_
};
86 void gga::append_data_to(std::string
& s
) const
88 append(s
, to_string(time_
));
89 append(s
, to_string(lat_
));
90 append(s
, to_string(lat_hem_
));
91 append(s
, to_string(lon_
));
92 append(s
, to_string(lon_hem_
));
93 append(s
, to_string(quality_indicator_
));
94 append(s
, to_string(n_satellites_
));
95 append(s
, to_string(hor_dilution_
));
96 append(s
, to_string(altitude_
));
97 append(s
, to_string_if(unit::distance::meter
, altitude_
));
98 append(s
, to_string(geodial_separation_
));
99 append(s
, to_string_if(unit::distance::meter
, geodial_separation_
));
100 append(s
, to_string(dgps_age_
));
101 append(s
, to_string(dgps_ref_
));