Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (59 sloc) 2.25 kB
1531d7c message 1-5 are able to decode in python
schwehr authored
1 // Since Apr 2010
d851631 added msg 14 - safety broadcast
schwehr authored
2 // Class A shipdata
1531d7c message 1-5 are able to decode in python
schwehr authored
3 #include "ais.h"
4
113e862 Add message 19
schwehr authored
5 //#include <iostream>
6 //#include <bitset>
7 //#include <string>
d851631 added msg 14 - safety broadcast
schwehr authored
8 //#include <cassert>
113e862 Add message 19
schwehr authored
9 //#include <cmath>
1531d7c message 1-5 are able to decode in python
schwehr authored
10
11
12 Ais5::Ais5(const char *nmea_payload) {
113e862 Add message 19
schwehr authored
13 assert(nmea_payload);
5545183 error handling now in place. starting on classb
schwehr authored
14 init();
15
113e862 Add message 19
schwehr authored
16 if (strlen(nmea_payload) != 71) { status = AIS_ERR_BAD_BIT_COUNT; return; }
17
18 std::bitset<426> bs; // 424 + 2 spare bits => 71 characters
5545183 error handling now in place. starting on classb
schwehr authored
19 status = aivdm_to_bits(bs, nmea_payload);
20 if (had_error()) return;
1531d7c message 1-5 are able to decode in python
schwehr authored
21
22 message_id = ubits(bs, 0, 6);
113e862 Add message 19
schwehr authored
23 if (5 != message_id) { status = AIS_ERR_WRONG_MSG_TYPE; return; }
1531d7c message 1-5 are able to decode in python
schwehr authored
24 repeat_indicator = ubits(bs,6,2);
25 mmsi = ubits(bs,8,30);
26
27 ais_version = ubits(bs, 38, 2);
28 imo_num = ubits(bs, 40, 30);
29 callsign = ais_str(bs, 70, 42);
30
31 name = ais_str(bs, 112, 120);
32
eb4644e @schwehr Fix type_and_cargo decoding
authored
33 type_and_cargo = ubits(bs, 232, 8);
1531d7c message 1-5 are able to decode in python
schwehr authored
34 dim_a = ubits(bs, 240, 9);
35 dim_b = ubits(bs, 249, 9);
36 dim_c = ubits(bs, 258, 6);
37 dim_d = ubits(bs, 264, 6);
38 fix_type = ubits(bs, 270, 4);
39 eta_month = ubits(bs, 274, 4);
40 eta_day = ubits(bs, 278, 5);
41 eta_hour = ubits(bs, 283, 5);
42 eta_minute = ubits(bs, 288, 6);
43 draught = ubits(bs, 294, 8) / 10.;
44 destination = ais_str(bs, 302, 120);
45 //cout << "destination:" << destination << endl;
46 dte = ubits(bs, 422, 1);
47 spare = ubits(bs, 423, 1);
48 }
49
50 void Ais5::print() {
51 std::cout << "Ais5 - shipdata\n"
52 << "\tmessage_id: " << message_id << " " << repeat_indicator << " " << mmsi << "\n"
53 << "\tcallsign: " << callsign << "\n"
54 << "\tname: " << name << "\n"
55 << "\ttype_and_cargo: " << type_and_cargo << "\n"
113e862 Add message 19
schwehr authored
56 << "\tdim: " << dim_a << " " << dim_b << " "<< dim_c << " " << dim_d << " (m)\n"
1531d7c message 1-5 are able to decode in python
schwehr authored
57 << "\tfix_type: " << fix_type << "\n"
58 << "\teta: " << eta_month << "-" << eta_day << "T" << eta_hour << ":" << eta_minute << "\n"
59 << "\tdestination: " << destination << "\n"
60 << "\tdte: " << dte << "\n"
61 << "\tspare: " << spare << "\n"
62 ;
63 }
64
65 std::ostream& operator<< (std::ostream& o, Ais5 const& a)
66 {
67 return o << 5 << ": " << a.mmsi << " \"" << a.name << "\" " << a.type_and_cargo
68 << " " << a.dim_a + a.dim_b << "x" << a.dim_c + a.dim_d << "x" << a.draught << "m"
69 ;
70 }
71
Something went wrong with that request. Please try again.