summaryrefslogtreecommitdiff
path: root/www/AIVDM.txt
blob: 512926d82cdeba8b334a3ec03d0f2dd5b751b344 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
= AIVDM/AIVDO protocol decoding =
Eric S. Raymond <esr@thyrsus.com>
v1.13, Jun 2009

This document is mastered in asciidoc format.  If you are reading it in HTML,
you can find the original at http://gpsd.berlios.de/AIVDM.txt[]

== Introduction ==

This is a description of how to decode AIVDM/AIVDO sentences.  It
collects and integrates information from publicly available sources
and is intended to assist developers of open-source software for
interpreting these messages.

AIVDM/AIVDO sentences are emitted by receivers for AIS, the marine
Automatic Identification System. All cargo vessels of more than 300
tons displacement and all passenger vessels are supposed to carry AIS
transmitters that periodically squawk their position and course,
using TDMA (Time Division Multiple Access) technology similar to the
way cellphones do to avoid mutual interference.

AIS receivers capture these squawks and report them as ASCII data
packets over serial lines, using the NMEA 0183 data format and
physical network standards. AIS packets have the introducer "!AIVDM"
or "!AIVDO"; AIVDM packets are reports from other ships and AIVDO
packets are reports from your own ship.

A lengthy description of AIS, focusing on the goals and history of the
system, but not describing the data protocols in any detail, can be
found at <<AIS>>.

== Standards ==

Multiple standards bear on the AIVDM/AIVDO format.  This document
exists because assembling them into a complete picture is both
technically difficult and impeded by legal barriers.

ITU Recommendation M.1371, "Technical Characteristics for a Universal
Shipborne Automatic Identification System Using Time Division
Multiple Access" <<ITU1371>>, issued in 2001, describes the format of
AIS binary messages. It is proprietary, expensive, and surrounded by
attack lawyers.  I have not looked at it.

ITU-R M.1371 is expanded and clarified by "IALA Technical
Clarifications on Recommendation ITU-R M.1371-1" <<IALA>>, which
is freely available.

There have been two minor revisions of ITU-R M.1371 since it was
originally issued.  These add interpretations to packet bitfields that
were previously marked "spare" and "regional reserved".  I have not
seen these either, but have been passed information on them.

The ASCII format for AIS messages seems to have been set by IEC-PAS
61162-100, "Maritime navigation and radiocommunication equipment and
systems" <<IEC-PAS>>. It is proprietary and I have not looked at it.
Various public sources indicate that it has been "harmonized" with some
version of NMEA 0183 <<NMEA>>, which I also have not looked at because
it too is proprietary and expensive, and surrounded by even more
rapacious attack lawyers.

An effort, <<JSON-AIS>>, has been made to define a standard for
exchange of unpacked, human-readable AIS data. At present (edition of
6 Jun 2009) it covers only a small subset of the most common AIS
messages, and many data fields in the messages it does dump are
omitted.  The member names given in the bit-field tables match the
attributes used in JSON-AIS when JSON-AIS includes that field.

== Information Sources ==

Together, the the IALA Technical Clarifications at <<IALA>> and the
Coast Guard's AIS pages at <<NAVCEN>> describe AIS message payloads
almost completely.  The detail information on payload formats in this
document is mostly derived from these.

Kurt Schwehr is a research scientist at the Center for Coastal and
Ocean Mapping at the University of New Hamphire. Much of his research
involves AIS.  His work blog at <<Schwehr>> contains sample messages
and descriptions of AIS operation in the wild that shed light on
various obscure corners of the specification.  He has explained the
otherwise undocumented Repeat Indicator field and USCG extended AIVDM
to me by email. He also communicated some critical information from
<<IEC-PAS>>, and supplied information about new messages and fields in
ITU-1371-3.

== Improving This Document ==

To avoid copyright difficulties, I rely only on freely redistributable
public documents and paraphrased reports from people who have seen the
relevant proprietary standards.  If you are such a person, please help
by reporting the following to be included in future versions of this
document:

* Field offsets, types, and descriptions for messages 23, 25, and 26
  not described in <<IALA>>.

* Sample sentences of types 6-8, 10, 12-18, 20-23, and 25-26 together with
  decoded dumps of the field values.

== Open-Source Implementations ==

The http://gpsd.berlios.de/[GPSD project] ships an AIVDM/AIVDO
sentence decoder. This document was developed to be the specification
for it, and it will decode all sentence type described herein.

<<Schwehr>> includes links to a collection of Python scripts for
decoding and analyzing AIVDM sentences.  Kurt Schwehr warns that this
is research code rather than a production tool.

There is a http://gnuais.sourceforge.net/[GNU AIS] project at
SourceForge.  It seems intended primarily to work directly
with AIS radios.

There's a http://rl.se/aivdm[web form] that does sentence decoding.
It only understands message types 1-4.

== AIVDM/AIVDO Sentence Layer ==

AIVDM/AIVDO is a two-layer protocol.  The outer layer is a variant of
NMEA 0183, the ancient standard for data interchange in marine
navigation systems; NMEA 0183 is described at <<NMEA>>.

Here is a typical AIVDM data packet:

--------------------------------------------------------------------
!AIVDM,1,1,,B,177KQJ5000G?tO`K>RA1wUbN0TKH,0*5C
--------------------------------------------------------------------

And here is what the fields mean:

Field 1, !AIVDM, identifies this as an AIVDM packet.

Field 2 (1 in this example) is the count of fragments in the currently
accumulating message.  The payload size of each sentence is limited by
NMEA 0183's 82-character maximum, so it is sometimes required to split
a payload over several fragment sentences.

Field 3 (1 in this example) is the fragment number of this
sentence. It will be one-based.  A sentence with a fragment count of
1 and a fragment number of 1 is complete in itself.

Field 4 (empty in this example) is a sequential message ID for
multi-sentence messages.

Field 5 (B in this example) is a radio channel code. AIS uses the high
side of the duplex from two VHF radio channels: AIS Channel A is
161.975Mhz (87B); AIS Channel B is 162.025Mhz (88B).

Field 6 (177KQJ5000G?tO`K>RA1wUbN0TKH in this example) is the data
payload. We'll describe how to decode this in later sections.

Field 7 (0) is the number of fill bits requires to pad the data 
payload to a 6 bit boundary, ranging from 0 to 5.

The \*-separated suffix (\*5C) is the NMEA 0183 data-integrity checksum
for the sentence, preceded by "*".  It is computed on the entire
sentence including the AIVDM tag but excluding the leading "!".

For comparison, here is an example of a multifragment sentence with a
nonempty message ID field:

--------------------------------------------------------------------
!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E
!AIVDM,2,2,3,B,1@0000000000000,2*55
--------------------------------------------------------------------

== AIVDM/AIVDO Payload Armoring ==

The data payload is an ASCII-encoded bit vector.  Each character
represents six bits of data.  To recover the six bits, subtract 48
from the ASCII character value; if the result is greater than 40
subtract 8. According to <<IEC-PAS>>, the valid ASCII characters for
this encoding begin with "0" (64) and end with "w" (87); however, the
intermediate range "X" (58) to "\_" (95) is not used.  

.ASCII payload armoring
`--------`-------`---------`-------
 Char    ASCII   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
---------------------------------------

Concatenate all six-bit quantities found in the payload, MSB first.
This is the binary payload of the sentence.  

