Debian Codegraph @

src/libais/ais24.cpp

raw symbols SCIP
1 // Class B static data report. Can be one of 4 different parts. Only
2 // A and B defined for ITU 1371-3
3
4 #include "ais.h"
5
6 namespace libais {
7
8 Ais24::Ais24(const char *nmea_payload, const size_t pad)
9 : AisMsg(nmea_payload, pad), part_num(0), type_and_cargo(0),
10 dim_a(0), dim_b(0), dim_c(0), dim_d(0), spare(0) {
11 if (!CheckStatus()) {
12 return;
13 }
14 if (num_bits != 160 && num_bits != 168) {
15 status = AIS_ERR_BAD_BIT_COUNT;
16 return;
17 }
18
19 assert(message_id == 24);
20
21 bits.SeekTo(38);
22 part_num = bits.ToUnsignedInt(38, 2);
23
24 switch (part_num) {
25 case 0: // Part A
26 name = bits.ToString(40, 120);
27 if (num_bits == 168) {
28 // Accept the invalid size.
29 spare = bits.ToUnsignedInt(160, 8);
30 }
31 break;
32 case 1: // Part B
33 if (num_bits == 160) {
34 // Some devices incorrectly use part 1 as 0.
35 name = bits.ToString(40, 120);
36 part_num = 0;
37 break;
38 }
39 type_and_cargo = bits.ToUnsignedInt(40, 8);
40 vendor_id = bits.ToString(48, 42);
41 callsign = bits.ToString(90, 42);
42 dim_a = bits.ToUnsignedInt(132, 9);
43 dim_b = bits.ToUnsignedInt(141, 9);
44 dim_c = bits.ToUnsignedInt(150, 6);
45 dim_d = bits.ToUnsignedInt(156, 6);
46 spare = bits.ToUnsignedInt(162, 6);
47 break;
48 case 2: // FALLTHROUGH - Not defined by ITU 1371-5
49 case 3: // FALLTHROUGH - Not defined by ITU 1371-5
50 default:
51 status = AIS_ERR_BAD_MSG_CONTENT;
52 return;
53 }
54
55 assert(bits.GetRemaining() == 0);
56 status = AIS_OK;
57 }
58
59 } // namespace libais