M0r13n / pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
MIT License
176 stars 61 forks source link

MessageType24PartA : incorrect length? #120

Closed G7OCD closed 1 year ago

G7OCD commented 1 year ago

Hi, I think this should have spare_1 removed because this should only be 160bits, not 168bits.

M0r13n commented 1 year ago

Hey @G7OCD,

according to the standard, both the A and B parts are supposed to be 168 bits. However, in the wild, A parts are often transmitted with only 160 bits, omitting the 'spare' 7 bits at the end. Implementers should be permissive about this.

G7OCD commented 1 year ago

I'm not sure about this. ITU-R M.1371-5 shows this: image

M0r13n commented 1 year ago

It does appear to be correct; however, the gpsd project page specifies a length of 168 bits. It seems that this is yet another example of an implementation dependent variation. Currently, this project supports both variants: 160 bits and 168 bits. The same applies for the Aggsoft decoder.

I believe we should maintain this flexibility and be liberal in what we accept, don't you agree?"

G7OCD commented 1 year ago

Probably won't cause any harm. I just wanted to make sure you knew.

I only stumbled across this because I am taking a few portion of your code for a Micropython AIS handler and all the test data I have to hand kept breaking 24A message parsing.

M0r13n commented 1 year ago

@G7OCD

Probably won't cause any harm. I just wanted to make sure you knew.

Thanks for bringing this up, anyways. :)

I only stumbled across this because I am taking a few portion of your code for a Micropython AIS handler and all the test data I have to hand kept breaking 24A message parsing.

Is the code that you took from pyais breaking? If so, this should be fixed so that both cases can be handled. May I ask you for some example messages, that break the parser?

G7OCD commented 1 year ago

The class definition includes spare_1, so if you enumerate the fields and consume bits based on this you run out of bits, at least with every Type 24A message I have received off-air which is only ever 160 long. My Micropython code is now almost entirely from scratch because many of the nice python techniques/libraries pyais uses are not available and heap fragmentation has also been a huge issue. So I'm only really using the message classes from pyais.