Build: add GCC-13, Clang-14, Clang-15, Clang-16, Clang-17
[marnav.git] / src / marnav / nmea / mwv.cpp
blobb0ef80002369751f2b05a8374a982df07863fb1e
1 #include <marnav/nmea/mwv.hpp>
2 #include "checks.hpp"
3 #include <marnav/nmea/io.hpp>
5 namespace marnav::nmea
7 constexpr sentence_id mwv::ID;
8 constexpr const char * mwv::TAG;
10 mwv::mwv()
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");
31 angle_ = deg;
32 angle_ref_ = ref;
35 void mwv::set_speed(units::velocity speed, unit::velocity u) noexcept
37 switch (u) {
38 case unit::velocity::knot:
39 set_speed(speed.get<units::knots>());
40 break;
41 case unit::velocity::kmh:
42 set_speed(speed.get<units::kilometers_per_hour>());
43 break;
44 case unit::velocity::mps:
45 set_speed(speed.get<units::meters_per_second>());
46 break;
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_)
71 return {};
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_}};
82 return {};
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_));