forked from schwehr/libais
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathais24.cpp
80 lines (63 loc) · 2.18 KB
/
ais24.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Since 2010-05-09
// Class B static data report. Can be one of 4 different parts. Only
// A and B defined for ITU 1371-3
#include "ais.h"
Ais24::Ais24(const char *nmea_payload) {
assert (nmea_payload);
init();
const int num_bits = (strlen(nmea_payload) * 6);
// 160 + 2 spare for part A
if (162 != num_bits && 168 != num_bits) { status = AIS_ERR_BAD_BIT_COUNT; return; }
std::bitset<168> bs;
status = aivdm_to_bits(bs, nmea_payload);
if (had_error()) return;
message_id = ubits(bs, 0, 6);
if (24 != message_id) { status = AIS_ERR_WRONG_MSG_TYPE; return; }
repeat_indicator = ubits(bs,6,2);
mmsi = ubits(bs,8,30);
part_num = ubits(bs,38,2);
switch(part_num) {
case 0: // Part A
if (162 != num_bits) { status = AIS_ERR_BAD_BIT_COUNT; return; }
name = ais_str(bs, 40, 120);
break;
case 1: // Part B
if (168 != num_bits) { status = AIS_ERR_BAD_BIT_COUNT; return; }
type_and_cargo = ubits(bs, 40, 8);
vendor_id = ais_str(bs, 48, 42);
callsign = ais_str(bs, 90, 42);
dim_a = ubits(bs, 132, 9);
dim_b = ubits(bs, 141, 9);
dim_c = ubits(bs, 150, 6);
dim_d = ubits(bs, 156, 6);
spare = ubits(bs, 162,6);
break;
case 2: // FALLTHROUGH - not yet defined by ITU
case 3: // FALLTHROUGH - not yet defined by ITU
default:
status = AIS_ERR_BAD_MSG_CONTENT;
return;
}
}
void
Ais24::print() {
std::cout << "Class B static data: " << message_id << " part " << part_num << "\n";
switch (part_num) {
case 0:
std::cout << "\tname: " << name << std::endl;
break;
case 1:
std::cout << "\ttype_and_cargo: " << type_and_cargo << "\n"
<< "\tvendor_id: " << vendor_id << "\n"
<< "\tcallsign: " << callsign << "\n"
<< "\tdim: " << dim_a << " " << dim_b << " "<< dim_c << " " << dim_d << " (m)\n"
<< "\tspare: " << spare << std::endl;
;
break;
case 2: // FALLTHROUGH - not yet defined by ITU
case 3: // FALLTHROUGH - not yet defined by ITU
default:
assert(false);
return;
}
}