M0r13n / pyais

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

lat lon converters float accuracy #107

Closed AllNamesWereTakenIsNotAvailable closed 1 year ago

AllNamesWereTakenIsNotAvailable commented 1 year ago

for the example sentence: !AIVDM,1,1,,A,100u3g@0291Q1>BW6uDUwDk00LE@,0*74

decode and then encode will results in a change to lat lon

the problem line is:

            elif d_type == float:
                val = int(val)
                bits = int_to_bin(val, width, signed=signed)

Suggested resolution:

            elif d_type == float:
                val = int(round(val))
                bits = int_to_bin(val, width, signed=signed)

Kind Regards

M0r13n commented 1 year ago

Hey @AllNamesWereTakenIsNotAvailable,

thank you bringing this up. It is also very helpful that you included an example message. So it was easy for me to reproduce your issue.

There was indeed a rounding error. I fixed it in the relevant conversion function.

I also included your example as an unit test to prevent future regressions. So I am closing this for now. Feel free to reopen if needed.

Have a great day.

Kind regards, leon

M0r13n commented 1 year ago

The fix is publicly available with version v2.5.1