schwehr / libais

C++ decoder for Automatic Identification System for tracking ships and decoding maritime information
Other
218 stars 97 forks source link

How to parse multi-line messages without stream #158

Closed j0nson closed 6 years ago

j0nson commented 7 years ago

The readme is not clear about how to parse multi-line messages without the stream module. I'm trying to do:

!AIVDM,2,1,4,B,56LUAP02>M9oL`<v2210u<DT@tr0hD4@E:22221?2rhI75Gf0EEDp0PC,0*3A

!AIVDM,2,2,4,B,888888888888880,2*23

t=ais.decode("56LUAP02>M9oL`<v2210u<DT@tr0hD4@E:22221?2rhI75Gf0EEDp0PC888888888888880",0)

And i get this error: AIS_ERROR_BAD_BIT_COUNT

Can anyone help?

IoannisTsalamanis commented 7 years ago

Try changing the last '0' to '2'.

schwehr commented 6 years ago

You need the fill bits from the final part of the message... just before the *

python
>>> import ais
>>> m1 = '#!AIVDM,2,1,4,B,56LUAP02>M9oL`<v2210u<DT@tr0hD4@E:22221?2rhI75Gf0EEDp0PC,0*3A'
>>> m2 = '#!AIVDM,2,2,4,B,888888888888880,2*23'
>>> m = m1.split(',')[5] + m2.split(',')[5]
>>> m
'56LUAP02>M9oL`<v2210u<DT@tr0hD4@E:22221?2rhI75Gf0EEDp0PC888888888888880'
>>> ais.decode(m, 2)
{'destination': 'US BAL              ', 'ais_version': 0, 'draught': 8.5, 'eta_minute': 0, 'dim_c': 25, 'fix_type': 1, 'mmsi': 432624000, 'name': 'POSEIDON LEADER     ', 'id': 5, 'dim_a': 23, 'imo_num': 9335965, 'type_and_cargo': 79, 'eta_hour': 14, 'dte': 0, 'eta_day': 15, 'eta_month': 5, 'dim_d': 7, 'repeat_indicator': 0, 'dim_b': 176, 'callsign': '7JCO   ', 'spare': 0}

The fill bits is found by:

m2.split(',')[6][0]
'2'