Build: add GCC-13, Clang-14, Clang-15, Clang-16, Clang-17
[marnav.git] / src / marnav / seatalk / message_00.cpp
blobf2d11529a5d4ebfe4668b07171cb213263749eac
1 #include <marnav/seatalk/message_00.hpp>
2 #include <cmath>
4 namespace marnav::seatalk
7 message_00::message_00()
8 : message(ID)
12 std::unique_ptr<message> message_00::parse(const raw & data)
14 check_size(data, SIZE);
16 std::unique_ptr<message> result = std::make_unique<message_00>();
17 auto & msg = static_cast<message_00 &>(*result);
19 const uint8_t flags = data[2];
20 msg.anchor_alarm_active_ = (flags & 0x80) != 0;
21 msg.metric_display_units_ = (flags & 0x40) != 0;
22 msg.transducer_defective_ = (flags & 0x04) != 0;
23 msg.depth_alarm_active_ = (flags & 0x02) != 0;
24 msg.shallow_depth_alarm_active_ = (flags & 0x01) != 0;
26 msg.depth_ = 0;
27 msg.depth_ += data[4];
28 msg.depth_ <<= 8;
29 msg.depth_ += data[3];
31 return result;
34 raw message_00::get_data() const
36 uint8_t flags = 0;
38 flags |= anchor_alarm_active_ ? 0x80 : 0x00;
39 flags |= metric_display_units_ ? 0x40 : 0x00;
40 flags |= transducer_defective_ ? 0x04 : 0x00;
41 flags |= depth_alarm_active_ ? 0x02 : 0x00;
42 flags |= shallow_depth_alarm_active_ ? 0x01 : 0x00;
44 return raw{static_cast<uint8_t>(ID), 0x02, flags,
45 static_cast<uint8_t>((depth_ >> 0) & 0xff), static_cast<uint8_t>((depth_ >> 8) & 0xff)};
48 double message_00::get_depth_meters() const noexcept
50 if (transducer_defective_)
51 return 0.0;
52 return (static_cast<double>(depth_) / 10.0) / 3.2808;
55 void message_00::set_depth_meters(double t) noexcept
57 if (t <= 0.0) {
58 depth_ = 0;
59 } else {
60 depth_ = static_cast<uint16_t>(std::round(10.0 * (t * 3.2808)));