1 #include <marnav/nmea/mwv.hpp>
3 #include <marnav/nmea/io.hpp>
9 constexpr sentence_id
mwv::ID
;
10 constexpr const char * mwv::TAG
;
13 : sentence(ID
, TAG
, talker::integrated_instrumentation
)
17 mwv::mwv(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
18 : sentence(ID
, TAG
, talk
)
20 if (std::distance(first
, last
) != 5)
21 throw std::invalid_argument
{"invalid number of fields in mwv"};
23 read(*(first
+ 0), angle_
);
24 read(*(first
+ 1), angle_ref_
);
25 read(*(first
+ 2), speed_
);
26 read(*(first
+ 3), speed_unit_
);
27 read(*(first
+ 4), data_valid_
);
30 void mwv::set_angle(double deg
, reference ref
)
32 check_value(ref
, {reference::TRUE
, reference::RELATIVE
}, "angle_ref");
37 void mwv::set_speed(units::velocity speed
, unit::velocity u
) noexcept
40 case unit::velocity::knot
:
41 set_speed(speed
.get
<units::knots
>());
43 case unit::velocity::kmh
:
44 set_speed(speed
.get
<units::kilometers_per_hour
>());
46 case unit::velocity::mps
:
47 set_speed(speed
.get
<units::meters_per_second
>());
52 void mwv::set_speed(units::knots speed
) noexcept
54 speed_
= speed
.value();
55 speed_unit_
= unit::velocity::knot
;
58 void mwv::set_speed(units::kilometers_per_hour speed
) noexcept
60 speed_
= speed
.value();
61 speed_unit_
= unit::velocity::kmh
;
64 void mwv::set_speed(units::meters_per_second speed
) noexcept
66 speed_
= speed
.value();
67 speed_unit_
= unit::velocity::mps
;
70 std::optional
<units::velocity
> mwv::get_speed() const
72 if (!speed_
|| !speed_unit_
)
75 switch (*speed_unit_
) {
76 case unit::velocity::knot
:
77 return {units::knots
{*speed_
}};
78 case unit::velocity::kmh
:
79 return {units::kilometers_per_hour
{*speed_
}};
80 case unit::velocity::mps
:
81 return {units::meters_per_second
{*speed_
}};
87 void mwv::append_data_to(std::string
& s
, const version
&) const
89 append(s
, to_string(angle_
));
90 append(s
, to_string(angle_ref_
));
91 append(s
, to_string(speed_
));
92 append(s
, to_string(speed_unit_
));
93 append(s
, to_string(data_valid_
));