Debian Codegraph @

src/libais/ais26.cpp

raw symbols SCIP
1 // 'J' - Multi slot binary message with comm state
2 // TODO(schwehr): handle payload
3 // BAD: the comm-state is after the veriable payload. This is a bad design.
4
5 // See also: http://www.e-navigation.nl/asm
6
7 #include "ais.h"
8
9 namespace libais {
10
11 Ais26::Ais26(const char *nmea_payload, const size_t pad)
12 : AisMsg(nmea_payload, pad), use_app_id(false), dest_mmsi_valid(false),
13 dest_mmsi(0), dac(0), fi(0), commstate_flag(0), sync_state(0),
14 slot_timeout_valid(false), slot_timeout(0),
15 received_stations_valid(false), received_stations(0),
16 slot_number_valid(false), slot_number(0),
17 utc_valid(false), utc_hour(0), utc_min(0), utc_spare(0),
18 slot_offset_valid(false), slot_offset(0),
19 slot_increment_valid(false), slot_increment(0),
20 slots_to_allocate_valid(false), slots_to_allocate(0),
21 keep_flag_valid(false), keep_flag(false) {
22 if (!CheckStatus()) {
23 return;
24 }
25
26 // TODO(schwehr): Check for off by one.
27 const size_t comm_flag_offset = num_bits - 20;
28
29 if (num_bits < 52 || num_bits > 1064) {
30 status = AIS_ERR_BAD_BIT_COUNT;
31 return;
32 }
33
34 assert(message_id == 26);
35
36 bits.SeekTo(38);
37 const bool addressed = bits[38];
38 use_app_id = bits[39];
39 if (addressed) {
40 dest_mmsi_valid = true;
41 dest_mmsi = bits.ToUnsignedInt(40, 30);
42 if (use_app_id) {
43 if (num_bits < 86) {
44 status = AIS_ERR_BAD_BIT_COUNT;
45 return;
46 }
47 dac = bits.ToUnsignedInt(70, 10);
48 fi = bits.ToUnsignedInt(80, 6);
49 }
50 // TODO(schwehr): Handle the payload.
51 } else {
52 // broadcast
53 if (use_app_id) {
54 dac = bits.ToUnsignedInt(40, 10);
55 fi = bits.ToUnsignedInt(50, 6);
56 }
57 // TODO(schwehr): Handle the payload.
58 }
59
60 bits.SeekTo(comm_flag_offset);
61 commstate_flag = bits[comm_flag_offset];
62 sync_state = bits.ToUnsignedInt(comm_flag_offset + 1, 2); // SOTDMA and TDMA.
63
64 if (!commstate_flag) {
65 // SOTDMA
66 slot_timeout = bits.ToUnsignedInt(comm_flag_offset + 3, 3);
67 slot_timeout_valid = true;
68 switch (slot_timeout) {
69 case 0:
70 slot_offset = bits.ToUnsignedInt(comm_flag_offset + 6, 14);
71 slot_offset_valid = true;
72 break;
73 case 1:
74 utc_hour = bits.ToUnsignedInt(comm_flag_offset + 6, 5);
75 utc_min = bits.ToUnsignedInt(comm_flag_offset + 11, 7);
76 utc_spare = bits.ToUnsignedInt(comm_flag_offset + 18, 2);
77 utc_valid = true;
78 break;
79 case 2: // FALLTHROUGH
80 case 4: // FALLTHROUGH
81 case 6:
82 slot_number = bits.ToUnsignedInt(comm_flag_offset + 6, 14);
83 slot_number_valid = true;
84 break;
85 case 3: // FALLTHROUGH
86 case 5: // FALLTHROUGH
87 case 7:
88 received_stations = bits.ToUnsignedInt(comm_flag_offset + 6, 14);
89 received_stations_valid = true;
90 break;
91 default:
92 assert(false);
93 }
94 } else {
95 // ITDMA
96 slot_increment = bits.ToUnsignedInt(comm_flag_offset + 3, 13);
97 slot_increment_valid = true;
98
99 slots_to_allocate = bits.ToUnsignedInt(comm_flag_offset + 16, 3);
100 slots_to_allocate_valid = true;
101
102 keep_flag = bits[comm_flag_offset + 19];
103 keep_flag_valid = true;
104 }
105
106 // TODO(schwehr): Add assert(bits.GetRemaining() == 0);
107 status = AIS_OK;
108 }
109
110 } // namespace libais