forked from schwehr/libais
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathais1_2_3_unittest.cpp
120 lines (101 loc) · 3.45 KB
/
ais1_2_3_unittest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include "ais.h"
using namespace std;
TEST(TestAis1_2_3,AisMsg) {
AisMsg a;
a.init();
ASSERT_EQ(AIS_OK, a.get_error());
}
/* Python:
import binary
bv = binary.ais6tobitvec('15Mq4J0P01EREODRv4@74gv00HRq')
print bv
*/
TEST(TestAis1_2_3, BitDecoding) {
build_nmea_lookup();
const string m_str("15Mq4J0P01EREODRv4@74gv00HRq");
const string bits_expected("000001000101011101111001000100011010000000100000000000000001010101100010010101011111010100100010111110000100010000000111000100101111111110000000000000011000100010111001");
bitset<168> bs;
AIS_STATUS status = aivdm_to_bits(bs, m_str.c_str());
//cout << "decode_status: " << status << endl;
ASSERT_EQ(AIS_OK,status);
for (size_t i=0; i < 168; i++) {
char c = bs[i]? '1':'0';
ASSERT_EQ(bits_expected[i], c);
}
}
/*
~/projects/src/noaadata/ais/ais_msg_1_handcoded.py -d '!AIVDM,1,1,,B,15Mq4J0P01EREODRv4@74gv00HRq,0*72,b003669970,1272412824'
position:
MessageID: 1
RepeatIndicator: 0
UserID: 366888040
NavigationStatus: 0
ROT: -128
SOG: 0.1
PositionAccuracy: 0
longitude: -146.2903833333333333333333333
latitude: 61.11413333333333333333333333
COG: 181
TrueHeading: 511
TimeStamp: 0
RegionalReserved: 0
Spare: 0
RAIM: False
sync_state: 0
slot_timeout: 6
received_stations: n/a
slot_number: 2233
commstate_utc_hour: n/a
commstate_utc_min: n/a
commstate_utc_spare: n/a
slot_offset: n/a
*/
TEST(TestAis1_2_3, AisMsg1) {
const string m_str("AIVDM,1,1,,B,15Mq4J0P01EREODRv4@74gv00HRq,0*72,b003669970,1272412824");
const string body(nth_field(m_str,5,','));
ASSERT_STREQ("15Mq4J0P01EREODRv4@74gv00HRq",body.c_str());
Ais1_2_3 m(body.c_str());
//cout << "AisMsg had_error should be: " << AIS_OK << " == " << m.get_error() << endl;
ASSERT_EQ(AIS_OK, m.get_error());
//m.print(true);
ASSERT_EQ(1,m.message_id);
ASSERT_EQ(0,m.repeat_indicator);
ASSERT_EQ(366888040,m.mmsi);
ASSERT_EQ(0,m.nav_status);
ASSERT_EQ(true,m.rot_over_range);
ASSERT_EQ(-128,m.rot_raw);
//ASSERT_FLOAT_EQ(-731.386, m.rot);
ASSERT_NEAR(-731.386, m.rot, 0.001);
ASSERT_FLOAT_EQ(0.1,m.sog);
ASSERT_EQ(false,m.position_accuracy);
ASSERT_FLOAT_EQ(-146.2903833,m.x);
ASSERT_FLOAT_EQ( 61.1141333,m.y);
ASSERT_FLOAT_EQ(181.0,m.cog);
ASSERT_EQ(511, m.true_heading);
ASSERT_EQ(0, m.timestamp);
ASSERT_EQ(0, m.special_manoeuvre); // Pre ITU 1371-3, this and the spare were one
ASSERT_EQ(0, m.spare);
ASSERT_EQ(false, m.raim);
// COMM STATE
ASSERT_EQ(0,m.sync_state);
ASSERT_EQ(6,m.slot_timeout);
ASSERT_EQ(false,m.received_stations_valid);
ASSERT_EQ(-1,m.received_stations);
ASSERT_EQ(true,m.slot_number_valid);
ASSERT_EQ(2233,m.slot_number);
ASSERT_EQ(false,m.utc_valid);
ASSERT_EQ(-1,m.utc_hour);
ASSERT_EQ(-1,m.utc_min);
ASSERT_EQ(-1,m.utc_spare);
ASSERT_EQ(false,m.slot_offset_valid);
ASSERT_EQ(-1,m.slot_offset);
ASSERT_EQ(false,m.slot_increment_valid);
ASSERT_EQ(-1,m.slot_increment);
ASSERT_EQ(false,m.slots_to_allocate_valid);
ASSERT_EQ(-1,m.slots_to_allocate);
ASSERT_EQ(false,m.keep_flag_valid);
ASSERT_EQ(false,m.keep_flag);
}