Skip to content
Newer
Older
100644 149 lines (126 sloc) 4.65 KB
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
1 // Since Apr 2010
2
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
3 #include "ais.h"
4
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
5 #include <iostream>
6 #include <bitset>
7 #include <string>
8 #include <cassert>
9 #include <cmath>
2660e8a @lukec abs() for int comes from <cstdlib> per section 26.5 of the C++ Standard
lukec authored Aug 1, 2011
10 #include <cstdlib>
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
11
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
12 using namespace std;
13
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
14 Ais1_2_3::Ais1_2_3(const char *nmea_payload) {
5545183 error handling now in place. starting on classb
schwehr authored May 5, 2010
15 assert(nmea_payload);
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
16 assert(nmea_ord_initialized); // Make sure we have the lookup table built
5545183 error handling now in place. starting on classb
schwehr authored May 5, 2010
17 init();
18
113e862 Add message 19
schwehr authored May 6, 2010
19 if (strlen(nmea_payload) != 168/6) { status = AIS_ERR_BAD_BIT_COUNT; return; }
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
20
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
21 std::bitset<168> bs; // 1 slot
5545183 error handling now in place. starting on classb
schwehr authored May 5, 2010
22 status = aivdm_to_bits(bs, nmea_payload);
23 if (had_error()) return;
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
24
25 message_id = ubits(bs, 0, 6);
5545183 error handling now in place. starting on classb
schwehr authored May 5, 2010
26 if (message_id < 1 or message_id > 3) {
27 status = AIS_ERR_WRONG_MSG_TYPE;
28 return;
29 }
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
30
31 repeat_indicator = ubits(bs,6,2);
32 mmsi = ubits(bs,8,30);
33 nav_status = ubits(bs,38,4);
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
34
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
35 /*const int*/ rot_raw = sbits(bs,42,8);
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
36 rot_over_range = abs(rot_raw) > 126 ? true : false ;
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
37 //rot = 4.733 * sqrt(fabs(rot_raw)); // FIX: this was wrong... double check
38 rot = pow( (rot_raw/4.733), 2 );
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
39 if (rot_raw < 0) rot = -rot;
40
41 sog = ubits(bs,50,10) / 10.;
42 position_accuracy = ubits(bs,60,1);
43 x = sbits(bs, 61, 28) / 600000.;
44 y = sbits(bs, 89, 27) / 600000.;
45 cog = ubits(bs, 116, 12) / 10.;
46 true_heading = ubits(bs, 128, 9);
47 timestamp = ubits(bs, 137, 6);
48 special_manoeuvre = ubits(bs, 143, 2);
49 spare = ubits(bs, 145, 3);
50 raim = bool(bs[148]);
51
52 sync_state = ubits(bs, 149, 2);
53
54 // Set all to invalid - this way we don't have to track it in multiple places
55 received_stations = -1; received_stations_valid = false;
56 slot_number = -1; slot_number_valid = false;
57 utc_hour = utc_min = -1; utc_valid = false;
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
58 utc_spare = -1;
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
59 slot_offset = -1; slot_offset_valid = false;
60
61 slot_increment = -1; slot_increment_valid = false;
62 slots_to_allocate = -1; slots_to_allocate_valid = false;
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
63 keep_flag = false; keep_flag_valid = false;
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
64
65
66 if ( 1 == message_id || 2 == message_id) {
67 slot_timeout = ubits(bs,151,3);
68
69 switch (slot_timeout) {
70 case 0:
71 slot_offset = ubits(bs, 154, 14);
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
72 slot_offset_valid = true;
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
73 break;
74 case 1:
75 utc_hour = ubits(bs, 154, 5);
76 utc_min = ubits(bs, 159, 7);
77 utc_spare = ubits(bs, 166, 2);
78 utc_valid = true;
79 break;
80 case 2: // FALLTHROUGH
81 case 4: // FALLTHROUGH
82 case 6:
83 slot_number = ubits(bs, 154, 14);
84 slot_number_valid = true;
85 break;
86 case 3: // FALLTHROUGH
87 case 5: // FALLTHROUGH
88 case 7:
89 received_stations = ubits(bs, 154, 14);
90 received_stations_valid = true;
91 break;
92 default:
93 assert (false);
94 }
95 } else {
62f9951 class B message 18/B looks to be working
schwehr authored May 5, 2010
96 //std::cout << "expecting 3: " << message_id << std::endl;
0d187b2 ais msg 9 - sar position
schwehr authored May 14, 2010
97 // ITDMA
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
98 assert (3 == message_id);
99 slot_increment = ubits(bs, 151, 13);
100 slot_increment_valid = true;
101
102 slots_to_allocate = ubits(bs, 164, 3);
103 slots_to_allocate_valid = true;
104
105 keep_flag = bool(bs[167]);
106 keep_flag_valid = true;
107
108 }
109 }
110
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
111 void
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
112 Ais1_2_3::print(bool verbose/*=false*/) {
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
113 std::cout << "Class A Position: " << message_id
114 << std::endl;
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
115 if (!verbose) return;
116 cout << "\trow_raw: " << rot_raw << endl;
117 cout << "\trot: " << rot << " -> " << (rot_over_range? "greater than": " ") << " " << rot << endl;
118 cout << "\tsog: " << sog << endl;
119 cout << "\tpos_acc: " << position_accuracy << endl;
120 cout << "\tpos_x: " << x << endl;
121 cout << "\tpos_y: " << y << endl;
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
122 //cout << "cog_raw: " << ubits(bs,116,12) << endl;
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
123 cout << "\tcog: " << cog << endl;
124 cout << "\ttrue_heading:" << true_heading << endl;
125 cout << "\ttimestamp: " << timestamp << endl;
126 cout << "\tspecial_manoeuvre: " << special_manoeuvre << endl;
127 cout << "\tspare: " << spare << endl;
128 cout << "\tsync_state: " << sync_state << endl;
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
129 if ( 1 == message_id || 2 == message_id) {
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
130 cout << "\tSOTDMA type " << message_id << endl;
131 cout << "\t\tslot_offset: " << slot_offset << endl;
132 cout << "\t\tslot_timeout: " << slot_timeout << endl;
133 cout << "\t\tslot_number: " << slot_number << endl;
134 cout << "\t\treceived_stations: " << received_stations << endl;
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
135 } else {
136 assert (3 == message_id);
c791296 @schwehr Added ais1_2_3_unittest based on gtest.
authored Apr 2, 2011
137 cout << "\tITDMA type" << endl;
138 cout << "\t\tslot_increment: " << slot_increment << endl;
139 cout << "\t\tslots_to_allocate: " << slots_to_allocate << endl;
140 cout << "\t\tkeep_flag: " << (keep_flag?"keep":"do_not_keep") << endl;
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
141 }
142 }
143
144 std::ostream& operator<< (std::ostream& o, Ais1_2_3 const& a)
145 {
146 return o << a.message_id << ": " << a.mmsi ;
61caae9 something that actually works\!
schwehr authored Apr 28, 2010
147 }
1531d7c message 1-5 are able to decode in python
schwehr authored May 3, 2010
148
Something went wrong with that request. Please try again.