Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 104 lines (85 sloc) 2.735 kB
1531d7c message 1-5 are able to decode in python
schwehr authored
1 // AIS message 4 or 11
2
3 #include "ais.h"
4
5 #include <iostream>
6 #include <bitset>
7 #include <string>
8 #include <cassert>
c31fb83 msg 7 now works
schwehr authored
9 //#include <cmath>
1531d7c message 1-5 are able to decode in python
schwehr authored
10
11 Ais4_11::Ais4_11(const char *nmea_payload) {
cac8aca getting into the nais2pg.py development
schwehr authored
12 assert(nmea_payload);
5545183 error handling now in place. starting on classb
schwehr authored
13 init();
1531d7c message 1-5 are able to decode in python
schwehr authored
14
15 std::bitset<168> bs;
5545183 error handling now in place. starting on classb
schwehr authored
16
17 status = aivdm_to_bits(bs, nmea_payload);
18 if (had_error()) return;
1531d7c message 1-5 are able to decode in python
schwehr authored
19
20 message_id = ubits(bs, 0, 6);
5545183 error handling now in place. starting on classb
schwehr authored
21 if (message_id != 4 and message_id != 11) {
22 status = AIS_ERR_WRONG_MSG_TYPE;
23 return;
24 }
25
1531d7c message 1-5 are able to decode in python
schwehr authored
26 repeat_indicator = ubits(bs,6,2);
27 mmsi = ubits(bs,8,30);
28
29 year = ubits(bs,38,14);
30 month = ubits(bs,52,4);
31 day = ubits(bs,56,5);
32 hour = ubits(bs,61,5);
33 minute = ubits(bs,66,6);
34 second = ubits(bs,72,6);
35
36 position_accuracy = ubits(bs,78,1);
37 x = sbits(bs, 79, 28) / 600000.;
38 y = sbits(bs, 107, 27) / 600000.;
39
40 fix_type = ubits(bs,134,4);
41 spare = ubits(bs,138,10);
42
43
44 //
45 // SOTDMA commstate
46 //
47
48 // Set all to invalid - this way we don't have to track it in multiple places
49 received_stations = -1; received_stations_valid = false;
50 slot_number = -1; slot_number_valid = false;
51 utc_hour = utc_min = -1; utc_valid = false;
52 slot_offset = -1; slot_offset_valid = false;
53
54 slot_timeout = ubits(bs,151,3);
55
cac8aca getting into the nais2pg.py development
schwehr authored
56 //std::cout << "slot_timeout:" << slot_timeout << std::endl;
1531d7c message 1-5 are able to decode in python
schwehr authored
57 switch (slot_timeout) {
58 case 0:
59 slot_offset = ubits(bs, 154, 14);
60 slot_offset_valid=true;
61 break;
62 case 1:
63 utc_hour = ubits(bs, 154, 5);
64 utc_min = ubits(bs, 159, 7);
65 utc_spare = ubits(bs, 166, 2);
66 utc_valid = true;
67 break;
68 case 2: // FALLTHROUGH
69 case 4: // FALLTHROUGH
70 case 6:
71 slot_number = ubits(bs, 154, 14);
72 slot_number_valid = true;
73 break;
74 case 3: // FALLTHROUGH
75 case 5: // FALLTHROUGH
76 case 7:
77 received_stations = ubits(bs, 154, 14);
78 received_stations_valid = true;
79 break;
80 default:
81 assert (false);
82 }
83 }
84
85 void Ais4_11::print() {
86 std::cout << ( ( 4==message_id )?"bs_report: ":"utc response: ") << message_id << "\n"
c31fb83 msg 7 now works
schwehr authored
87 << "\tmmsi: " << mmsi << " repeat: " << repeat_indicator << "\n"
88 << "\tdate/time: " << year << "-" << month << "-" << day
89 << "T" << hour << ":" << minute << ":" << second << "Z\n"
90 << "\tposition_accuracy: " << position_accuracy << "\n"
91 << "\tlocation: " << x << " " << y << "\n"
92 << "\tspare: " << spare << "\n"
93 << "\traim: " << (raim?"true":"false") << "\n"
1531d7c message 1-5 are able to decode in python
schwehr authored
94 << std::endl;
95 ;
96
97 }
98
99 std::ostream& operator<< (std::ostream& o, Ais4_11 const& msg)
100 {
101 return o << msg.message_id << ": " << msg.mmsi
102 ;
103 }
Something went wrong with that request. Please try again.