Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (100 sloc) 4.002 kB
0d187b2 ais msg 9 - sar position
schwehr authored
1 // Since 2010-May-14
2
3 #include "ais.h"
4
5 Ais9::Ais9(const char *nmea_payload) {
6 assert(nmea_payload);
7 init();
8
9 if (strlen(nmea_payload) != 168/6) {
10 status = AIS_ERR_BAD_BIT_COUNT;
11 return;
12 }
13
14 std::bitset<168> bs; // 1 slot
15 status = aivdm_to_bits(bs, nmea_payload);
16 if (had_error()) return;
17
18 message_id = ubits(bs, 0, 6);
19 if (9 != message_id) { status = AIS_ERR_WRONG_MSG_TYPE; return; }
20 repeat_indicator = ubits(bs,6,2);
21 mmsi = ubits(bs,8,30);
22 alt = ubits(bs,38, 12);
23 sog = ubits(bs,50,10) / 10.;
24
25 position_accuracy = ubits(bs,60,1);
26 x = sbits(bs, 61, 28) / 600000.;
27 y = sbits(bs, 89, 27) / 600000.;
28
29 cog = ubits(bs, 116, 12) / 10.;
30 timestamp = ubits(bs, 128, 6);
31 alt_sensor = int(bs[129]); // ubits(bs, 129, 1);
32 spare = ubits(bs, 136, 7);
33 dte = int(bs[143]);//ubits(bs, 143, 1);
34 spare2 = ubits(bs, 146, 3);
35 raim = bool(bs[147]);
36 commstate_flag = bs[148]; // 0 SOTDMA, 1 ITDMA
37
38 #ifndef NDEBUG
39 slot_timeout = -1;
40 received_stations = slot_number = utc_hour = utc_min = utc_spare -1;
41 slot_offset = slot_increment = slots_to_allocate = -1;
42 keep_flag = false;
43 #endif
44 slot_timeout_valid = false;
45 received_stations_valid = slot_number_valid = utc_valid = false;
46 slot_offset_valid = slot_increment_valid = slots_to_allocate_valid = keep_flag_valid = 0;
47
48 if (0 == commstate_flag) {//unit_flag) {
49
50 // SOTDMA
51 slot_timeout = ubits(bs,151,3);
52 slot_timeout_valid = true;
53
54 switch (slot_timeout) {
55 case 0:
56 slot_offset = ubits(bs, 154, 14);
57 slot_offset_valid = true;
58 break;
59 case 1:
60 utc_hour = ubits(bs, 154, 5);
61 utc_min = ubits(bs, 159, 7);
62 utc_spare = ubits(bs, 166, 2);
63 utc_valid = true;
64 break;
65 case 2: // FALLTHROUGH
66 case 4: // FALLTHROUGH
67 case 6:
68 slot_number = ubits(bs, 154, 14);
69 slot_number_valid = true;
70 break;
71 case 3: // FALLTHROUGH
72 case 5: // FALLTHROUGH
73 case 7:
74 received_stations = ubits(bs, 154, 14);
75 received_stations_valid = true;
76 break;
77 default:
78 assert (false);
79 }
80
81 } else {
82 // ITDMA
83 slot_increment = ubits(bs, 151, 13);
84 slot_increment_valid = true;
85
86 slots_to_allocate = ubits(bs, 164, 3);
87 slots_to_allocate_valid = true;
88
89 keep_flag = bool(bs[167]);
90 keep_flag_valid = true;
91 }
92 }
93
94
95 void Ais9::print() {
96 std::cout << "SAR position: " << message_id << "\n"
97 << "\tmmsi: " << mmsi << " repeat: " << repeat_indicator << "\n"
98 << "\talt: " << alt << " (m) alt_sensor: " << alt_sensor << "\n"
99 << "\tposition_accuracy: " << position_accuracy << "\n"
100 << "\tlocation: " << x << " " << y << "\n"
101 << "\ttimestamp: " << timestamp << "spare: " << spare << "\n"
102 << "\tdte: " << dte << "spare2: " << spare2 << "\n"
103 << "\traim: " << (raim?"true":"false") << "\n"
104 << "\tcommstate_flag: " << commstate_flag
105 << std::endl;
106 // SOTDMA
107 if (slot_timeout_valid) std::cout << "\t\tslot_timeout: " << slot_timeout << "\n";
108 if (slot_offset_valid) std::cout << "\t\tslot_offset" << slot_offset << "\n";
109 if (utc_valid) std::cout <<"\t\tUTC: " << utc_hour << ":"<<utc_min << " spare:" << utc_spare << "\n";
110 if (slot_number_valid) std::cout << "\t\tslot_number: " << slot_number << "\n;";
111 if (received_stations_valid) std::cout << "\t\treceived_stations: " << received_stations << "\n";
112
113 // ITDMA
114 if (slot_increment_valid) std::cout << "\t\tslot_increment: " << slot_increment << "\n";
115 if (slots_to_allocate_valid) std::cout << "\t\tslots_to_allocate: " << slots_to_allocate << "\n";
116 if (keep_flag_valid) std::cout << "\t\tkeep_flag: " << keep_flag << "\n";
117
118 }
Something went wrong with that request. Please try again.