General: reorganization of header files
[marnav.git] / src / marnav / ais / message_23.cpp
blob252a82cd3f83edb4f939cc7f4a6777030a9ac9a8
1 #include <marnav/ais/message_23.hpp>
2 #include <marnav/ais/angle.hpp>
3 #include <algorithm>
4 #include <cmath>
6 namespace marnav
8 namespace ais
10 constexpr message_id message_23::ID;
11 constexpr std::size_t message_23::SIZE_BITS;
13 message_23::message_23()
14 : message(ID)
18 message_23::message_23(const raw & bits)
19 : message(ID)
21 if (bits.size() != SIZE_BITS)
22 throw std::invalid_argument{"invalid number of bits in message_23"};
23 read_data(bits);
26 void message_23::read_data(const raw & bits)
28 get(bits, repeat_indicator);
29 get(bits, mmsi);
30 get(bits, ne_lon);
31 get(bits, ne_lat);
32 get(bits, sw_lon);
33 get(bits, sw_lat);
34 get(bits, station_type);
35 get(bits, shiptype);
36 get(bits, txrx_mode);
37 get(bits, interval);
38 get(bits, quiet_time);
41 raw message_23::get_data() const
43 raw bits(SIZE_BITS);
45 bits.set(type(), 0, 6);
46 set(bits, repeat_indicator);
47 set(bits, mmsi);
48 set(bits, ne_lon);
49 set(bits, ne_lat);
50 set(bits, sw_lon);
51 set(bits, sw_lat);
52 set(bits, station_type);
53 set(bits, shiptype);
54 set(bits, txrx_mode);
55 set(bits, interval);
56 set(bits, quiet_time);
58 return bits;
61 utils::optional<geo::position> message_23::get_position_ne() const
63 if ((ne_lat == latitude_not_available_short) || (ne_lon == longitude_not_available_short))
64 return utils::make_optional<geo::position>();
66 return utils::make_optional<geo::position>(
67 to_geo_latitude(ne_lat, ne_lat.count, angle_scale::I1),
68 to_geo_longitude(ne_lon, ne_lon.count, angle_scale::I1));
71 utils::optional<geo::position> message_23::get_position_sw() const
73 if ((sw_lat == latitude_not_available_short) || (sw_lon == longitude_not_available_short))
74 return utils::make_optional<geo::position>();
76 return utils::make_optional<geo::position>(
77 to_geo_latitude(sw_lat, sw_lat.count, angle_scale::I1),
78 to_geo_longitude(sw_lon, sw_lon.count, angle_scale::I1));
81 void message_23::set_position_ne(const geo::position & t) noexcept
83 ne_lat = to_latitude_minutes(t.lat(), ne_lat.count, angle_scale::I1);
84 ne_lon = to_longitude_minutes(t.lon(), ne_lon.count, angle_scale::I1);
87 void message_23::set_position_sw(const geo::position & t) noexcept
89 sw_lat = to_latitude_minutes(t.lat(), sw_lat.count, angle_scale::I1);
90 sw_lon = to_longitude_minutes(t.lon(), sw_lon.count, angle_scale::I1);