Utils: bitset update to e865429e8a6c17366105e985fd037e42261a1af9.
[marnav.git] / src / marnav / ais / message_22.cpp
blob459d8bc3656bc2dfeb2837ede83bb17f5bbfb871
1 #include "message_22.hpp"
2 #include <algorithm>
3 #include <cmath>
4 #include <marnav/ais/angle.hpp>
6 namespace marnav
8 namespace ais
10 message_22::message_22()
11 : message(ID)
15 message_22::message_22(const raw & bits)
16 : message(ID)
18 if (bits.size() != SIZE_BITS)
19 throw std::invalid_argument{"invalid number of bits in message_22"};
20 read_data(bits);
23 void message_22::read_data(const raw & bits)
25 get(bits, repeat_indicator);
26 get(bits, mmsi);
27 get(bits, channel_a);
28 get(bits, channel_b);
29 get(bits, txrx_mode);
30 get(bits, power);
31 get(bits, addressed);
32 get(bits, band_a);
33 get(bits, band_b);
34 get(bits, zone_size);
36 if (addressed) {
37 get(bits, mmsi_1);
38 get(bits, mmsi_2);
39 } else {
40 get(bits, ne_lon);
41 get(bits, ne_lat);
42 get(bits, sw_lon);
43 get(bits, sw_lat);
47 raw message_22::get_data() const
49 raw bits(SIZE_BITS);
51 bits.set(type(), 0, 6);
52 set(bits, repeat_indicator);
53 set(bits, mmsi);
54 set(bits, channel_a);
55 set(bits, channel_b);
56 set(bits, txrx_mode);
57 set(bits, power);
58 set(bits, addressed);
59 set(bits, band_a);
60 set(bits, band_b);
61 set(bits, zone_size);
63 if (addressed) {
64 set(bits, mmsi_1);
65 set(bits, mmsi_2);
66 } else {
67 set(bits, ne_lon);
68 set(bits, ne_lat);
69 set(bits, sw_lon);
70 set(bits, sw_lat);
73 return bits;
76 utils::optional<geo::position> message_22::get_position_ne() const
78 if ((ne_lat == latitude_not_available_short) || (ne_lon == longitude_not_available_short))
79 return utils::make_optional<geo::position>();
81 return utils::make_optional<geo::position>(
82 to_geo_latitude(ne_lat, ne_lat.count, angle_scale::I1),
83 to_geo_longitude(ne_lon, ne_lon.count, angle_scale::I1));
86 utils::optional<geo::position> message_22::get_position_sw() const
88 if ((sw_lat == latitude_not_available_short) || (sw_lon == longitude_not_available_short))
89 return utils::make_optional<geo::position>();
91 return utils::make_optional<geo::position>(
92 to_geo_latitude(sw_lat, sw_lat.count, angle_scale::I1),
93 to_geo_longitude(sw_lon, sw_lon.count, angle_scale::I1));
96 void message_22::set_position_ne(const geo::position & t) noexcept
98 ne_lat = to_latitude_minutes(t.lat(), ne_lat.count, angle_scale::I1);
99 ne_lon = to_longitude_minutes(t.lon(), ne_lon.count, angle_scale::I1);
102 void message_22::set_position_sw(const geo::position & t) noexcept
104 sw_lat = to_latitude_minutes(t.lat(), sw_lat.count, angle_scale::I1);
105 sw_lon = to_longitude_minutes(t.lon(), sw_lon.count, angle_scale::I1);