Dev: preparation script added for code coverage.
[marnav.git] / src / marnav / ais / message_22.cpp
blobbcb78cf7165e18125eb3ea8b6fbbef0947cc2025
1 #include "message_22.hpp"
2 #include <algorithm>
3 #include <cmath>
4 #include <marnav/ais/angle.hpp>
6 namespace marnav
8 namespace ais
10 MARNAV_AIS_DEFINE_MESSAGE_PARSE_FUNC(message_22)
12 message_22::message_22()
13 : message(ID)
17 message_22::message_22(const raw & bits)
18 : message(ID)
20 if (bits.size() != SIZE_BITS)
21 throw std::invalid_argument{"invalid number of bits in message_22"};
22 read_data(bits);
25 void message_22::read_data(const raw & bits)
27 get(bits, repeat_indicator);
28 get(bits, mmsi);
29 get(bits, channel_a);
30 get(bits, channel_b);
31 get(bits, txrx_mode);
32 get(bits, power);
33 get(bits, addressed);
34 get(bits, band_a);
35 get(bits, band_b);
36 get(bits, zone_size);
38 if (addressed) {
39 get(bits, mmsi_1);
40 get(bits, mmsi_2);
41 } else {
42 get(bits, ne_lon);
43 get(bits, ne_lat);
44 get(bits, sw_lon);
45 get(bits, sw_lat);
49 raw message_22::get_data() const
51 raw bits{SIZE_BITS};
53 bits.set(type(), 0, 6);
54 set(bits, repeat_indicator);
55 set(bits, mmsi);
56 set(bits, channel_a);
57 set(bits, channel_b);
58 set(bits, txrx_mode);
59 set(bits, power);
60 set(bits, addressed);
61 set(bits, band_a);
62 set(bits, band_b);
63 set(bits, zone_size);
65 if (addressed) {
66 set(bits, mmsi_1);
67 set(bits, mmsi_2);
68 } else {
69 set(bits, ne_lon);
70 set(bits, ne_lat);
71 set(bits, sw_lon);
72 set(bits, sw_lat);
75 return bits;
78 geo::position message_22::get_position_ne() const noexcept
80 return {geo::latitude{ne_lat / (60.0 * 10.0)}, geo::longitude{ne_lon / (60.0 * 10.0)}};
83 geo::position message_22::get_position_sw() const noexcept
85 return {geo::latitude{sw_lat / (60.0 * 10.0)}, geo::longitude{sw_lon / (60.0 * 10.0)}};
88 void message_22::set_position_ne(const geo::position & t) noexcept
90 ne_lat = std::floor(60.0 * 10.0 * t.lat());
91 ne_lon = std::floor(60.0 * 10.0 * t.lon());
94 void message_22::set_position_sw(const geo::position & t) noexcept
96 sw_lat = std::floor(60.0 * 10.0 * t.lat());
97 sw_lon = std::floor(60.0 * 10.0 * t.lon());