1 #include <marnav/seatalk/message_51.hpp>
2 #include <marnav/math/floatingpoint.hpp>
4 namespace marnav::seatalk
7 message_51::message_51()
12 std::unique_ptr
<message
> message_51::parse(const raw
& data
)
14 check_size(data
, SIZE
);
16 std::unique_ptr
<message
> result
= std::make_unique
<message_51
>();
17 auto & msg
= static_cast<message_51
&>(*result
);
22 const uint32_t degrees
= data
[2];
28 const uint32_t minutes
= (m
& 0x7fff) / 100;
29 const uint32_t seconds
= (((m
& 0x7fff) % 100) * 60) / 100;
30 const geo::longitude::hemisphere hemisphere
31 = (m
& 0x8000) ? geo::longitude::hemisphere::east
: geo::longitude::hemisphere::west
;
33 msg
.lon_
= geo::longitude
{degrees
, minutes
, seconds
, hemisphere
};
35 // deliberately ignored 'Z'
40 raw
message_51::get_data() const
43 m
+= lon_
.minutes() * 100;
44 m
+= math::float_cast
<decltype(m
)>((lon_
.seconds() * 100) / 60);
45 if (lon_
.hem() == geo::longitude::hemisphere::east
)
48 return raw
{static_cast<uint8_t>(ID
), 0x02, static_cast<uint8_t>(lon_
.degrees() & 0xff),
49 static_cast<uint8_t>((m
>> 8) & 0xff), static_cast<uint8_t>((m
>> 0) & 0xff)};