tbsalling / aismessages

AISmessages is a Java-based light-weight, zero-dependency, and ultra-efficient message decoder for maritime navigation and safety messages compliant with ITU 1371 (NMEA armoured AIS messages). A live demo of AISmessages is available on http://ais.tbsalling.dk.
https://github.com/tbsalling/aismessages/wiki
Other
156 stars 66 forks source link

bitstring Integer sign parsing. #18

Closed ftence closed 6 years ago

ftence commented 6 years ago

Apply two's complement for INTEGER_DECODER.

Changes from INTEGER_DECODER to UNSIGNED_INTEGER_DECODER have to be checked as I'm not an expert on NMEA/AIS messages.

tbsalling commented 6 years ago

Thanks for the contribution! Changes in this area needs particular care - so I will review it as soon as I get time and either merge or give my feeback.

ftence commented 6 years ago

I do agree, these a changes have many implications. I noticed the problem looking at the SOG value with should be -128 when the information is unavailable.

After some reflection I think it should be better to keep Integer.parseInt instead of Integer.parseUnsignedInt.

tbsalling commented 6 years ago

In message type 1, 2 and 3 SOG must be 102.3 when not available. Where do you get -128 from? One of the other message types?

Why do you think it is better to "keep Integer.parseInt instead of Integer.parseUnsignedInt." ?

Some of the unit tests are failing when your changes are applied. I am trying to look into this.

ftence commented 6 years ago

Sorry, I meant ROT, not SOG. Taken from https://www.navcen.uscg.gov/?pageName=AISMessagesA: "-128 (80 hex) indicates no turn information available (default)."

About my remark on the usage of parseInt or parseUnsignedInt. I was concerned that INTEGER_DECODER could be used to decode string of length 33 without error because parseUnsignedInt can accept a string with 32 "1" for instance. Upon reflection, parseUnsignedInt should be kept but a check should be added to INTEGER_DECODER to avoid decoding strings of length 33.

tbsalling commented 6 years ago

Great thanks. And this has not been forgotten - I will resume to it as soon as time permits!

tbsalling commented 6 years ago

Thank you for this contribution which fixed a subtle bug involving ROT and other numeric values derived from a bitstring.