Debian Codegraph @

src/libais/ais1_2_3.cpp

raw symbols SCIP
1 // Since Apr 2010
2
3 #include <cmath>
4
5 #include "ais.h"
6
7 using std::abs;
8
9 namespace libais {
10
11 Ais1_2_3::Ais1_2_3(const char *nmea_payload, const size_t pad)
12 : AisMsg(nmea_payload, pad), nav_status(0), rot_over_range(false),
13 rot_raw(0), rot(0.0), sog(0.0), position_accuracy(0),
14 cog(0.0), true_heading(0), timestamp(0), special_manoeuvre(0), spare(0),
15 raim(false), sync_state(0),
16 slot_timeout_valid(false), slot_timeout(0),
17 received_stations_valid(false), received_stations(0),
18 slot_number_valid(false), slot_number(0),
19 utc_valid(false), utc_hour(0), utc_min(0), utc_spare(0),
20 slot_offset_valid(false), slot_offset(0),
21 slot_increment_valid(false), slot_increment(0),
22 slots_to_allocate_valid(false), slots_to_allocate(0),
23 keep_flag_valid(false), keep_flag(false) {
24 if (!CheckStatus()) {
25 return;
26 }
27 if (pad != 0 || num_chars != 28) {
28 status = AIS_ERR_BAD_BIT_COUNT;
29 return;
30 }
31
32 assert(message_id >= 1 && message_id <= 3);
33
34 bits.SeekTo(38);
35 nav_status = bits.ToUnsignedInt(38, 4);
36
37 rot_raw = bits.ToInt(42, 8);
38 rot_over_range = abs(rot_raw) > 126 ? true : false;
39 rot = pow((rot_raw/4.733), 2);
40 if (rot_raw < 0) rot = -rot;
41
42 sog = bits.ToUnsignedInt(50, 10) / 10.0; // Knots.
43 position_accuracy = bits[60];
44 position = bits.ToAisPoint(61, 55);
45 cog = bits.ToUnsignedInt(116, 12) / 10.0; // Degrees.
46 true_heading = bits.ToUnsignedInt(128, 9);
47 timestamp = bits.ToUnsignedInt(137, 6);
48 special_manoeuvre = bits.ToUnsignedInt(143, 2);
49 spare = bits.ToUnsignedInt(145, 3);
50 raim = bits[148];
51
52 sync_state = bits.ToUnsignedInt(149, 2);
53
54 if (message_id == 1 || message_id == 2) {
55 slot_timeout = bits.ToUnsignedInt(151, 3);
56 slot_timeout_valid = true;
57
58 switch (slot_timeout) {
59 case 0:
60 slot_offset = bits.ToUnsignedInt(154, 14);
61 slot_offset_valid = true;
62 break;
63 case 1:
64 utc_hour = bits.ToUnsignedInt(154, 5);
65 utc_min = bits.ToUnsignedInt(159, 7);
66 utc_spare = bits.ToUnsignedInt(166, 2);
67 utc_valid = true;
68 break;
69 case 2: // FALLTHROUGH
70 case 4: // FALLTHROUGH
71 case 6:
72 slot_number = bits.ToUnsignedInt(154, 14);
73 slot_number_valid = true;
74 break;
75 case 3: // FALLTHROUGH
76 case 5: // FALLTHROUGH
77 case 7:
78 received_stations = bits.ToUnsignedInt(154, 14);
79 received_stations_valid = true;
80 break;
81 default:
82 assert(false);
83 }
84 } else {
85 // ITDMA
86 slot_increment = bits.ToUnsignedInt(151, 13);
87 slot_increment_valid = true;
88
89 slots_to_allocate = bits.ToUnsignedInt(164, 3);
90 slots_to_allocate_valid = true;
91
92 keep_flag = bits[167];
93 keep_flag_valid = true;
94 }
95
96 assert(bits.GetRemaining() == 0);
97
98 status = AIS_OK;
99 }
100
101 ostream& operator<< (ostream &o, const Ais1_2_3 &msg) {
102 return o << msg.message_id << ": " << msg.mmsi;
103 }
104
105 } // namespace libais