diff options
-rwxr-xr-x | devtools/ais.py | 10 | ||||
-rw-r--r-- | driver_aivdm.c | 4 | ||||
-rw-r--r-- | test/sample.aivdm | 11 | ||||
-rw-r--r-- | test/sample.aivdm.chk | 1 |
4 files changed, 21 insertions, 5 deletions
diff --git a/devtools/ais.py b/devtools/ais.py index 0700e5f5..c62c81bb 100755 --- a/devtools/ais.py +++ b/devtools/ais.py @@ -410,9 +410,12 @@ type16 = ( bitfield("offset1 ", 12, 'unsigned', 0, "First slot offset"), bitfield("increment1",10, 'unsigned', 0, "First slot increment"), spare(2), - bitfield("mmsi2", 30, 'unsigned', 0, "Interrogated MMSI 2"), - bitfield("offset2", 12, 'unsigned', 0, "Second slot offset"), - bitfield("increment2",10, 'unsigned', 0, "Second slot increment"), + bitfield("mmsi2", 30, 'unsigned', 0, "Interrogated MMSI 2", + conditional=lambda i, v: v['length'] >= 144), + bitfield("offset2", 12, 'unsigned', 0, "Second slot offset", + conditional=lambda i, v: v['length'] >= 144), + bitfield("increment2",10, 'unsigned', 0, "Second slot increment", + conditional=lambda i, v: v['length'] >= 144), spare(2), ) @@ -835,6 +838,7 @@ def parse_ais_messages(source, scaled=False, skiperr=False, verbose=0): # Render assembled payload to packed bytes bits = BitVector() bits.from_sixbit(payload) + values['length'] = bits.bitlen # Magic recursive unpacking operation try: cooked = aivdm_unpack(bits, 0, values, aivdm_decode) diff --git a/driver_aivdm.c b/driver_aivdm.c index 2265c597..eaf53a2b 100644 --- a/driver_aivdm.c +++ b/driver_aivdm.c @@ -357,8 +357,8 @@ bool aivdm_decode(const char *buf, size_t buflen, ais->type16.mmsi1 = UBITS(40, 30); ais->type16.offset1 = UBITS(70, 12); ais->type16.increment1 = UBITS(82, 10); - if (ais_context->bitlen <= 96) - ais->type16.mmsi2 = 0; + if (ais_context->bitlen < 144) + ais->type16.mmsi2=ais->type16.offset2=ais->type16.increment2 = 0; else { ais->type16.mmsi2 = UBITS(92, 30); ais->type16.offset2 = UBITS(122, 12); diff --git a/test/sample.aivdm b/test/sample.aivdm index a3f72fd5..7becbaef 100644 --- a/test/sample.aivdm +++ b/test/sample.aivdm @@ -353,6 +353,17 @@ # First Message Type: 5 # First Slot Offset: 0 # +# Type 16: +# From AISHub. Only a regression test to check that the C and Python decoders +# do the same thing, not yet checked against other decoders. +!AIVDM,1,1,,A,@01uEO@mMk7P<P00,0*18 +# Message Type : 16 +# Repeat Indicator : 0 +# MMSI : 2053501 +# Interrogated MMSI 1 : 224251000 +# First slot offset : 200 +# First slot increment : 0 +# # Type 18: # From Kurt Schwehr # I had to regenerate the CRC32 for this one myself, it was missing diff --git a/test/sample.aivdm.chk b/test/sample.aivdm.chk index 91a7f6b7..3def3d69 100644 --- a/test/sample.aivdm.chk +++ b/test/sample.aivdm.chk @@ -25,6 +25,7 @@ 14,0,237008900,EP228 IX48 FG3 DK7 PL56.
14,0,311764000,TEST
15,0,368578000,5158,5,0,0,0,0,0,0
+16,0,002053501,224251000,200,0,0,0,0
18,0,338087471,0,1,0,-44443279,24410724,796,511,49,0x0,1,0,1,1,1,1,0xe0006
18,0,338088483,0,0,0,-42486718,25869335,1716,511,20,0x0,1,0,1,1,1,1,0xe0006
18,0,368161000,0,51,1,-43340309,23688555,349,511,17,0x0,1,0,1,1,0,1,0xe0006
|