Skip to content
Newer
Older
100644 53 lines (43 sloc) 1.42 KB
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
1 #include "ais.h"
2
3 #include <iostream>
4 #include <bitset>
5 //#include <string>
6 #include <cassert>
7 //#include <vector>
5545183 error handling now in place. starting on classb
schwehr authored
8 //using namespace std;
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
9
10 Ais7_13::Ais7_13(const char *nmea_payload) {
5545183 error handling now in place. starting on classb
schwehr authored
11 init();
12
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
13 assert (nmea_payload);
14 const size_t num_bits = strlen(nmea_payload) * 6;
5545183 error handling now in place. starting on classb
schwehr authored
15 //cout << "num_bits: " << num_bits << endl;
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
16
5545183 error handling now in place. starting on classb
schwehr authored
17 if (! ((40+32*1)==num_bits or (40+32*2)==num_bits or (40+32*3)==num_bits or (40+32*4)==num_bits) ){
18 status = AIS_ERR_BAD_BIT_COUNT;
19 return;
20 }
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
21
22 std::bitset<168> bs;
5545183 error handling now in place. starting on classb
schwehr authored
23 status = aivdm_to_bits(bs, nmea_payload);
24 if (had_error()) return;
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
25
26 message_id = ubits(bs, 0, 6);
5545183 error handling now in place. starting on classb
schwehr authored
27 if (message_id != 7 and message_id != 13) {
28 status = AIS_ERR_WRONG_MSG_TYPE;
29 return;
30 }
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
31 repeat_indicator = ubits(bs,6,2);
32 mmsi = ubits(bs,8,30);
33 spare = ubits(bs,38,2);
34
35 const size_t num_acks = (num_bits - 40) / 32;
36 for (size_t i=0; i < num_acks; i++) {
5545183 error handling now in place. starting on classb
schwehr authored
37 dest_mmsi.push_back(ubits(bs,40+i*32,30));
38 seq_num.push_back(ubits(bs,40+i*32+30,2));
ac15f1d The ack message... helped me find a problem in noaadata. Nice!
schwehr authored
39 }
40 }
41
42 void
43 Ais7_13::print() {
44 std::cout << message_id << ( (7==message_id)?" ABM Ack":" safety ack" ) << "\n"
45 << "\tmmsi: " << mmsi << " repeat: " << repeat_indicator << "\n";
46 std::cout << "\tspare: " << spare << "\n";
47 for (size_t i=0; i < dest_mmsi.size(); i++) {
48 std::cout << "\tack: " << dest_mmsi[i] << " seq: " << seq_num[i] << "\n";
49 }
50
51 std::cout << std::endl;
52 }
Something went wrong with that request. Please try again.