Debian Codegraph @

src/libais/ais4_11.cpp

raw symbols SCIP
1 // AIS message 4 or 11
2
3 #include "ais.h"
4
5 namespace libais {
6
7 Ais4_11::Ais4_11(const char *nmea_payload, const size_t pad)
8 : AisMsg(nmea_payload, pad), year(0), month(0), day(0), hour(0), minute(0),
9 second(0), position_accuracy(0), fix_type(0),
10 transmission_ctl(0), spare(0), raim(false), sync_state(0),
11 slot_timeout(0), received_stations_valid(false), received_stations(0),
12 slot_number_valid(false), slot_number(0), utc_valid(false), utc_hour(0),
13 utc_min(0), utc_spare(0), slot_offset_valid(false), slot_offset(0) {
14 if (!CheckStatus()) {
15 return;
16 }
17 if (pad != 0 || num_chars != 28) {
18 status = AIS_ERR_BAD_BIT_COUNT;
19 return;
20 }
21
22 assert(message_id == 4 || message_id == 11);
23
24 bits.SeekTo(38);
25 year = bits.ToUnsignedInt(38, 14);
26 month = bits.ToUnsignedInt(52, 4);
27 day = bits.ToUnsignedInt(56, 5);
28 hour = bits.ToUnsignedInt(61, 5);
29 minute = bits.ToUnsignedInt(66, 6);
30 second = bits.ToUnsignedInt(72, 6);
31
32 position_accuracy = bits[78];
33 position = bits.ToAisPoint(79, 55);
34
35 fix_type = bits.ToUnsignedInt(134, 4);
36 transmission_ctl = bits[138];
37 spare = bits.ToUnsignedInt(139, 9);
38 raim = bits[148];
39
40 // SOTDMA commstate
41 sync_state = bits.ToUnsignedInt(149, 2);
42 slot_timeout = bits.ToUnsignedInt(151, 3);
43
44 switch (slot_timeout) {
45 case 0:
46 slot_offset = bits.ToUnsignedInt(154, 14);
47 slot_offset_valid = true;
48 break;
49 case 1:
50 utc_hour = bits.ToUnsignedInt(154, 5);
51 utc_min = bits.ToUnsignedInt(159, 7);
52 utc_spare = bits.ToUnsignedInt(166, 2);
53 utc_valid = true;
54 break;
55 case 2: // FALLTHROUGH
56 case 4: // FALLTHROUGH
57 case 6:
58 slot_number = bits.ToUnsignedInt(154, 14);
59 slot_number_valid = true;
60 break;
61 case 3: // FALLTHROUGH
62 case 5: // FALLTHROUGH
63 case 7:
64 received_stations = bits.ToUnsignedInt(154, 14);
65 received_stations_valid = true;
66 break;
67 default:
68 assert(false);
69 }
70
71 assert(bits.GetRemaining() == 0);
72 status = AIS_OK;
73 }
74
75 ostream& operator<< (ostream &o, const Ais4_11 &msg) {
76 return o << msg.message_id << ": " << msg.mmsi;
77 }
78
79 } // namespace libais