Note: There are references to "bit-stuffing" in the <<IALA>>
clarifications describing certain payload fields.  <<C2>> reveals the
following in 3.2.2.1: "The bitstream is subject to bit stuffing. This
means that if more than 5 consecutive 1s are found in the output bit
stream, a zero is inserted. This applies to all bits except the
databits of HDLC flags."  <<IALA>> clarifies as follows: "On the
transmitting side, this means that if five (5) consecutive ones (1s)
are found in the output bit stream, a zero should be inserted after
the five (5) consecutive ones (1s). This applies to all bits between
the HDLC flags [...] On the receiving side, the first zero after five
(5) consecutive ones (1s) should be removed."

It appears that this bit stuffing is meant to be performed by the AIS
radio link layer at transmission time and undone at reception time,
and should not be visible in AIVDM payloads reported by the
receiver.  Nevertheless we document it here because it is just the
sort of thing that is (a) likely to confuse implementors reading
the public sources, and (b) all too likely to become visible if there
are firmware or software errors in the transmission chain.

== AIVDM/AIVDO Six-Bit ASCII ==

Character-string fields within AIVDM/AIVDO messages are encoded in a
special way, referred to as "six-bit" in the tables below. Each
six-bit segment maps to an ASCII character.  Segments 0-31 map to the
characters "@" ( ASCII 64) through "\_" (ASCII 95) respectively;
segments 32-63 map to characters " " (ASCII 32) though "?"  (ASCII
63). Lowercase ASCII letters, the backtick, right and left curly
brackets, pipe bar, tilde and DEL cannot be encoded.

