Skip to content

Commit

Permalink
implement best effort decoding for type 1,2,3 when there are extra bi…
Browse files Browse the repository at this point in the history
…ts present
  • Loading branch information
pwoods25443 committed Jun 7, 2024
1 parent 96c6dcf commit 5884afc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ais_tools/ais.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ais_tools.transcode import DecodeError
from ais_tools.transcode import ASCII8toAIS6
from ais_tools import ais_1_2_3
from ais_tools import ais5
from ais_tools import ais8
from ais_tools import ais9
Expand All @@ -19,6 +20,9 @@
}

decode_fn = {
1: ais_1_2_3.ais_1_2_3_decode,
2: ais_1_2_3.ais_1_2_3_decode,
3: ais_1_2_3.ais_1_2_3_decode,
5: ais5.ais5_decode,
8: ais8.ais8_decode,
9: ais9.ais9_decode,
Expand Down
10 changes: 10 additions & 0 deletions ais_tools/ais_1_2_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ais as libais
from ais import DecodeError


def ais_1_2_3_decode(body, pad):
try:
return libais.decode(body[:28], 0)
except DecodeError as e:
raise DecodeError(f'TYPE 1-2-3 LIBAIS ERR: {str(e)}')

Check warning on line 9 in ais_tools/ais_1_2_3.py

View check run for this annotation

Codecov / codecov/patch

ais_tools/ais_1_2_3.py#L8-L9

Added lines #L8 - L9 were not covered by tests

13 changes: 13 additions & 0 deletions sample/type1-bad-bitcount.nmea
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\s:rMT4097,t:ais-listener,c:1697012399*7E\!AIVDM,1,1,,A,13UuUj0P00QgDCLEiGAcOOwl2<0Igw;,0*28
\s:rMT1200,t:ais-listener,c:1697012048*78\!AIVDM,1,1,,A,33lP4T5P00QJoU6Fd1<v4?v>2D`Jal<,0*7F
\s:rMT1200,t:ais-listener,c:1697011998*7F\!AIVDM,1,1,,A,13R3iq00001LhHDFVNd@RC@R0<0FPF=,0*6C
\s:rMT6030,t:ais-listener,c:1697011876*78\!AIVDM,1,1,,B,15Ca7j002HQer4PClUD<1qbH089PRn4,0*07
\s:rMT6168,t:ais-listener,c:1697014351*7F\!AIVDM,1,1,,B,16eg3D1P00RT5kHCfSje>Ovr:`AhPc=,0*57
\s:rMT6030,t:ais-listener,c:1697014102*77\!AIVDM,1,1,,A,13R3=u3P00QfIwhCt;09V?v`0530Li7,0*61
\s:rMT1200,t:ais-listener,c:1697011340*70\!AIVDM,1,1,,B,13VOUT002W1KM1hFbSbcrITb0<1Muw>,0*03
\s:rMT6030,t:ais-listener,c:1717190215*76\!AIVDM,1,1,,A,144d5;0uiHQjSVjC6w:iL1Ab26a05d4,0*72
\s:rMT6030,t:ais-listener,c:1717190199*71\!AIVDM,1,1,,A,13lHkf001C1o?`HC3=Oc@8w408Cos:<,0*3D
\s:rMT6030,t:ais-listener,c:1717190200*72\!AIVDM,1,1,,B,19@9=p0P1<1mUP`C7ttkBOw800RqWe=,0*3C
\s:rMT1200,t:ais-listener,c:1717190111*77\!AIVDM,1,1,,B,34i:=V50001K=nbFbsWeH42D2000j0<,0*5F
\s:rMT1200,t:ais-listener,c:1717189944*77\!AIVDM,1,1,,B,33TVdn1P01QK>R`Fc78v4?vh2DlbI03,0*20

4 changes: 3 additions & 1 deletion tests/test_aivdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
('\\s:66,c:1663246931*35\\!AIVDM,1,1,,,9001?BP=h:qJ9vb;:f7EN1h240Rb,0*3F',
{'alt_sensor': 0, 'assigned_mode': False}),
('\\c:1712130370,s:dynamic,t:spire*55\\!AIVDM,1,1,,A,403wboivQ1WfE`4gnt5MJT?024rp,0*24',
{'year': 2024, 'month': 4, 'day': 3, 'hour': 7, 'minute': 46, 'second': 21})
{'year': 2024, 'month': 4, 'day': 3, 'hour': 7, 'minute': 46, 'second': 21}),
('\\s:rMT4097,t:ais-listener,c:1697012399*7E\\!AIVDM,1,1,,A,13UuUj0P00QgDCLEiGAcOOwl2<0Igw;,0*28',
{'id': 1, 'mmsi': 241133000}),
])
def test_decode(nmea, expected):
decoder = AIVDM()
Expand Down

0 comments on commit 5884afc

Please sign in to comment.