General: reorganization of header files
[marnav.git] / src / marnav / seatalk / message_50.cpp
blob75c06e94412921ef64d4e723a2cb279997ec1856
1 #include <marnav/seatalk/message_50.hpp>
3 namespace marnav
5 namespace seatalk
8 message_50::message_50()
9 : message(ID)
13 std::unique_ptr<message> message_50::parse(const raw & data)
15 check_size(data, SIZE);
17 std::unique_ptr<message> result = utils::make_unique<message_50>();
18 message_50 & msg = static_cast<message_50 &>(*result);
20 // 50 Z2 XX YY YY
21 // raw 1 2 3 4
23 const uint32_t degrees = data[2];
24 uint32_t m = 0;
25 m += data[3];
26 m <<= 8;
27 m += data[4];
29 const uint32_t minutes = (m & 0x7fff) / 100;
30 const uint32_t seconds = (((m & 0x7fff) % 100) * 60) / 100;
31 const geo::latitude::hemisphere hemisphere
32 = (m & 0x8000) ? geo::latitude::hemisphere::south : geo::latitude::hemisphere::north;
34 msg.lat_ = geo::latitude{degrees, minutes, seconds, hemisphere};
36 // deliberately ignored 'Z'
38 return result;
41 raw message_50::get_data() const
43 uint16_t m = 0;
44 m += lat_.minutes() * 100;
45 m += (lat_.seconds() * 100) / 60;
46 if (lat_.hem() == geo::latitude::hemisphere::south)
47 m |= 0x8000;
49 return raw{static_cast<uint8_t>(ID), 0x02, static_cast<uint8_t>(lat_.degrees() & 0xff),
50 static_cast<uint8_t>((m >> 8) & 0xff), static_cast<uint8_t>((m >> 0) & 0xff)};