`------`---`------`------`---`--------------`------`---`-------`------`---`----
000000  0  "@"    010000 16  "P"            100000 32  " "     110000 48  "0"
000001  1  "A"    010001 17  "Q"            100001 33  "!"     110001 49  "1"
000010  2  "B"    010010 18  "R"            100010 34  """     110010 50  "2"
000011  3  "C"    010011 19  "S"            100011 35  "\#"    110011 51  "3"
000100  4  "D"    010100 20  "T"            100100 36  "$"     110100 52  "4"
000101  5  "E"    010101 21  "U"            100101 37  "%"     110101 53  "5"
000110  6  "F"    010110 22  "V"            100110 38  "&"     110110 54  "6"
000111  7  "G"    010111 23  "W"            100111 39  "\'"    110111 55  "7"
001000  8  "H"    011000 24  "X"            101000 40  "("     111000 56  "8"
001001  9  "I"    011001 25  "Y"            101001 41  ")"     111001 56  "9"
001010 10  "J"    011010 26  "Z"            101010 42  "\*"    111010 58  ":"
001011 11  "K"    011011 27  "["            101011 43  "\+"    111011 59  ";"
001100 12  "L"    011100 28  "{backslash}"  101100 44  ","     111100 60  "<"
001101 13  "M"    011101 29  "]"            101101 45  "-"     111101 61  "="
001110 14  "N"    011110 30  "\^"           101110 46  "."     111110 62  ">"
001111 15  "O"    011111 31  "\_"           101111 47  "/"     111111 63  "?"
-----------------------------------------------------------------------------

According to the standard, trailing unused characters in six-bit
fields will be represented by "@" (six-bit zero). It is common to
space-fill the fields instead, so a decoder should strip trailing
spaces well as at-signs.

== AIVDM/AIVDO Payload Interpretation ==

AIVDM data is encoded as bitfields in the sentence.  The bitfields are
generally interpreted as big-endian twos-complement integers; when
signed, the sign bit is the highest.  Many fields have an associated
divisor which should be applied to convert to the correct units.

Note that many sources use 1-origin numbering for the bits.  We'll
use 0-origin in this document.

The message type names are somewhat variable across different public
sources. Whatever ITU-1371 says should be considered authoritative,
but the variations I have seen appear to have no practical consequences.

The first 6 bits of the payload (0-5) are the message type.  Message
types are as follows:

.Message types
`--`-------------------------------------------------
01 Position Report Class A
02 Position Report Class A (Assigned schedule)
03 Position Report Class A (Response to interrogation)
04 Base Station Report
05 Ship and Voyage data
06 Addressed Binary Message
07 Binary Acknowledge
08 Binary Broadcast Message
09 Standard SAR Aircraft Position Report
10 UTC and Date Inquiry
11 UTC and Date Response
12 Addressed Safety Related Message
13 Safety Related Acknowledge
14 Safety Related Broadcast Message
15 Interrogation
16 Assigned Mode Command
17 GNSS Binary Broadcast Message
18 Standard Class B CS Position Report
19 Extended Class B Equipment Position Report
20 Data Link Management
21 Aid-to-Navigation Report
22 Channel Management
23 Group Assignment Command
24 Class B CS Static Data Report 
25 Binary Message, Single Slot
26 Binary Message, Multiple Slot
-----------------------------------------------------

In normal operation, an AIS transceiver will send a position report
(type 1, 2, or 3) every 2 to 10 seconds depending on the vessel's
speed while underway, and every 3 minutes while the vessel is at
anchor and stationary. It will send a type 5 identification every 6
minutes.   (More detail is at <<IALA>>, part 2.3)

Class 6 is used for unencrypted structured extension messages by local
authorities such as the St. Lawrence Seaway and The U.S Coast Goard's 
PAWSS.

Class 8 is in common use for private encrypted messages, such as
location transmission in military exercises. It is also used for
unencrypted structured extension messages by local authorities 
such as the St. Lawrence Seaway and PAWSS.

Classes 12 and 14 are used for safety-related text messaging.

In practice, message types other than 1, 3, 4, 5, 18, and 24 are
unusual or rare; many AIS transponders never emit them.

An MMSI is a Mobile Marine Service Identifier, a unique 9-digit ID 
for the ship's radio(s).  The first three digits convey information
about the country in which the ID was issued <<ITU-MID>>.

Detailed descriptions of message types 1-22 and 24 follow. Message
types 1-22 are derived from <<IALA>>. Message types 23-24 are listed
at <<BOSUN>> with no further information; message types 25-26 are
reported by <<Schwehr>>, who observes they were added in Version 3 of
<<ITU1371>>.

The "Member" column in these tables is not derived from any of the ITU
standards or amendments.  I have invented it in order to be able to
describe a lossless textual encoding of AIS sentences.  These names
are also chosen for suitability as structure/object member names in
computer languages, so that application programming interfaces across
different languages can have a common and readily intelligible set to
use.

The field breakdowns in this document have been checked against live
decoded data rendered by known-good implementations for message types
1-5, 9-11, 18-19, and 24.  Described but unchecked are 6-8, 12-17, and
20-22.

=== Types 1, 2 and 3: Position Report Class A ===

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.

.Common Navigation Block
`-------`---`------------------------`--------`--------------------------------
Field   Len Description              Member   Units
-------------------------------------------------------------------------------
0-5      6  Message Type             type     Unsigned integer: 1-3
6-7      2  Repeat Indicator         repeat   3 = "Do not repeat"; see below..
8-37    30  MMSI                     mmsi     Unsigned integer: 9 digits
38-41    4  Navigation Status        status   See table below
42-49    8  Rate of Turn (ROT)       turn     Signed integer: see below
50-59   10  Speed Over Ground (SOG)  speed    Unsigned integer: see below
60-60    1  Position Accuracy        accuracy See below
61-88   28  Longitude                lon      Minutes/10000 (see below)
89-115  27  Latitude                 lat      Minutes/10000 (see below)
116-127 12  Course Over Ground (COG) course   Relative to true north,
                                              to 0.1 degree precision
128-136  9  True Heading (HDG)       heading  0 to 359 degrees, 
                                              511 = not available
137-142  6  Time Stamp               second   Second of UTC timestamp
143-144  2  Maneuver Indicator       maneuver See below
145-147  3  Spare                    
148-148  1  RAIM flag                raim     See below
149-167 19  Radio status             radio    See below
-------------------------------------------------------------------------------

The Repeat Indicator is a directive to an AIS transceiver that this
message should be rebroadcast.  This was intended as a way of getting
AIS messages around hills and other obstructions in coastal waters,
but is little used as base station coverage is more effective.  It is
intended that the bit be incremented on each retransmission, to a
maximum of three hops.

.Navigation status codes
`-`-------------------------------------------------------------
0  Under way using engine  
1  At anchor
2  Not under command
3  Restricted manoeuverability
4  Constrained by her draught
5  Moored
6  Aground
7  Engaged in Fishing
8  Under way sailing
9  Reserved for future amendment of Navigational Status for HSC
10 Reserved for future amendment of Navigational Status for WIG
11 Reserved for future use
12 Reserved for future use
13 Reserved for future use
14 Reserved for future use
15 Not defined (default)
---------------------------------------------------------------

Turn rate is encoded as follows:

* 0...126 = turning right at up to 708 degrees per minute or higher
* 0...-126 = turning left at up to 708 degrees per minute or higher
* 127 = turning right at more than 5deg/30s (No TI available)
* -127 = turning left at more than 5deg/30s (No TI available)
* –128 (80 hex) indicates no turn information available (default)

Values between 0 and 708 degrees/min coded by ROT~AIS~=4.733 *
SQRT(ROT~sensor~) degrees/min where ROT~sensor~ is the Rate of Turn as
input by an external Rate of Turn Indicator. ROT~AIS~ is rounded to
the nearest integer value.  Thus, to decode the field value, square it
and divide by 4.733. Sign of the field value should be preserved when
squaring it, otherwise the left/right indication will be lost.

Speed over ground is in 0.1-knot resolution from 0 to 102 knots.
value 1023 indicates speed is not available, value 1022 indicates
102.2 knots or higher.

Position accuracy flag indicates the accuracy of the fix.  A value of
1 indicates a DGPS-quality fix with an accuracy of < 10ms.  0, the
default, indicates an unaugmented GNSS fix with accuracy > 10m.

Longitude is given in in 1/10000 min; divide by 600000.0 to obtain
degrees. Values up to plus or minus 180 degrees, East = positive, West
= negative.  A value of 181 degrees (0x6791AC0 hex) indicates that
longitude is not available and is the default.

Latitude is given in in 1/10000 min; divide by 600000.0 to obtain
degrees. Values up to plus or minus 90 degrees, North = positive,
South = negative. A value of 91 degrees (0x3412140 hex) indicates
latitude is not available and is the default.

Course over ground will be 3600 (0xE10) if that data is not available.

Seconds in UTC timestamp should be 0-59, except for these special values:

* 60 if time stamp is not available (default)
* 61 if positioning system is in manual input mode
* 62 if Electronic Position Fixing System operates in estimated (dead
     reckoning) mode,
* 63 if the positioning system is inoperative.

The Regional Reserved field is intended for use by local maritime
authorities.  It is not known to be in any actual use up to 2009.

The Maneuver Indicator (143-144) may have these values:

* 0 = Not available (default)
* 1 = No special maneuver
* 2 = Special maneuver (such as regional passing arrangement)

The interpretation of bits 143-147 has been a bit unstable. In
<<IALA>>. and therefore in the original <<ITU1371>>, they were 
described like this:

`-------`---`------------------
Field   Len Description        
-------------------------------
143-145  3  Regional Reserved  
146-147  2  Spare              
-------------------------------

The interpretation of 143-144 as a special maneuver field is new in
revision 3 of <<ITU1371>>.

The RAIM flag indicates whether Receiver Autonomous Integrity
Monitoring is being used to check the performance of the EPFD.
0 = RAIM not in use(default), 1 = RAIM in use.  See <<RAIM>> for
a detailed description of this flag.

Bits 149-167 are diagnostic information for the radio system.  Consult
<<IALA>> for detailed description of the latter.  Total of 168 bits,
occupying one AIVDM sentence.

=== Type 4: Base Station Report ===

Total of 168 bits, occupying one AIVDM sentence.

The standard uses "EPFD" to designate any Electronic Position Fixing Device.

`-------`----`----------------`--------`----------------------------------------
Field   Len  Description      Member   Units
--------------------------------------------------------------------------------
0-5       6  Message Type     type     Unsigned integer: 4
6-7       2  Repeat Indicator repeat   Unknown
8-37     30  MMSI             mmsi     Unsigned integer: 9 digits
38-51    14  Year             year     UTC, 1-999, 0 = not available (default)
52-55     4  Month            month    1-12; 0 = not available (default)
56-60     5  Day              day      1-31; 0 = not available (default)
61-65     5  Hour             hour     0-23; 24 = not available (default)
66-71     6  Minute           minute   0-59; 60 = not available (default)
72-77     6  Second           second   0-59; 60 = not available (default)
78-78     1  Fix quality      accuracy As in Common Navigation Block
79-106   28  Longitude        lon      As in Common Navigation Block
107-133  27  Latitude         lat      As in Common Navigation Block
134-137   4  Type of EPFD     epfd     See below
138-147  10  Spare                     Not used
148-148   1  RAIM flag        raim     As for common navigation block
149-167  19  SOTDMA state     radio    As in same bits for Type 1
--------------------------------------------------------------------------------

.EPFD fix type codes
`----`----------------------------
Code Position Fix Type
----------------------------------
0    Undefined (default)
1    GPS
2    GLONASS
3    Combined GPS/GLONASS
4    Loran-C
5    Chayka
6    Integrated navigation system
7    Surveyed
8    Galileo
----------------------------------

=== Type 5: Ship static and voyage related data ===

Message has a total of 424 bits, occupying two AIVDM sentences.

In practice, the information in these fields (especially ETA and
destination) is not reliable, as it has to be hand-updated by
humans rather than gathered automatically from sensors.

`-------`---`----------------------`------------`------------------------------
Field   Len Description            Member       Encoding   
-------------------------------------------------------------------------------
0-5       6 Message Type           type         Unsigned integer: 5
6-7       2 Repeat Indicator       repeat       Message repeat count
8-37     30 MMSI                   mmsi         Unsigned integer: 9 digits
38-39     2 AIS Version            ais_version  0=<<ITU1371>>, 
                                                1-3 = future editions
40-69    30 IMO Number             imo          Unsigned IMO ship ID number
70-111   42 Call Sign              callsign     7 six-bit characters
112-231 120 Vessel Name            shipname     20 six-bit characters
232-239   8 Ship Type              shiptype     See table below
240-248   9 Dimension to Bow       to_bow       Unsigned integer: Meters
249-257   9 Dimension to Stern     to_stern     Unsigned integer: Meters
258-263   6 Dimension to Port      to_port      Unsigned integer: Meters
264-269   6 Dimension to Starboard to_starboard Unsigned integer: Meters
270-273   4 Position Fix Type      epfd         As in Type 4 EPSD codes
274-277   4 ETA month              month        1-12, 0=not available (default)
278-282   5 ETA day                day          1-31, 0=not available (default)
283-287   5 ETA hour               hour         0-23, 24=not available (default)
288-293   6 ETA minute             minute       0-59, 60=not available (default)
294-301   8 Draught                second       Unsigned integer: Meters
302-421 120 Destination            destination  20 6-bit characters
422-422   1 DTE                    dte          0=Data terminal ready, 
                                                1=Not ready (default)
423-423   1 Spare                               Not used
-------------------------------------------------------------------------------

Ship dimensions will be 0 if not available. For the dimensions to bow
and stern, the special value 511 indicates 511 meters or greater; for
the dimensions to port and starboard, the special value 63 indicates
63 meters or greater.

.Codes for Ship Type
`------`-----------------------------------------------------
Code   Ship & Cargo Classification
-------------------------------------------------------------
0      Not available (default)
1-19   Reserved for future use
20     Wing in ground (WIG), all ships of this type
21     Wing in ground (WIG), Hazardous category A
22     Wing in ground (WIG), Hazardous category B
23     Wing in ground (WIG), Hazardous category C
24     Wing in ground (WIG), Hazardous category D
25     Wing in ground (WIG), Reserved for future use
26     Wing in ground (WIG), Reserved for future use
27     Wing in ground (WIG), Reserved for future use
28     Wing in ground (WIG), Reserved for future use
29     Wing in ground (WIG), Reserved for future use
30     Fishing
31     Towing
32     Towing: length exceeds 200m or breadth exceeds 25m
33     Dredging or underwater ops
34     Diving ops
35     Military ops
36     Sailing
37     Pleasure Craft
38     Reserved
39     Reserved
40     High speed craft (HSC), all ships of this type
41     High speed craft (HSC), Hazardous category A
42     High speed craft (HSC), Hazardous category B
43     High speed craft (HSC), Hazardous category C
44     High speed craft (HSC), Hazardous category D
45     High speed craft (HSC), Reserved for future use
46     High speed craft (HSC), Reserved for future use
47     High speed craft (HSC), Reserved for future use
48     High speed craft (HSC), Reserved for future use
49     High speed craft (HSC), No additional information
50     Pilot Vessel
51     Search and Rescue vessel
52     Tug
53     Port Tender
54     Anti-pollution equipment
55     Law Enforcement
56     Spare - Local Vessel
57     Spare - Local Vessel
58     Medical Transport
59     Ship according to RR Resolution No. 18
60     Passenger, all ships of this type
61     Passenger, Hazardous category A
62     Passenger, Hazardous category B
63     Passenger, Hazardous category C
64     Passenger, Hazardous category D
65     Passenger, Reserved for future use
66     Passenger, Reserved for future use
67     Passenger, Reserved for future use
68     Passenger, Reserved for future use
69     Passenger, No additional information
70     Cargo, all ships of this type
71     Cargo, Hazardous category A
72     Cargo, Hazardous category B
73     Cargo, Hazardous category C
74     Cargo, Hazardous category D
75     Cargo, Reserved for future use
76     Cargo, Reserved for future use
77     Cargo, Reserved for future use
78     Cargo, Reserved for future use
79     Cargo, No additional information
80     Tanker, all ships of this type
81     Tanker, Hazardous category A
82     Tanker, Hazardous category B
83     Tanker, Hazardous category C
84     Tanker, Hazardous category D
85     Tanker, Reserved for future use
86     Tanker, Reserved for future use
87     Tanker, Reserved for future use
88     Tanker, Reserved for future use
89     Tanker, No additional information
90     Other Type, all ships of this type
91     Other Type, Hazardous category A
92     Other Type, Hazardous category B
93     Other Type, Hazardous category C
94     Other Type, Hazardous category D
95     Other Type, Reserved for future use
96     Other Type, Reserved for future use
97     Other Type, Reserved for future use
98     Other Type, Reserved for future use
99     Other Type, no additional information
-------------------------------------------------------------

=== Type 6: Addressed Binary Message ===

Message type 6 is an addressed point-to-point message with unspecified
binary payload.  The St. Lawrence Seaway AIS system and the USG PAWSS
system use this payload for local extension messages. It is variable
in length up to a maximum of 1008 bits (up to 5 AIVDM sentence
payloads).

`-------`---`----------------`--------------`-----------------------------------
Field   Len Description      Member         Units
--------------------------------------------------------------------------------
0-5       6 Message Type     type           Unsigned integer: 6
6-7       2 Repeat Indicator repeat         As in Common Navigation Block
8-37     30 Source MMSI      mmsi           Unsigned integer: 9 digits
38-39     2 Sequence Number  seqno          Unsigned integer 0-3
40-69    30 Destination MMSI dest_mmsi      Unsigned integer: 9 digits
70        1 Retransmit flag  retransmit     0 = no retransmission (default)
                                            1 = retransmitted
71        1 Spare                           Not used
72-87    16 Application ID   app_id         Unsigned integer
88      920 Data             data           Binary data
                                            Field may be shorter than 920 bits.
-------------------------------------------------------------------------------

=== Type 7: Binary Acknowledge ===

Message type 7 is a receipt acknowledgement to the senders of a
previous messages of type 6.  Total length varies between 72 and 168
bits depending on the number of destination MMSIs included.

`-------`---`----------------`--------`-----------------------------------------
Field   Len Description      Member   Units
--------------------------------------------------------------------------------
0-5       6 Message Type     type     Unsigned integer: 7
6-7       2 Repeat Indicator repeat   As in Common Navigation Block
8-37     30 Source MMSI      mmsi     Unsigned integer: 9 digits
38-39     2 Spare                     Not used
40-69    30 MMSI number 1    mmsi1    Unsigned integer: 9 digits
70-71     2 Spare                     Not used
62-101   30 MMSI number 2    mmsi2    Unsigned integer: 9 digits
102-103   2 Spare                     Not used
104-133  30 MMSI number 3    mmsi3    Unsigned integer: 9 digits
134-135   2 Spare                     Not used
136-165  30 MMSI number 4    mmsi4    Unsigned integer: 9 digits
166-167   2 Spare                     Not used
-------------------------------------------------------------------------------

=== Type 8: Binary Broadcast Message ===

Message type 8 is a broadcast message with unspecified binary payload.
The St. Lawrence Seaway AIS system and the USG PAWSS system use this
payload for local extension messages. It is variable in length up to a
maximum of 1008 bits (up to 5 AIVDM sentence payloads).

`-------`---`-----------------`--------------`---------------------------------
Field   Len Description       Member         Units
-------------------------------------------------------------------------------
0-5       6 Message Type      type           Unsigned integer: 8
6-7       2 Repeat Indicator  repeat         As in Common Navigation Block
8-37     30 Source MMSI       mmsi           Unsigned integer: 9 digits
38-39     2 Spare                            Not used
40-55    16 Application ID    app_id         Unsigned integer
56      952 Data              data           Binary data
                                             Field may be shorter than 952 bits.
-------------------------------------------------------------------------------

=== Type 9: Standard SAR Aircraft Position Report ===

Tracking information for search-and-rescue aircraft.  Total number of
bits is 168.

`-------`---`------------------`----------`------------------------------------
Field   Len Description        Member     Encoding   
-------------------------------------------------------------------------------
0-5      6  Message Type       type       Unsigned integer: 9
6-7      2  Repeat Indicator   repeat     As in Common Navigation Block
8-37    30  MMSI               mmsi       Unsigned integer: 9 digits
38-49   12  Altitude           alt        Unsigned integer: See below
50-59   10  SOG                speed      Unsigned integer: See below
60-60    1  Position Accuracy  accuracy   See below
61-88   28  Longitude          lon        Minutes/10000 (as in CNB)
89-115  27  Latitude           lat        Minutes/10000 (as in CNB)
116-127 12  Course Over Ground course     Relative to true north to 0.1 degree
128-133  6  Time Stamp         second     Unsigned integer: UTC second.
134-141  8  Regional reserved  regional
142-142  1  DTE                reserved   0=Data terminal ready, 
                                          1=Data terminal not ready (default)
143-145  3  Spare                         Not used
146-146  1  Assigned           assigned   Assigned-mode flag
147-147  1  RAIM flag          raim       As for common navigation block
148-167 20  Radio status       radio      See <<IALA>> for details.
-------------------------------------------------------------------------------

Altitude is in meters.  The special value 4095 indicates altitude is
not available; 4094 indicates 4094 meters or higher.

Speed over ground is in knots, not deciknots as in the common
navigation block; planes go faster. The special value 1023 indicates
speed not available, 1022 indicates 1022 knots or higher.

Position Accuracy, Longitude, Latitude, and Course over Ground
are encoded identically as in the common navigation block and
are even at the same bit offsets.  Time stamp has the same special
values as in the common navigation block, but is at a different offset.

=== Type 10: UTC/Date Inquiry ===

Request for UTC/Date information from an AIS base station. Total
number of bits is 72.

`-------`---`------------------`----------`------------------------------------
Field   Len Description        Member     Encoding   
-------------------------------------------------------------------------------
0-5      6  Message Type       type       Unsigned integer: 9
6-7      2  Repeat Indicator   repeat     As in Common Navigation Block
8-37    30  Source MMSI        mmsi       Unsigned integer: 9 digits
38-39    2  Spare                         Not used
40-69   30  Destination MMSI   dest_mmsi  Unsigned integer: 9 digits
70-71    2  Spare                         Not used
-------------------------------------------------------------------------------

=== Type 11: UTC/Date Response ===

Identical to message 4, with the semantics of a response to inquiry.

=== Type 12: Safety-Related Message ===

This is a point-to-point text message.  The payload is interpreted as
six-bit text.  This message is variable in length up to a maximum of
1008 bits (up to 5 AIVDM sentence payloads).

`-------`---`------------------`-----------`-----------------------------------
Field   Len Description        Member      Units
-------------------------------------------------------------------------------
0-5       6 Message Type       type        Unsigned integer: 12
6-7       2 Repeat Indicator   repeat      As in Common Navigation Block
8-37     30 Source MMSI        mmsi        Unsigned integer: 9 digits
38-39     2 Sequence Number    seqno       Unsigned integer 0-3
40-69    30 Destination MMSI   dest_mmsi   Unsigned integer: 9 digits
70        1 Retransmit flag    retransmit  0 = no retransmission (default)
                                           1 = retransmitted
71        1 Spare                          Not used
72      936 Text               text        1-156 chars of six-bit encoded text.
                                           Field may be shorter than 936 bits.
-------------------------------------------------------------------------------

=== Type 13: Safety-Related Acknowledge ===

Message type 13 is a receipt acknowledgement to senders of
previous messages of type 12.  The message layout is identical to
a type 7 Binary Acknowledge.

=== Type 14: Safety-Related Broadcast Message ===

This is a broadcast text message.  The payload is interpreted as
six-bit text.  This message is variable in length up to a maximum of
1008 bits (up to 5 AIVDM sentence payloads).

`-------`---`------------------`---------`-------------------------------------
Field   Len Description        Member    Units
-------------------------------------------------------------------------------
0-5       6 Message Type       type      Unsigned integer: 14
6-7       2 Repeat Indicator   repeat    As in Common Navigation Block
8-37     30 Source MMSI        mmsi      Unsigned integer: 9 digits
38-39     2 Spare                        Not used
40      968 Text               text      1-161 chars of six-bit encoded text.
                                         Field may be shorter than 936 bits.
-------------------------------------------------------------------------------

=== Type 15: Interrogation ===

Message type 15 is used by a base station to query one or two other AIS
transceivers for status messages of specified types. "Source MMSI" is
the interrogating station.  88-160 bits depending on the number of queries.

This message is probably not interesting unless you are doing traffic
analysis of information flow in an AIS station network.  The "slot offset" 
members are a request for the response to interrogation to occupy
a particular time division in the TDMA packet layer.

`-------`---`-------------------`---------`-------------------------------------
Field   Len Description         Member    Units
--------------------------------------------------------------------------------
0-5       6 Message Type        type      Unsigned integer: 15
6-7       2 Repeat Indicator    repeat    As in Common Navigation Block
8-37     30 Source MMSI         mmsi      Unsigned integer: 9 digits
38-39     2 Spare                         Not used
40-69    30 Interrogated MMSI   mmsi1     Unsigned integer: 9 digits
70-75     6 First message type  type1_1   Unsigned integer
76-87    12 First slot offset   offset1_1 Unsigned integer
88-89     2 Spare                         Not used
90-95     6 Second message type type1_2   Unsigned integer
96-107   12 Second slot offset  offset1_2 Unsigned integer
108-109   2 Spare                         Not used
110-139  30 Interrogated MMSI   mmsi2     Unsigned integer: 9 digits
140-145   6 First message type  type2_1   Unsigned integer
146-157  12 First slot offset   offset2_1 Unsigned integer
158-159   2 Spare                         Not used
------------------------------------------------------------------------------

There are four use cases for this message.  A decoder must dispatch on
the length of the data packet to determine which it is seeing:

1. One station is interrogated for one message type.  Length is 88-90 bits.

2. One station is interrogated for two message types, Length is 108-110 bits.

3. Two stations are interrogated for one message type each. Length is
158-160 bits.  The second message type and second slot offset associated
with the first queried MMSI should be zeroed.

4. One station is interrogated for two message types, and a second for
one message type.  Length is 158-160 bits.

The reason the lengths given here vary by up to two bits is that
<<IALA>> is not consistent about whether it expects trailing spare
bits to be included in the data packet. The shortest message length is
given as 88, implying that in case 1 the trailing spare bits 88-89 are
not expected to be sent.  The longest message length is gven as 160,
implying that in cases 3 and 4 the trailing spare bits 159-160 are
expected to be sent.  A robust decoder should check for both possible
lengths in each case.

=== Type 16: Assigned Mode Command ===

Message type 16 is used by a base station with control authority to
configure the scheduling of AIS informational messages from
subordinate stations, either as a frquency per 10-minute interval or
by specifying the TDMA slot(s) offset on which those messages should
be transmitted.  It is probably not of interest unless you are
studying the internal operation of an AIS base station network.
Length may be 96 or 144 bits.

`-------`---`-------------------`----------`------------------------------------
Field   Len Description         Member     Units
--------------------------------------------------------------------------------
0-5       6 Message Type        type       Unsigned integer: 16
6-7       2 Repeat Indicator    repeat     As in Common Navigation Block
8-37     30 Source MMSI         mmsi       Unsigned integer: 9 digits
38-39     2 Spare                          Not used
40-69    30 Destination A MMSI  mmsi1      Unsigned integer: 9 digits
70-81    12 Offset A            offset1    See <<IALA>>
82-91    10 Increment A         increment1 See <<IALA>>
92-121   30 Destination B MMSI  mmsi2      Unsigned integer: 9 digits
122-133  12 Offset B            offset2    See <<IALA>>
134-143  10 Increment B         increment2 See <<IALA>>
------------------------------------------------------------------------------

If the message is 96 bits long, it should be interpreted as an
assignment for a single station (92 bits) followed by 4 bits of
padding reserved for future use. If the message is 144 bits long it
should be interpreted as a channel assignment for two stations; no
padding follows.

When increment is zero, the offset field is interpreted as the
frequency with which the subordinate station should report prer
10-minute interval. When increment is nonzero, reporting interval
is specified at the level of TDMA slot numbers; see <<IALA>> for the 
detailed specification.

=== Type 17: GNSS Broadcast Binary Message ===

Message type 17 is used to broadcast differential corrections for GPS.
The data in the payload is intended to be passed directly to GPS
receivers capable of accepting such corrections. 80 to 816 bits
depending on payload size.

`-------`---`-------------------`----------`------------------------------------
Field   Len Description         Member     Units
--------------------------------------------------------------------------------
0-5       6 Message Type        type       Unsigned integer: 16
6-7       2 Repeat Indicator    repeat     As in Common Navigation Block
8-37     30 Source MMSI         mmsi       Unsigned integer: 9 digits
38-39     2 Spare                          Not used
40-57    18 Longitude           lon        Minutes/10
58-74    17 Latitude            lat        Minutes/10
75-79     5 Spare                          Not used - reserved
80-815  736 Payload             data       DGNSS correction data
------------------------------------------------------------------------------

Nore that latitude and longitude are in units of a tenth of a minute;
sign interpretation and out-of-band values are as in the Common
Navigation Clock.  (Note, howeverm that the hex representastion of
the out-of-band values differs; it is 181 \* 60 \* 10 = 0x1a838 for
longitude, 91 \* 60 \* 10 = 0xd548 for latitude.)

The <<IALA>> description of the payload portion subfields has been
omitted, as it appears to be tied to the now obsolete RTCM2 protocol.

=== Type 18: Standard Class B CS Position Report ===

A less detailed report for vessels using Class B transponders.  Omits
navigational status and rate of turn.  Fields are encoded as in the
common navigation block.  168 bits total.

In <<IALA>> (and ITU 1371-1) bits 141-145 were designated "Spare"; the
bit-flag semantics given here are from ITU-1371-3 and were
communicated by Kurt Schwehr.  Kurt warns that "the spec does not do a
good job of explaining these fields... I don't think that I totally
understand these fields."

`-------`---`------------------`---------`-------------------------------------
Field   Len Description        Member    Units
-------------------------------------------------------------------------------
0-5      6  Message Type       type      Unsigned integer: 18
6-7      2  Repeat Indicator   repeat    As in Common Navigation Block
8-37    30  MMSI               mmsi      Unsigned integer: 9 digits
38-45    8  Regional Reserved  reserved
46-55   10  Speed Over Ground  speed     As in common navigation block
56-56    1  Position Accuracy  accuracy  See below
57-84   28  Longitude          lon       Minutes/10000 (as in CNB)
85-111  27  Latitude           lat       Minutes/10000 (as in CNB)
112-123 12  Course Over Ground course    Relative to true north to 0.1 degree
124-132  9  True Heading       heading   0 to 359 degrees, 511 = not available
133-138  6  Time Stamp         second    Second of UTC timestamp.
139-140  2  Regional reserved  regional
141-141  1  CS Unit            cs        0=Class B SOTDMA unit
                                         1=Class B CS (Carrier Sense) unit
142-142  1  Display flag       display   0=No visual display, 1=Has display
                                         (Probably not reliable.)
143-143  1  DSC Flag           dsc       If 1, unit is attached to a VHF
                                         voice radio with DSC capability.
144-144  1  Band flag          band      Base stations can command units
                                         to switch frequency.  If this flag
                                         is 1, the unit can use any part
				         of the marine channel
145-145  1  Message 22 flag    msg22     If 1, unit can accept a channel
                                         assignment via Message Type 22.
146-146  1  Assigned           assigned  Assigned-mode flag
147-147  1  RAIM flag          raim      As for common navigation block
148-167 20  Radio status       radio     See <<IALA>> for details.
-------------------------------------------------------------------------------

=== Type 19: Extended Class B CS Position Report ===

A more detailed report for vessels using Class B transponders.  Omits
navigational status and rate of turn.  Fields are encoded as in the
common navigation block and the Type 5 message.  Note that until just
before the reserved field at bit 139 this is identical to message 18.
312 bits total.

In practice, the information in the ship name and dimension fields is
not reliable, as it has to be hand-entered by humans rather than
gathered automatically from sensors.

`--------`---`----------------------`-------------`-----------------------------
Field    Len Description            Member        Units
--------------------------------------------------------------------------------
0-5       6  Message Type           type          Unsigned integer: 19
6-7       2  Repeat Indicator       repeat        As in Common Navigation Block
8-37     30  MMSI                   mmsi          Unsigned integer: 9 digits
38-45     8  Regional Reserved      reserved
46-55    10  Speed Over Ground      speed         As in common navigation block
56-56     1  Position Accuracy      accuracy      See below
57-84    28  Longitude              lon           Minutes/10000 (as in CNB)
85-111   27  Latitude               lat           Minutes/10000 (as in CNB)
112-123  12  Course Over Ground     course        Relative to true north,
                                                  units of 0.1 degrees0.1 degree
124-132   9  True Heading           heading       0 to 359 degrees, 
                                                  511 = not available
133-138   6  Time Stamp             second        Second of UTC timestamp.
139-142   4  Regional reserved      regional
143-262 120  Name                   shipname      20 6-bit characters 
263-270   8  Type of ship and cargo shiptype      As in Message 5
271-279   9  Dimension to Bow       to_bow        Unsigned integer: Meters
280-288   9  Dimension to Stern     to_stern      Unsigned integer: Meters
289-294   6  Dimension to Port      to_port       Unsigned integer: Meters
295-297   6  Dimension to Starboard to_starboard  Unsigned integer: Meters
299-301   4  Position Fix Type      epsd          As in Type 4 EPSD codes
302-303   1  RAIM flag              raim          As for common navigation block
304-305   1  DTE                    dte           0=Data terminal ready, 
306-306   1  Assigned mode flag     assigned      See <<IALA>> for details
307-311   5  Spare                                Unused, should be zero
--------------------------------------------------------------------------------

=== Type 20 Data Link Management Message ===

This message is used to pre-allocate TDMA slots within an AIS base
station network.  It contains no navigational information, and is
unlikely to be of interest unless you are implementing or studying
an AIS base station network. Length varies from 72-160 depending on
the number of slot reservations (1 to 4) in the message.

`--------`---`-----------------`-------------`-----------------------------
Field    Len Description       Member        Units
---------------------------------------------------------------------------
0-5       6  Message Type      type          Unsigned integer: 20
6-7       2  Repeat Indicator  repeat        As in Common Navigation Block
8-37     30  MMSI              mmsi          Unsigned integer: 9 digits
38-39     2  Spare                           Not used
40-51    12  Offset number 1   offset1       Reserved offset number
52-55     4  Reserved slots    number1       Consecutive slots
56-58     3  Time-out          timeout1      Allocation timeout in minutes
59-69    11  Increment         increment1    Repeat increment
70-81    12  Offset number 2   offset2       Reserved offset number
82-85     4  Reserved slots    number2       Consecutive slots
86-88     3  Time-out          timeout2      Allocation timeout in minutes
89-99    11  Increment         increment2    Repeat increment
100-111  12  Offset number 3   offset3       Reserved offset number
112-115   4  Reserved slots    number3       Consecutive slots
116-118   3  Time-out          timeout3      Allocation timeout in minutes
119-129  11  Increment         increment3    Repeat increment
130-141  12  Offset number 4   offset4       Reserved offset number
142-145   4  Reserved slots    number4       Consecutive slots
146-148   3  Time-out          timeout4      Allocation timeout in minutes
149-159  11  Increment         increment4    Repeat increment
---------------------------------------------------------------------------

See <<IALA>> for details on the meaning of these fields.

=== Type 21: Aid-to-Navigation Report ===

Identification and location message to be emitted by aids to
navigation such as buoys and lighthouses.

This message is unusual in that it varies in length depending on the 
presence and size of the Name Extension field. May vary between 272
and 360 bits.

`--------`---`----------------------`------------`------------------------------
Field   Len Description             Member       Units
--------------------------------------------------------------------------------
0-5       6  Message Type           type         Unsigned integer: 21
6-7       2  Repeat Indicator       repeat       As in Common Navigation Block
8-37     30  MMSI                   mmsi         Unsigned integer: 9 digits
38-42     5  Aid type               type         See Below
43-162  120  Name                   name         Name of the aid to navigation
163-163   1  Position Accuracy      accuracy     As in common navigation block
164-191  28  Longitude              lon          Minutes/10000 (as in CNB)
192-218  27  Latitude               lat          Minutes/10000 (as in CNB)
219-227   9  Dimension to Bow       to_bow       Unsigned integer: Meters
228-236   9  Dimension to Stern     to_stern     Unsigned integer: Meters
237-242   6  Dimension to Port      to_port      Unsigned integer: Meters
243-248   6  Dimension to Starboard to_starboard Unsigned integer: Meters
249-252   4  Type of EPFD           epfd         As in Message Type 4
253-258   6  UTC Second             second       As in Message Type 5
259-259   1  Off-Position Indicator off_position See Below
260-267   8  Regional reserved      regional
268-268   1  RAIM flag              raim         As for common navigation block
269-269   1  Virtual-aid flag       virtual_aid  See Below
270-270   1  Assigned-mode flag     assigned     See <<IALA>> for details
271-271   1  Spare                               Not used
272-360  88  Name Extension                      See Below
--------------------------------------------------------------------------------

According to <<IALA>>, the aid type field has values 1-15 for fixed
and 16-31 for floating aids to navigation.  The detailed list is as follows:

`----`-------------------------------------------------------------
Code Definition
-------------------------------------------------------------------
0    Default, Type of Aid to Navigation not specified
1    Reference point
2    RACON
3    Fixed structure off shore, such as oil platforms, wind farms,
     rigs. (Note: This code should identify an obstruction that is
     fitted with an Aid-to-Navigation AIS station.)
4    Spare, Reserved for future use.
5    Light, without sectors
6    Light, with sectors
7    Leading Light Front
8    Leading Light Rear
9    Beacon, Cardinal N
10   Beacon, Cardinal E
11   Beacon, Cardinal S
12   Beacon, Cardinal W
13   Beacon, Port hand
14   Beacon, Starboard hand
15   Beacon, Preferred Channel port hand
16   Beacon, Preferred Channel starboard hand
17   Beacon, Isolated danger
18   Beacon, Safe water
19   Beacon, Special mark
20   Cardinal Mark N
21   Cardinal Mark E
22   Cardinal Mark S
23   Cardinal Mark W
24   Port hand Mark
25   Starboard hand Mark
26   Preferred Channel Port hand
27   Preferred Channel Starboard hand
28   Isolated danger
29   Safe Water
30   Special Mark
31   Light Vessel / LANBY / Rigs
-------------------------------------------------------------------

The name field is 6-bit ASCII.  If this field is full (has no trailing @
characters) the decoder should interpret the Name Extension field
later in the message and concatenate it to this one to obtain the full name.

<<IALA>> describes bits 219-248 As "Dimension/Reference for Position",
implying that it is vessel dimensions as in message type 5.

The Off-Position Indicator is for floating Aids-to-Navigation only: 0
= on position; 1 = off position. Only valid if UTC second is equal to
or below 59.

The Virtual Aid flag is interpreted as follows: 0 = default = real Aid
to Navigation at indicated position; 1 = virtual Aide to
Navigation simulated by nearby AIS station.

If present, the Name Extension consists of packed six-bit ASCII
characters followed by 0-6 bytes of padding to an 8-bit boundary. The
<<IALA>> description says "This parameter should be omitted when no
more than 20 characters for the name of the A-to-N are needed in
total. Only the required number of characters should be transmitted,
i.e. no @-character should be used."  A decoder can deduce the bit length
of the name extension field by subtracting 272 from the total message
bit length.

=== Type 22: Channel Management ===

This message is broadcast by a base station to set VHF parameters for
an AIS coverage region.  It contains no navigational information, and is
unlikely to be of interest unless you are implementing or studying
an AIS base station network. Length is 168 bits.

`--------`---`----------------`------------`------------------------------------
Field   Len Description       Member       Units
--------------------------------------------------------------------------------
0-5       6  Message Type     type         Unsigned integer: 22
6-7       2  Repeat Indicator repeat       As in Common Navigation Block
8-37     30  MMSI             mmsi         Unsigned integer: 9 digits
38-39     2  Spare                         Not used
40-51    12  Channel A        channel_a    Channel number
52-63    12  Channel B        channel_b    Channel number
64-67     4  Tx/Rx mode       mode         Transmit/receive mode
68-68     1  Power            power        Low=0, high=1
69-86    18  NE Longitude     ne_lon       NE corner longitude to 0.1 minutes
87-103   17  NE Latitude      ne_lat       NE corner latitude to 0.1 minutes
104-121  18  SW Longitude     sw_lon       SW corner longitude to 0.1 minutes
122-138  17  SW Latitude      sw_lat       SW corner latitude to 0.1 minutes
139-139   1  Addressed        addressed    0=Broadcast, 1=Addressed
140-140   1  Channel A Band   band_a       0=Default, 1=12.5kHz
141-141   1  Channel A Band   band_a       0=Default, 1=12.5kHz
142-144   3  Zone size        zonesize     Size of transitional zone
145-167  23  Spare                         Reserved for future use
--------------------------------------------------------------------------------

See <<IALA>> for details on the meaning of these fields.

=== Type 24: Class B CS Static Data Report  ===

Equivalent of a Type 5 message for ships using Class B equipment.  A
"Type 24" may be in part A or part B format; either is 168 bits.
Parts A and B are expected to be broadcast in adjacent pairs.  The
interpretation of some fields in Type B format changes depending on
the range of the Type B MMSI field.

<<IALA>> does not describe this message type; format information
is thanks to Kurt Schwehr.

`-------`---`----------------------`---------------`----------------------------
Field   Len Description             Member          Units
--------------------------------------------------------------------------------
0-5       6  Message Type           type            Unsigned integer: 19
6-7       2  Repeat Indicator       repeat          As in CNB
8-37     30  MMSI                   mmsi            Unsigned integer: 9 digits
38-39     2  Part Number            partno          Unsigned integer: 0-1
40-159  120  Vessel Name            shipname        (Part A) 20 six-bit chars
160-167   8  Spare                                  (Part A) Not used
40-47     8  Ship Type              shiptype        (Part B) As in Message Type 5
48-89    42  Vendor ID              vendorid        (Part B) 7 six-bit chars
90-131   42  Call Sign              callsign        (Part B) As in Message Type 5
132-140   9  Dimension to Bow       to_bow          (Part B) Unsigned int: Meters
141-149   9  Dimension to Stern     to_stern        (Part B) Unsigned int: Meters
150-155   6  Dimension to Port      to_port         (Part B) Unsigned int: Meters
156-161   6  Dimension to Starboard to_starboard    (Part B) Unsigned int: Meters
132-161  30  Mothership MMSI        mothership_mmsi (Part B) See below
162-167   8  Spare                                  (Part B) Not used
--------------------------------------------------------------------------------

If the Part Number field is 0, the rest of the message is interpreted
as a Part A; if it is 1, the rest of the message is interpreted
as a Part B; values 2 and 3 are not allowed.

The "Vendor ID" field is the name of the AIS equipment vendor.

Interpretation of the 30 bits 132-162 in Part B is variable. If the
MMSI at 8-37 is that of an auxiliary craft, the entry is taken to
refer to a small attached auxiliary vessel and these 30 bits are read
as the MMSI of the mother ship.  Otherwise the 30 bits describe vessel
dimensions as in Message Type 5.

According to <<MMSI>>, an MMSI is associated with an auxiliary craft
when it is of the form 98MIDXXXX where the digits 3, 4 and 5 represent
the MID and X is any figure from 0 to 9.

== Local extensions ==

Some regional authorities extend the AIS message set.

The St. Lawrence Seaway broadcasts hydrological and lock-scheduling
messages using special encodings of the binary data of message types 6
and 8 (described in <<SEAWAY>>, freely available), and safety
information using types 12 and 14.

The U.S. Coast Guard has a system called PAWSS (Port and Water Safety
System) which uses extended AIS binary formats. <<SEAWAY>> says it's
intercompatible with the St. Lawrence Seaway system; I have not been
able to find any message documentation on PAWSS with which to verify
this, however.

=== U.S. Coast Guard Extended AIVDM ===

You may occasionally see AIVDM packets with additional comma-separated
fields following the CRC-32 checksum.  This is a semi-obsolescent
logging format used by the USCG, which has never documented it well
and plans to replace it with a new one based on NMEA 4.0.

Here's a sample sentence and field breakdown:

-------------------------------------------------------------------------------
!AIVDM,1,1,,B,15Cjtd0Oj;Jp7ilG7=UkKBoB0<06,0*63,s1234,d-119,T12.34567123,r003669958,1085889680
-------------------------------------------------------------------------------

Following the "*63" checksum are additional fields delimited by commas.  
These fields provide additional metadata about the reception of each AIS  
broadcast.

The field beginning with the lower case "s" is a Relative Signal  
Strength Indicator (RSSI) measurement from the receiver. This  
measurement has a range of 0-65535. This is one of the parameters used  
internally by the AIS receiver to determine the signal strength value as  
reported in the field beginning with the lower case "d". This field only  
exists when the AIS receiver provides this data.

The field beginning with a lower case "d" is the signal strength  
measurement for this broadcast in dBm. This field only exists when the  
AIS receiver provides this data.

The field beginning with the upper case "T" is the Time of Arrival  
of the received broadcast in seconds from UTC 0. This field only exists  
when the AIS receiver provides this data.

Another optional field not shown is one that begins with an upper  
case "S" and represents the slot number in which the reception occurred.  
The field would appear after the checksum and before the station  
identifier field. This field only exists when the AIS receiver provides  
this data. Example: S0042

The field beginning with the lower case "r" is a station identifier  
field. This field is always provided, regardless of the type of AIS  
equipment.  (Occasionally a base station identifier will be prefixed with
"b" instead.)

The last field is a time tag based on the standard C programming  
language time function. Both date and time to the nearest second can be  
derived from this field. This field is always provided, regardless of  
the type of AIS equipment.

== References ==

[bibliography]
- [[[AIS]]] http://en.wikipedia.org/wiki/Automatic_Identification_System[Automatic
Identification System]

- [[[ITU1371]]]
  http://www.itu.int/rec/R-REC-M.1371-2-200603-I/en[ITU-R M.1371:
  ITU Recommendation on the Technical Characteristics for a Universal
  Shipborne Automatic Identification System (AIS) using Time Division
  Multiple Access in the Maritime Mobile Band]. 
  Reference included for completeness; I have not looked at it.

- [[[IALA]]]  http://www.ialathree.org/iala/pages/AIS/IALATech1.5.pdf[IALA
  Technical Clarifications on Recommendation ITU-R M.1371-1]

- [[[NAVCEN]]] http://www.navcen.uscg.gov/enav/ais/[NAVCEN AIS pages]

- [[[BOSUN]]] http://www.bosunsmate.org/ais/[Marine Automatic
  Identification System (AIS)]

- [[[NMEA]]] http://gpsd.berlios.de/standards/NMEA.txt[NMEA sentences]

- [[[SEAWAY]]] http://www.greatlakes-seaway.com/en/pdf/aisdata.pdf[St. Lawrence
  Seaway AIS Data Messaging Formats and Specifications]

- [[[Schwehr]]] http://schwehr.org/blog/[Kurt Schwehr's weblog]

-  [[[IEC-PAS]]] IEC-PAS 61162-100, "Maritime navigation and
   radiocommunication equipment and systems"  The six-bit encoding
   is described on page 26 of Annex C, Table C-1.  Communicated by 
   Kurt Schwehr; I have not looked at it.

- [[[ITU-MID]]] http://www.itu.int/cgi-bin/htsh/glad/cga_mids.sh?lng=E[Table 
  of Maritime Identification Digits]

- [[[RAIM]]] http://en.wikipedia.org/wiki/RAIM[Receiver Autonomous
  Integrity Monitoring]

- [[[C2]]] http://www.uais.org/AISspecificationCorrigendum2.pdf[AIS
  Specification Corrigendum 2]

- [[[MMSI]]] http://www.navcen.uscg.gov/marcomms/gmdss/mmsi.htm#format[MMSI 
  Format]

- [[[JSON-AIS]]] http://wiki.ham.fi/JSON_AIS.en[JSON AIS transmission protocol]

== Change history ==

Version 1.0 was the initial release covering messages 1-3, 4, and 5.

Version 1.1 adds message breakdowns for 9 and 18, explanation of the
Repeat Indicator feld, and the explanation of USCG extended AIVDM.

Version 1.2 adds information on the the ITU1371 edition 3 maneuver field,
and the RAIM flag. It also adds an important clarification about
six-bit decoding.

Version 1.3 adds information on message types 6, 7, 12, and 13, and
attempts to demystify bit-stuffing.

Version 1.4 adds explicit decoding tables for ASCII armoring and
six-bit ASCII.

Version 1.5 corrects the interpretation of field 7 in AIVDM
ASCII-armored sentences.

Version 1.6 corrects some minor errors in the interpretation of Type
5 messages.

Version 1.7 adds descriptions for Type 10, 11, 19, 21, and 24
messages, information about ITU-1371-3 flags in message type 18,
and the new section on Improving This Document.

Version 1.8 fixes some broken markup and adds information about JSON-AIS.

Version 1.9 adds more information on JSON and the member names.

Version 1.10 fixes a typo in the formula for undoing 6-bit armoring.

Version 1.11 describes message types 15, 16, and 17.

Version 1.12 describes messages 20 and 22, and adds navigation aid
type codes.

Version 1.13 documents more out-of-band values and treats radio status
blocks more uniformly.