Refactor: code duplication reduced for size check of seatalk messages
[marnav.git] / src / marnav / seatalk / message_26.hpp
blob58e744a84a5d485da229b70333e0b3aeee2e86e6
1 #ifndef __SEATALK__MESSAGE_26__HPP__
2 #define __SEATALK__MESSAGE_26__HPP__
4 #include <marnav/seatalk/message.hpp>
6 namespace marnav
8 namespace seatalk
11 /// @brief Speed through water
12 ///
13 /// @code
14 /// 26 04 XX XX YY YY DE
15 ///
16 /// XXXX/100 Knots, sensor 1, current speed, valid if D & 4 == 4
17 /// YYYY/100 Knots, average speed (trip/time) if D & 8 == 0
18 /// or data from sensor 2 if D & 8 == 8
19 /// E & 1 == 1: Average speed calulation stopped
20 /// E & 2 == 2: Display value in MPH
21 /// @endcode
22 ///
23 /// Corresponding NMEA sentence: VHW
24 ///
25 class message_26 : public message
27 public:
28 constexpr static const message_id ID = message_id::speed_through_water_2;
29 constexpr static size_t SIZE = 7;
31 message_26();
32 message_26(const message_26 &) = default;
33 message_26 & operator=(const message_26 &) = default;
35 virtual raw get_data() const override;
37 static std::unique_ptr<message> parse(const raw & data);
39 private:
40 uint16_t speed1;
41 uint16_t speed2;
42 uint8_t status;
44 public:
45 bool is_display_in_mph() const noexcept { return (status & 0x02) != 0; }
46 bool avg_speed_calc_stopped() const noexcept { return (status & 0x01) != 0; }
47 bool is_sensor1_valid() const noexcept { return (status & 0x40) != 0; }
48 bool is_avg_valid() const noexcept { return (status & 0x80) == 0; }
49 bool is_sensor2_valid() const noexcept { return (status & 0x80) != 0; }
51 double get_speed1() const noexcept;
52 double get_speed2() const noexcept;
54 void set_display_in_mph(bool t) noexcept;
55 void set_avg_speed_calc_stopped(bool t) noexcept;
56 void set_sensor1_valid(bool t) noexcept;
57 void set_avg_valid() noexcept { status &= ~0x80; }
58 void set_sensor2_valid() noexcept { status |= 0x80; }
60 void set_speed1(double t) noexcept;
61 void set_speed2(double t) noexcept;
66 #endif