NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / wpl.cpp
blob2613fae2bf1bfe19fb564f7a65efe50ec04f1ddc
1 #include "wpl.hpp"
2 #include <marnav/nmea/io.hpp>
3 #include <marnav/nmea/convert.hpp>
5 namespace marnav
7 namespace nmea
9 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(wpl)
11 constexpr const char * wpl::TAG;
13 wpl::wpl()
14 : sentence(ID, TAG, talker_id::global_positioning_system)
18 wpl::wpl(talker talk, fields::const_iterator first, fields::const_iterator last)
19 : sentence(ID, TAG, talk)
21 if (std::distance(first, last) != 5)
22 throw std::invalid_argument{"invalid number of fields in wpl"};
24 read(*(first + 0), lat);
25 read(*(first + 1), lat_hem);
26 read(*(first + 2), lon);
27 read(*(first + 3), lon_hem);
28 read(*(first + 4), waypoint_id);
30 // instead of reading data into temporary lat/lon, let's correct values afterwards
31 lat = correct_hemisphere(lat, lat_hem);
32 lon = correct_hemisphere(lon, lon_hem);
35 utils::optional<geo::longitude> wpl::get_longitude() const
37 return (lon && lon_hem) ? lon : utils::optional<geo::longitude>{};
40 utils::optional<geo::latitude> wpl::get_latitude() const
42 return (lat && lat_hem) ? lat : utils::optional<geo::latitude>{};
45 void wpl::set_lat(const geo::latitude & t)
47 lat = t;
48 lat_hem = convert_hemisphere(t);
51 void wpl::set_lon(const geo::longitude & t)
53 lon = t;
54 lon_hem = convert_hemisphere(t);
57 std::vector<std::string> wpl::get_data() const
59 return {to_string(lat), to_string(lat_hem), to_string(lon), to_string(lon_hem),
60 to_string(waypoint_id)};