SeaTalk: message 54 added.
[marnav.git] / src / marnav / seatalk / message_27.cpp
blob3bf1d9d165a554532c06785b9775cdede260bd53
1 #include "message_27.hpp"
3 namespace marnav
5 namespace seatalk
8 message_27::message_27()
9 : message(ID)
10 , temperature(0)
14 std::unique_ptr<message> message_27::parse(const raw & data)
16 if (data.size() != 4)
17 throw std::invalid_argument{"invalid number of bytes in message_27::parse"};
18 if (data[1] != 0x01)
19 throw std::invalid_argument{"invalid size specified in message"};
21 std::unique_ptr<message> result = utils::make_unique<message_27>();
22 message_27 & msg = static_cast<message_27 &>(*result);
24 uint16_t value = 0;
25 value += data[2];
26 value <<= 8;
27 value += data[3];
29 msg.temperature = value;
30 msg.temperature -= 100;
32 return result;
35 raw message_27::get_data() const
37 uint16_t value = (temperature + 100) & 0xffff;
39 return raw{static_cast<uint8_t>(ID), 0x01, static_cast<uint8_t>((value >> 8) & 0xff),
40 static_cast<uint8_t>((value >> 0) & 0xff)};