SeaTalk: message 54 added.
[marnav.git] / src / marnav / seatalk / message_00.cpp
blobaf308d48aabf5eed6048205828b528674c7165d7
1 #include "message_00.hpp"
3 namespace marnav
5 namespace seatalk
8 message_00::message_00()
9 : message(ID)
10 , anchor_alarm_active(false)
11 , metric_display_units(false)
12 , transducer_defective(false)
13 , depth_alarm_active(false)
14 , shallow_depth_alarm_active(false)
15 , depth(0)
19 std::unique_ptr<message> message_00::parse(const raw & data)
21 if (data.size() != 5)
22 throw std::invalid_argument{"invalid number of bytes in message_00::parse"};
23 if (data[1] != 0x02)
24 throw std::invalid_argument{"invalid size specified in message"};
26 std::unique_ptr<message> result = utils::make_unique<message_00>();
27 message_00 & msg = static_cast<message_00 &>(*result);
29 const uint8_t flags = data[2];
30 msg.anchor_alarm_active = (flags & 0x80) != 0;
31 msg.metric_display_units = (flags & 0x40) != 0;
32 msg.transducer_defective = (flags & 0x04) != 0;
33 msg.depth_alarm_active = (flags & 0x02) != 0;
34 msg.shallow_depth_alarm_active = (flags & 0x01) != 0;
36 msg.depth = 0;
37 msg.depth += data[4];
38 msg.depth <<= 8;
39 msg.depth += data[3];
41 return result;
44 raw message_00::get_data() const
46 uint8_t flags = 0;
48 flags |= anchor_alarm_active ? 0x80 : 0x00;
49 flags |= metric_display_units ? 0x40 : 0x00;
50 flags |= transducer_defective ? 0x04 : 0x00;
51 flags |= depth_alarm_active ? 0x02 : 0x00;
52 flags |= shallow_depth_alarm_active ? 0x01 : 0x00;
54 return raw{static_cast<uint8_t>(ID), 0x02, flags, static_cast<uint8_t>((depth >> 0) & 0xff),
55 static_cast<uint8_t>((depth >> 8) & 0xff)};
58 double message_00::get_depth_meters() const noexcept
60 if (transducer_defective)
61 return 0.0;
62 return (static_cast<double>(depth) / 10.0) * 3.2808;