1 #include <marnav/nmea/wpl.hpp>
3 #include <marnav/nmea/io.hpp>
10 constexpr sentence_id
wpl::ID
;
11 constexpr const char * wpl::TAG
;
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_lon() const
37 return (lon_
&& lon_hem_
) ? lon_
: utils::optional
<geo::longitude
>{};
40 utils::optional
<geo::latitude
> wpl::get_lat() const
42 return (lat_
&& lat_hem_
) ? lat_
: utils::optional
<geo::latitude
>{};
45 void wpl::set_lat(const geo::latitude
& t
)
48 lat_hem_
= convert_hemisphere(t
);
51 void wpl::set_lon(const geo::longitude
& t
)
54 lon_hem_
= convert_hemisphere(t
);
57 void wpl::append_data_to(std::string
& s
) const
59 append(s
, to_string(lat_
));
60 append(s
, to_string(lat_hem_
));
61 append(s
, to_string(lon_
));
62 append(s
, to_string(lon_hem_
));
63 append(s
, to_string(waypoint_id_
));