Debian Codegraph @

src/libais/ais18.cpp

raw symbols SCIP
1 // Class B position report - 18 "B"
2
3 #include "ais.h"
4
5 namespace libais {
6
7 Ais18::Ais18(const char *nmea_payload, const size_t pad)
8 : AisMsg(nmea_payload, pad),
9 spare(0),
10 sog(0.0),
11 position_accuracy(0),
12 cog(0.0),
13 true_heading(0),
14 timestamp(0),
15 spare2(0),
16 unit_flag(0),
17 display_flag(0),
18 dsc_flag(0),
19 band_flag(0),
20 m22_flag(0),
21 mode_flag(0),
22 raim(false),
23 commstate_flag(0),
24 sync_state(0),
25 slot_timeout_valid(false),
26 slot_timeout(0),
27 received_stations_valid(false),
28 received_stations(0),
29 slot_number_valid(false),
30 slot_number(0),
31 utc_valid(false),
32 utc_hour(0),
33 utc_min(0),
34 utc_spare(0),
35 slot_offset_valid(false),
36 slot_offset(0),
37 slot_increment_valid(false),
38 slot_increment(0),
39 slots_to_allocate_valid(false),
40 slots_to_allocate(0),
41 keep_flag_valid(false),
42 keep_flag(0),
43 commstate_cs_fill_valid(false),
44 commstate_cs_fill(0) {
45 if (!CheckStatus()) {
46 return;
47 }
48 if (pad != 0 || num_chars != 28) {
49 status = AIS_ERR_BAD_BIT_COUNT;
50 return;
51 }
52
53 assert(message_id == 18);
54
55 bits.SeekTo(38);
56 spare = bits.ToUnsignedInt(38, 8);
57 sog = bits.ToUnsignedInt(46, 10) / 10.;
58
59 position_accuracy = bits[56];
60 position = bits.ToAisPoint(57, 55);
61
62 cog = bits.ToUnsignedInt(112, 12) / 10.;
63 true_heading = bits.ToUnsignedInt(124, 9);
64 timestamp = bits.ToUnsignedInt(133, 6);
65 spare2 = bits.ToUnsignedInt(139, 2);
66 unit_flag = bits[141];
67 display_flag = bits[142];
68 dsc_flag = bits[143];
69 band_flag = bits[144];
70 m22_flag = bits[145];
71 mode_flag = bits[146];
72 raim = bits[147];
73 commstate_flag = bits[148]; // 0 SOTDMA, 1 ITDMA
74
75 if (unit_flag == 0) {
76 sync_state = bits.ToUnsignedInt(149, 2);
77 if (commstate_flag == 0) {
78 // SOTDMA
79 slot_timeout = bits.ToUnsignedInt(151, 3);
80 slot_timeout_valid = true;
81
82 switch (slot_timeout) {
83 case 0:
84 slot_offset = bits.ToUnsignedInt(154, 14);
85 slot_offset_valid = true;
86 break;
87 case 1:
88 utc_hour = bits.ToUnsignedInt(154, 5);
89 utc_min = bits.ToUnsignedInt(159, 7);
90 utc_spare = bits.ToUnsignedInt(166, 2);
91 utc_valid = true;
92 break;
93 case 2: // FALLTHROUGH
94 case 4: // FALLTHROUGH
95 case 6:
96 slot_number = bits.ToUnsignedInt(154, 14);
97 slot_number_valid = true;
98 break;
99 case 3: // FALLTHROUGH
100 case 5: // FALLTHROUGH
101 case 7:
102 received_stations = bits.ToUnsignedInt(154, 14);
103 received_stations_valid = true;
104 break;
105 default:
106 assert(false);
107 }
108
109 } else {
110 // ITDMA
111 slot_increment = bits.ToUnsignedInt(151, 13);
112 slot_increment_valid = true;
113
114 slots_to_allocate = bits.ToUnsignedInt(164, 3);
115 slots_to_allocate_valid = true;
116
117 keep_flag = bits[167];
118 keep_flag_valid = true;
119 }
120 } else {
121 // Carrier Sense (CS) with unit_flag of 1.
122 commstate_cs_fill = bits.ToUnsignedInt(149, 19);
123 commstate_cs_fill_valid = true;
124 }
125
126 assert(bits.GetRemaining() == 0);
127 status = AIS_OK;
128 }
129
130 } // namespace libais