General: reorganization of header files
[marnav.git] / src / marnav / nmea / mwd.cpp
blobe0b7ac535163b4a4c3527eb4773522b490ed7ba7
1 #include <marnav/nmea/mwd.hpp>
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 constexpr sentence_id mwd::ID;
9 constexpr const char * mwd::TAG;
11 mwd::mwd()
12 : sentence(ID, TAG, talker_id::weather_instruments)
16 mwd::mwd(talker talk, fields::const_iterator first, fields::const_iterator last)
17 : sentence(ID, TAG, talk)
19 if (std::distance(first, last) != 8)
20 throw std::invalid_argument{"invalid number of fields in mwd"};
22 read(*(first + 0), direction_true_);
23 read(*(first + 1), direction_true_ref_);
24 read(*(first + 2), direction_mag_);
25 read(*(first + 3), direction_mag_ref_);
26 read(*(first + 4), speed_kn_);
27 read(*(first + 5), speed_kn_unit_);
28 read(*(first + 6), speed_ms_);
29 read(*(first + 7), speed_ms_unit_);
32 void mwd::set_direction_true(double t) noexcept
34 direction_true_ = t;
35 direction_true_ref_ = reference::TRUE;
38 void mwd::set_direction_mag(double t) noexcept
40 direction_mag_ = t;
41 direction_mag_ref_ = reference::MAGNETIC;
44 void mwd::set_speed_knots(double t) noexcept
46 speed_kn_ = t;
47 speed_kn_unit_ = unit::velocity::knot;
50 void mwd::set_speed_mps(double t) noexcept
52 speed_ms_ = t;
53 speed_ms_unit_ = unit::velocity::mps;
56 void mwd::append_data_to(std::string & s) const
58 append(s, format(direction_true_, 1));
59 append(s, to_string(direction_true_ref_));
60 append(s, format(direction_mag_, 1));
61 append(s, to_string(direction_mag_ref_));
62 append(s, format(speed_kn_, 1));
63 append(s, to_string(speed_kn_unit_));
64 append(s, format(speed_ms_, 1));
65 append(s, to_string(speed_ms_unit_));