2 #include <marnav/nmea/io.hpp>
3 #include <marnav/nmea/convert.hpp>
9 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(bwr
)
11 constexpr const char * bwr::TAG
;
14 : sentence(ID
, TAG
, talker_id::global_positioning_system
)
18 bwr::bwr(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
19 : sentence(ID
, TAG
, talk
)
21 const auto n
= std::distance(first
, last
);
22 if ((n
< 12) || (n
> 13))
23 throw std::invalid_argument
{"invalid number of fields in bwr"};
25 read(*(first
+ 0), time_utc
);
26 read(*(first
+ 1), lat
);
27 read(*(first
+ 2), lat_hem
);
28 read(*(first
+ 3), lon
);
29 read(*(first
+ 4), lon_hem
);
30 read(*(first
+ 5), bearing_true
);
31 read(*(first
+ 6), bearing_true_ref
);
32 read(*(first
+ 7), bearing_mag
);
33 read(*(first
+ 8), bearing_mag_ref
);
34 read(*(first
+ 9), distance
);
35 read(*(first
+ 10), distance_unit
);
36 read(*(first
+ 11), waypoint_id
);
39 read(*(first
+ 12), mode_ind
);
41 // instead of reading data into temporary lat/lon, let's correct values afterwards
42 lat
= correct_hemisphere(lat
, lat_hem
);
43 lon
= correct_hemisphere(lon
, lon_hem
);
46 utils::optional
<geo::longitude
> bwr::get_longitude() const
48 return (lon
&& lon_hem
) ? lon
: utils::optional
<geo::longitude
>{};
51 utils::optional
<geo::latitude
> bwr::get_latitude() const
53 return (lat
&& lat_hem
) ? lat
: utils::optional
<geo::latitude
>{};
56 void bwr::set_lat(const geo::latitude
& t
)
59 lat_hem
= convert_hemisphere(t
);
62 void bwr::set_lon(const geo::longitude
& t
)
65 lon_hem
= convert_hemisphere(t
);
68 void bwr::set_bearing_true(double t
) noexcept
71 bearing_true_ref
= reference::TRUE
;
74 void bwr::set_bearing_mag(double t
) noexcept
77 bearing_mag_ref
= reference::MAGNETIC
;
80 void bwr::set_distance(double t
) noexcept
83 distance_unit
= unit::distance::nm
;
86 std::vector
<std::string
> bwr::get_data() const
88 return {to_string(time_utc
), to_string(lat
), to_string(lat_hem
), to_string(lon
),
89 to_string(lon_hem
), to_string(bearing_true
), to_string(bearing_true_ref
),
90 to_string(bearing_mag
), to_string(bearing_mag_ref
), to_string(distance
),
91 to_string(distance_unit
), to_string(waypoint_id
), to_string(mode_ind
)};