Utils: bitset update to e865429e8a6c17366105e985fd037e42261a1af9.
[marnav.git] / src / marnav / ais / message_23.cpp
blobd4cf9f44371ddbf4c85694541b0b02a7966f3afd
1 #include "message_23.hpp"
2 #include <algorithm>
3 #include <cmath>
4 #include <marnav/ais/angle.hpp>
6 namespace marnav
8 namespace ais
10 message_23::message_23()
11 : message(ID)
15 message_23::message_23(const raw & bits)
16 : message(ID)
18 if (bits.size() != SIZE_BITS)
19 throw std::invalid_argument{"invalid number of bits in message_23"};
20 read_data(bits);
23 void message_23::read_data(const raw & bits)
25 get(bits, repeat_indicator);
26 get(bits, mmsi);
27 get(bits, ne_lon);
28 get(bits, ne_lat);
29 get(bits, sw_lon);
30 get(bits, sw_lat);
31 get(bits, station_type);
32 get(bits, shiptype);
33 get(bits, txrx_mode);
34 get(bits, interval);
35 get(bits, quiet_time);
38 raw message_23::get_data() const
40 raw bits(SIZE_BITS);
42 bits.set(type(), 0, 6);
43 set(bits, repeat_indicator);
44 set(bits, mmsi);
45 set(bits, ne_lon);
46 set(bits, ne_lat);
47 set(bits, sw_lon);
48 set(bits, sw_lat);
49 set(bits, station_type);
50 set(bits, shiptype);
51 set(bits, txrx_mode);
52 set(bits, interval);
53 set(bits, quiet_time);
55 return bits;
58 utils::optional<geo::position> message_23::get_position_ne() const
60 if ((ne_lat == latitude_not_available_short) || (ne_lon == longitude_not_available_short))
61 return utils::make_optional<geo::position>();
63 return utils::make_optional<geo::position>(
64 to_geo_latitude(ne_lat, ne_lat.count, angle_scale::I1),
65 to_geo_longitude(ne_lon, ne_lon.count, angle_scale::I1));
68 utils::optional<geo::position> message_23::get_position_sw() const
70 if ((sw_lat == latitude_not_available_short) || (sw_lon == longitude_not_available_short))
71 return utils::make_optional<geo::position>();
73 return utils::make_optional<geo::position>(
74 to_geo_latitude(sw_lat, sw_lat.count, angle_scale::I1),
75 to_geo_longitude(sw_lon, sw_lon.count, angle_scale::I1));
78 void message_23::set_position_ne(const geo::position & t) noexcept
80 ne_lat = to_latitude_minutes(t.lat(), ne_lat.count, angle_scale::I1);
81 ne_lon = to_longitude_minutes(t.lon(), ne_lon.count, angle_scale::I1);
84 void message_23::set_position_sw(const geo::position & t) noexcept
86 sw_lat = to_latitude_minutes(t.lat(), sw_lat.count, angle_scale::I1);
87 sw_lon = to_longitude_minutes(t.lon(), sw_lon.count, angle_scale::I1);