Debian Codegraph @

src/libais/ais9.cpp

raw symbols SCIP
1 #include "ais.h"
2
3 namespace libais {
4
5 Ais9::Ais9(const char *nmea_payload, const size_t pad)
6 : AisMsg(nmea_payload, pad), alt(0), sog(0.0), position_accuracy(0),
7 cog(0.0), timestamp(0), alt_sensor(0), spare(0), dte(0), spare2(0),
8 assigned_mode(0), raim(false), commstate_flag(0), sync_state(0),
9 slot_timeout_valid(false), slot_timeout(0),
10 received_stations_valid(false), received_stations(0),
11 slot_number_valid(false), slot_number(0),
12 utc_valid(false), utc_hour(0), utc_min(0), utc_spare(0),
13 slot_offset_valid(false), slot_offset(0),
14 slot_increment_valid(false), slot_increment(0),
15 slots_to_allocate_valid(false), slots_to_allocate(0),
16 keep_flag_valid(false), keep_flag(false) {
17 if (!CheckStatus()) {
18 return;
19 }
20 if (pad != 0 || num_chars != 28) {
21 status = AIS_ERR_BAD_BIT_COUNT;
22 return;
23 }
24
25 assert(message_id == 9);
26
27 bits.SeekTo(38);
28 alt = bits.ToUnsignedInt(38, 12);
29 sog = bits.ToUnsignedInt(50, 10); // Type 9: Speed over ground is in knots.
30
31 position_accuracy = bits[60];
32 position = bits.ToAisPoint(61, 55);
33
34 cog = bits.ToUnsignedInt(116, 12) / 10.;
35 timestamp = bits.ToUnsignedInt(128, 6);
36 alt_sensor = bits[134];
37 spare = bits.ToUnsignedInt(135, 7);
38 dte = bits[142];
39 spare2 = bits.ToUnsignedInt(143, 3);
40 assigned_mode = bits[146];
41 raim = bits[147];
42 commstate_flag = bits[148]; // 0 SOTDMA, 1 ITDMA
43
44 sync_state = bits.ToUnsignedInt(149, 2);
45
46 if (commstate_flag == 0) {
47 // SOTDMA
48 slot_timeout = bits.ToUnsignedInt(151, 3);
49 slot_timeout_valid = true;
50
51 switch (slot_timeout) {
52 case 0:
53 slot_offset = bits.ToUnsignedInt(154, 14);
54 slot_offset_valid = true;
55 break;
56 case 1:
57 utc_hour = bits.ToUnsignedInt(154, 5);
58 utc_min = bits.ToUnsignedInt(159, 7);
59 utc_spare = bits.ToUnsignedInt(166, 2);
60 utc_valid = true;
61 break;
62 case 2: // FALLTHROUGH
63 case 4: // FALLTHROUGH
64 case 6:
65 slot_number = bits.ToUnsignedInt(154, 14);
66 slot_number_valid = true;
67 break;
68 case 3: // FALLTHROUGH
69 case 5: // FALLTHROUGH
70 case 7:
71 received_stations = bits.ToUnsignedInt(154, 14);
72 received_stations_valid = true;
73 break;
74 default:
75 assert(false);
76 }
77 } else {
78 // ITDMA
79 slot_increment = bits.ToUnsignedInt(151, 13);
80 slot_increment_valid = true;
81
82 slots_to_allocate = bits.ToUnsignedInt(164, 3);
83 slots_to_allocate_valid = true;
84
85 keep_flag = bits[167];
86 keep_flag_valid = true;
87 }
88
89 assert(bits.GetRemaining() == 0);
90 status = AIS_OK;
91 }
92
93 } // namespace libais