Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libais/ais8_200.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Ais8_200_10::Ais8_200_10(const char *nmea_payload, const size_t pad)
beam = bits.ToUnsignedInt(117, 10) / 10.; // m
ship_type = bits.ToUnsignedInt(127, 14);
haz_cargo = bits.ToUnsignedInt(141, 3);
draught = bits.ToUnsignedInt(144, 11) / 10.; // m
draught = bits.ToUnsignedInt(144, 11) / 100.; // m
loaded = bits.ToUnsignedInt(155, 2);
speed_qual = bits[157];
course_qual = bits[158];
Expand Down
25 changes: 25 additions & 0 deletions src/test/ais8_200_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ TEST(Ais8_200_10Test, DecodeAnything) {
0, 0, 0, 0, 0, 0);
}

TEST(Ais8_200_10Test, DraughtUsesCentimetres) {
// Existing fixture with only the 11-bit inland draught field changed.
// Inland AIS FI 10 uses centimetres; length and beam use decimetres.
{
Ais8_200_10 msg("85NLn@0j2d<8000000BhI?`50000", 0);
Validate8_200_10(&msg, 0, 367474240, "foo", 15, 5, 8000, 5,
0.0, 0, 0, 0, 0, 0);
}
{
Ais8_200_10 msg("85NLn@0j2d<8000000BhI?`50200", 0);
Validate8_200_10(&msg, 0, 367474240, "foo", 15, 5, 8000, 5,
0.01, 0, 0, 0, 0, 0);
}
{
Ais8_200_10 msg("85NLn@0j2d<8000000BhI?`53n00", 0);
Validate8_200_10(&msg, 0, 367474240, "foo", 15, 5, 8000, 5,
1.23, 0, 0, 0, 0, 0);
}
{
Ais8_200_10 msg("85NLn@0j2d<8000000BhI?`5vP00", 0);
Validate8_200_10(&msg, 0, 367474240, "foo", 15, 5, 8000, 5,
20.0, 0, 0, 0, 0, 0);
}
}

// TODO(pyrog): Test messages for 8:200:21.
// TODO(pyrog): Test messages for 8:200:22.

Expand Down
18 changes: 18 additions & 0 deletions test/inland_draught_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Inland AIS 8:200:10 draught is in centimetres, unlike length and beam."""
import ais
import pytest


@pytest.mark.parametrize('centimetres', [0, 1, 123, 2000])
def test_inland_draught_in_metres(centimetres):
# Modify only bits 144..154 in the existing inland-message test fixture.
payload = '85NLn@0j2d<8000000BhI?`50000'
bits = ''.join(format(ord(c) - 48 - (8 if ord(c) > 87 else 0), '06b') for c in payload)
bits = bits[:144] + format(centimetres, '011b') + bits[155:]
values = [int(bits[i:i + 6], 2) for i in range(0, len(bits), 6)]
encoded = ''.join(chr(v + 48 + (8 if v >= 40 else 0)) for v in values)
result = ais.decode(encoded, 0)
assert result['draught'] == pytest.approx(centimetres / 100.0)
assert result['length'] == 15
assert result['beam'] == 5
assert result['mmsi'] == 367474240