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
20 changes: 8 additions & 12 deletions src/libais/ais8_200.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,14 @@ Ais8_200_23::Ais8_200_23(const char *nmea_payload, const size_t pad)

bits.SeekTo(56);

// TODO(schwehr): Figure out the correct bits & test against actual messages.

// The total for the bit column in table 2.11 of ECE/TRANS/SC.3/2006/10
// add up to 256. However, start date and end date fields are lists with
// totals of 17 bits each, but within the details, the spec refers to 18 bits
// for each. It is likely the year should be one less bit.
// ECE/TRANS/SC.3/176 Table 2.11: each 17-bit date is 8/4/5 bits.
utc_year_start = bits.ToUnsignedInt(56, 8);
utc_month_start = bits.ToUnsignedInt(65, 4);
utc_day_start = bits.ToUnsignedInt(69, 5);
utc_month_start = bits.ToUnsignedInt(64, 4);
utc_day_start = bits.ToUnsignedInt(68, 5);

utc_year_end = bits.ToUnsignedInt(73, 8);
utc_month_end = bits.ToUnsignedInt(82, 4);
utc_day_end = bits.ToUnsignedInt(86, 5);
utc_month_end = bits.ToUnsignedInt(81, 4);
utc_day_end = bits.ToUnsignedInt(85, 5);

utc_hour_start = bits.ToUnsignedInt(90, 5);
utc_min_start = bits.ToUnsignedInt(95, 6);
Expand All @@ -182,14 +177,15 @@ Ais8_200_23::Ais8_200_23(const char *nmea_payload, const size_t pad)
position2 = bits.ToAisPoint(167, 55);

type = bits.ToUnsignedInt(222, 4);
// TODO(schwehr): Handle the sign bit for min and max.
// Values use sign-magnitude rather than two's complement.
min = bits.ToUnsignedInt(226, 9);
if (min & 0x100) min = -(min & 0xff);
max = bits.ToUnsignedInt(235, 9);
if (max & 0x100) max = -(max & 0xff);
classification = bits.ToUnsignedInt(244, 2);
wind_dir = bits.ToUnsignedInt(246, 4);
spare2 = bits.ToUnsignedInt(250, 6);

// TODO(schwehr): The above bit counts can't work.
assert(bits.GetRemaining() == 0);
status = AIS_OK;
}
Expand Down
42 changes: 42 additions & 0 deletions src/test/ais8_200_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,48 @@ TEST(Ais8_200_10Test, DecodeAnything) {
0, 0, 0, 0, 0, 0);
}

// Synthetic 256-bit EMMA warnings, following ECE/TRANS/SC.3/176 Table 2.11.
// Dates use 8/4/5 bits and min/max use a sign bit plus eight magnitude bits.
TEST(Ais8_200_23Test, DatesAndSignedValues) {
struct Example {
const char *payload;
int minimum;
int maximum;
};
const Example examples[] = {
{"81mg=5@j5ic?SHQ8;:D2o6h3TpL01eo@1lfe0B2PcD0", -5, 10},
{"81mg=5@j5ic?SHQ8;:D2o6h3TpL01eo@1lfe0AwOsD0", 254, -254},
{"81mg=5@j5ic?SHQ8;:D2o6h3TpL01eo@1lfe0B0OwD0", 0, -255},
{"81mg=5@j5ic?SHQ8;:D2o6h3TpL01eo@1lfe0@2gwD0", 5, 255},
};
for (const auto &example : examples) {
SCOPED_TRACE(example.payload);
const Ais8_200_23 msg(example.payload, 2);
ASSERT_FALSE(msg.had_error());
EXPECT_EQ(123456789, msg.mmsi);
EXPECT_EQ(26, msg.utc_year_start);
EXPECT_EQ(12, msg.utc_month_start);
EXPECT_EQ(31, msg.utc_day_start);
EXPECT_EQ(27, msg.utc_year_end);
EXPECT_EQ(1, msg.utc_month_end);
EXPECT_EQ(1, msg.utc_day_end);
EXPECT_EQ(4, msg.utc_hour_start);
EXPECT_EQ(5, msg.utc_min_start);
EXPECT_EQ(18, msg.utc_hour_end);
EXPECT_EQ(37, msg.utc_min_end);
EXPECT_DOUBLE_EQ(5, msg.position1.lng_deg);
EXPECT_DOUBLE_EQ(50, msg.position1.lat_deg);
EXPECT_DOUBLE_EQ(6, msg.position2.lng_deg);
EXPECT_DOUBLE_EQ(51, msg.position2.lat_deg);
EXPECT_EQ(4, msg.type);
EXPECT_EQ(example.minimum, msg.min);
EXPECT_EQ(example.maximum, msg.max);
EXPECT_EQ(3, msg.classification);
EXPECT_EQ(5, msg.wind_dir);
EXPECT_EQ(0, msg.spare2);
}
}

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

Expand Down