Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (30 sloc) 1.298 kB
72fe7de adding more messages
schwehr authored
1 // Since 2010-May-14
2 #include "ais.h"
3
4 Ais12::Ais12(const char *nmea_payload) {
5 assert(nmea_payload);
6 init();
7
8 const int num_char = strlen(nmea_payload);
9 // WARNING: the spec says max of 1008 bits, but 168 + 4*256 => 1192 bits or 199 characters
10 if ( num_char < 12 or num_char > 199 ) { status = AIS_ERR_BAD_BIT_COUNT; return; }
11
12 std::bitset<1192> bs; // Spec says 1008
13 status = aivdm_to_bits(bs, nmea_payload);
14 if (had_error()) return;
15
16 message_id = ubits(bs, 0, 6);
17 if (12 != message_id) { status = AIS_ERR_WRONG_MSG_TYPE; return; }
18 repeat_indicator = ubits(bs,6,2);
19 mmsi = ubits(bs,8,30);
20
21 seq_num = ubits(bs,38,2);
22 dest_mmsi = ubits(bs,40,30);
23 retransmitted = bool(bs[70]);
24 spare = bool(bs[71]);
25 int num_txt_bits = 6 * ((num_char * 6 - 72) / 6);
26 std::cout << "FIX: num_txt_bits: " << num_txt_bits << std::endl;
27 text = ais_str(bs,72,num_txt_bits);
28 }
29
30 void Ais12::print() {
31 std::cout << "Addressed safety message: " << message_id << "\n"
32 << "\tmmsi: " << mmsi << " repeat: " << repeat_indicator << "\n"
33 << "\tseq_num: " << seq_num << " retransmitted: " << retransmitted << "\n"
34 << "\tdest_mmsi: " << dest_mmsi << "\n"
35 << "\ttext: " << text << std::endl;
36 }
Something went wrong with that request. Please try again.