AIS0. understanding AIS NMEA 0183: How it's coded

For my boat tracking system, I found out that using AIS format seems to be a good idea, at least I don't have to worry about how to present boat data, since there are already plenty things for do this on mobile phone or PC.

Here is what I read: http://catb.org/gpsd/AIVDM.html

Looking into AIS NMEA0183, it has much more application then I think. Such as MOB device, epir, aid to navigation device...etc, all are included. it use the first few char to indicate the function:
Table 1. AIS talker IDs
!ABNMEA 4.0 Base AIS station
!AD
MMEA 4.0 Dependent AIS Base Station
!AI
Mobile AIS station
!AN
NMEA 4.0 Aid to Navigation AIS station
!AR
NMEA 4.0 AIS Receiving Station
!AS
NMEA 4.0 Limited Base Station
!AT
NMEA 4.0 AIS Transmitting Station
!AX
NMEA 4.0 Repeater AIS station
!BS
Base AIS station (deprecated in NMEA 4.0)
!SA
NMEA 4.0 Physical Shore AIS Station
It can also be used between device on boat for message communication, AIVDO
The message is a series of data with "," as separator and end with a XOR check sum right after ! to the end of payload.

For example: a AVIDM sentence may look like this:

This is what it means:
AIS Datensatz: !AIVDM,1,1,,B,177KQJ5000G?tO`K>RA1wUbN0TKH,0*5C
Checksumme OK
Datenfeld: 177KQJ5000G?tO`K>RA1wUbN0TKH
Kanal: B
Message Type: 1
MMSI: 477553000
Nav. Status: 5 das ist: Moored
SOG:0.0
Longitude: 325 Grad 2.7949 Minuten
Latitude: 47 Grad 34.9700 Minuten
COG: 51.0
Heading: 181

And AIS message also take consideration of saving bytes,
1. one sentence is 82 char max.
2. every item is carefully arranged, occupied only necessary bits for data range.
3. the payload is coded with 6 bit ASCII, and the binary result still have to be ready able under 8 bits ASCII.
So, the trick is to change the 8 bits ASCII that we see:177KQJ5000G?tO`K>RA1wUbN0TKH
and translate them into binary by using 6 bits ASCII table. Then take according bits for certain data.
Here are the Char used by AIS and it's six bits binary.Note! there is no x,y,z nor X,Y,Z
CharASCII
decimal 
6 bits
Decimal 
Bits
"0"
48
0
000000
"1"
49
1
000001
"2"
50
2
000010
"3"
51
3
000011
"4"
52
4
000100
"5"
53
5
000101
"6"
54
6
000110
"7"
55
7
000111
"8"
56
8
001000
"9"
57
9
001001
":"
58
10
001010
";"
59
11
001011
"<"
60
12
001100
"="
61
13
001101
">"
62
14
001110
"?"
63
15
001111
"@"
64
16
010000
"A"
65
17
010001
"B"
66
18
010010
"C"
67
19
010011
"D"
68
20
010100
"E"
69
21
010101
"F"
70
22
010110
"G"
71
23
010111
"H"
72
24
011000
"I"
73
25
011001
"J"
74
26
011010
"K"
75
27
011011
"L"
76
28
011100
"M"
77
29
011101
"N"
78
30
011110
"O"
79
31
011111
"P"
80
32
100000
"Q"
81
33
100001
"R"
82
34
100010
"S"
83
35
100011
"T"
84
36
100100
"U"
85
37
100101
"V"
86
38
100110
"W"
87
39
100111
"`"
96
40
101000
"a"
97
41
101001
"b"
98
42
101010
"c"
99
43
101011
"d"
100
44
101100
"e"
101
45
101101
"f"
102
46
101110
"g"
103
47
101111
"h"
104
48
110000
"i"
105
49
110001
"j"
106
50
110010
"k"
107
51
110011
"l"
108
52
110100
"m"
109
53
110101
"n"
110
54
110110
"o"
111
55
110111
"p"
112
56
111000
"q"
113
57
111001
"r"
114
58
111010
"s"
115
59
111011
"t"
116
60
111100
"u"
117
61
111101
"v"
118
62
111110
"w"
119
63
111111
To convert the Char we see(8 bits ASCII), subtract 48 from the ASCII character value; if the result is greater than 40 subtract another 8. (because in ASCII 88~95 are not used in AIS 6 bit table)
for example "w"=119
119-48=71, still greater than 40, 71-8=63, which resent 111111 in 6 bits.


Here is a web side easy to understand.
http://www.bosunsmate.org/news/article/258/Decoding-AIS-Data/

There is an example:
payload:
14eG;o@034o8sd<L9i:a;WF>062D
translate into 6bits binary:
000001 000100 101101 010111 011100 001010 010000 000000 000000 000000 110111 001000 110111 100001 101000 011100 011101 110010 011111 101011 110000 110101 010111 010000 000000 001000 011000 011011 

here is the table for messge type 01:

Type 1, 2 and 3 messages share a common reporting structure for navigational information; we’ll call it the Common Navigation Block (CNB). This is the information most likely to be of interest for decoding software. Total of 168 bits, occupying one AIVDM sentence.
Table 6. Common Navigation Block
FieldLenDescriptionMemberTUnits
0-5
6
Message Type
type
u
Constant: 1-3
6-7
2
Repeat Indicator
repeat
u
Message repeat count
8-37
30
MMSI
mmsi
u
9 decimal digits
38-41
4
Navigation Status
status
e
See "Navigation Status"
42-49
8
Rate of Turn (ROT)
turn
I3
See below
50-59
10
Speed Over Ground (SOG)
speed
U1
See below
60-60
1
Position Accuracy
accuracy
b
See below
61-88
28
Longitude
lon
I4
Minutes/10000 (see below)
89-115
27
Latitude
lat
I4
Minutes/10000 (see below)
116-127
12
Course Over Ground (COG)
course
U1
Relative to true north, to 0.1 degree precision
128-136
9
True Heading (HDG)
heading
u
0 to 359 degrees, 511 = not available.
137-142
6
Time Stamp
second
u
Second of UTC timestamp
143-144
2
Maneuver Indicator
maneuver
e
See "Maneuver Indicator"
145-147
3
Spare
x
Not used
148-148
1
RAIM flag
raim
b
See below
149-167
19
Radio status
radio
u
See below








So if we take the first 6 bits:000001 = 1, so the message type is 1
9 to 38 bits: 010010110101011101110000101001 = 316005417  this is the MMSI (here is binary to decimal, there is no issue for 6 bits or 8 bits)
navigation status39-42=0000=0
rate of turn:43-50=00000000=0 
SOG 51-60 = 0000000000=0
position accuracy 61-61=1=1
long 10111 001000 110111 100001 10100
lat   0 011100 011101 110010 011111 10
COG 1011 110000 11  =3011 which means 301.1
true heading 0101 01011    =171 
UTC in seconds 1 01000 


To find out how to convert these bits into readable nr: http://catb.org/gpsd/AIVDM.html

I ran into some issues: there is only second in this format. there is no min and hour.
which means the receiver device need to have a gps or accurate clock for getting time.

some are signed nr, such as lon, lat, you have to calculate with some thing like this:
if byte > 127:
    return (256-byte) * (-1)
else:
    return byte

for example lon is 28 bits, 









留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled