schwehr / libais

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

Ice Thickness units changed from centimeters to meters #228

Open andyvan-trabus opened 2 years ago

andyvan-trabus commented 2 years ago

The current libais tries to be helpful and convert values. However, I think that's a bad idea:

Here's an example from the processing for the 8:1:21 message.

Table 10.2 (WMO Weather observation report from ship) has the following for Ice deposit (thickness):

BUFR 020031 0 - 126 cm (offset = 0) Thickness = (Integer value) for Integer = 0 - 126 127 = not available = default

However the code in ais8.cpp is converting this from the native centimeters to meters:

ice_thickness = bits.ToUnsignedInt(324, 7) / 100.; // m. Network is cm,

This illustrates a general problem: by processing the values, rather than just extracting them, the resulting values no longer follow the spec. 127 is no longer the N/A value, you need to know that it was divided by 100.0, so now you need to check for 1.27.

We should consider just returning the bitfields as either a signed or unsigned integer, and let client code do the conversion. Or, in cases where we manipulate the value, we should return both an ice_thickness_raw and ice_thickness_meters field.