1 #include <marnav/nmea/mwv.hpp>
3 #include <marnav/nmea/io.hpp>
7 constexpr sentence_id
mwv::ID
;
8 constexpr const char * mwv::TAG
;
11 : sentence(ID
, TAG
, talker::integrated_instrumentation
)
15 mwv::mwv(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
16 : sentence(ID
, TAG
, talk
)
18 if (std::distance(first
, last
) != 5)
19 throw std::invalid_argument
{"invalid number of fields in mwv"};
21 read(*(first
+ 0), angle_
);
22 read(*(first
+ 1), angle_ref_
);
23 read(*(first
+ 2), speed_
);
24 read(*(first
+ 3), speed_unit_
);
25 read(*(first
+ 4), data_valid_
);
28 void mwv::set_angle(double deg
, reference ref
)
30 check_value(ref
, {reference::TRUE
, reference::RELATIVE
}, "angle_ref");
35 void mwv::set_speed(units::velocity speed
, unit::velocity u
) noexcept
38 case unit::velocity::knot
:
39 set_speed(speed
.get
<units::knots
>());
41 case unit::velocity::kmh
:
42 set_speed(speed
.get
<units::kilometers_per_hour
>());
44 case unit::velocity::mps
:
45 set_speed(speed
.get
<units::meters_per_second
>());
50 void mwv::set_speed(units::knots speed
) noexcept
52 speed_
= speed
.value();
53 speed_unit_
= unit::velocity::knot
;
56 void mwv::set_speed(units::kilometers_per_hour speed
) noexcept
58 speed_
= speed
.value();
59 speed_unit_
= unit::velocity::kmh
;
62 void mwv::set_speed(units::meters_per_second speed
) noexcept
64 speed_
= speed
.value();
65 speed_unit_
= unit::velocity::mps
;
68 std::optional
<units::velocity
> mwv::get_speed() const
70 if (!speed_
|| !speed_unit_
)
73 switch (*speed_unit_
) {
74 case unit::velocity::knot
:
75 return {units::knots
{*speed_
}};
76 case unit::velocity::kmh
:
77 return {units::kilometers_per_hour
{*speed_
}};
78 case unit::velocity::mps
:
79 return {units::meters_per_second
{*speed_
}};
85 void mwv::append_data_to(std::string
& s
, const version
&) const
87 append(s
, to_string(angle_
));
88 append(s
, to_string(angle_ref_
));
89 append(s
, to_string(speed_
));
90 append(s
, to_string(speed_unit_
));
91 append(s
, to_string(data_valid_
));