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
10 changes: 7 additions & 3 deletions src/libais/ais_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,10 +1870,13 @@ ais8_200_55_append_pydict(const char *nmea_payload, PyObject *dict,
return AIS_OK;
}

void
AIS_STATUS
ais8_367_22_append_pydict(const char *nmea_payload, PyObject *dict,
const size_t pad) {
Ais8_367_22 msg(nmea_payload, pad); // TODO(schwehr): check for errors
Ais8_367_22 msg(nmea_payload, pad);
if (msg.had_error()) {
return msg.get_error();
}

DictSafeSetItem(dict, "version", msg.version);
DictSafeSetItem(dict, "link_id", msg.link_id);
Expand Down Expand Up @@ -2006,6 +2009,7 @@ ais8_367_22_append_pydict(const char *nmea_payload, PyObject *dict,
}
DictSafeSetItem(dict, "sub_areas", sub_area_list);
Py_DECREF(sub_area_list);
return AIS_OK;
}

AIS_STATUS
Expand Down Expand Up @@ -2876,7 +2880,7 @@ ais8_to_pydict(const char *nmea_payload, const size_t pad) {
case 367: // United states.
switch (msg.fi) {
case 22: // USCG Area Notice 2012 (v5?).
ais8_367_22_append_pydict(nmea_payload, dict, pad);
status = ais8_367_22_append_pydict(nmea_payload, dict, pad);
break;
case AIS_FI_8_367_23_SSW:
status = ais8_367_23_append_pydict(nmea_payload, dict, pad);
Expand Down
45 changes: 45 additions & 0 deletions test/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,50 @@ def testDecodeUnknownMessage6(self):
self.assertRaisesRegex(ais.DecodeError, '6:669:11',
ais.decode, '6B?n;be:cbapalgc;i6?Ow4', 2)

class Ais8AreaNoticeDecoders(unittest.TestCase):

# Recorded USCG messages already exercised by the C++ decoder tests in
# src/test/ais8_367_test.cpp. Exercise the public Python decoder as well.
CIRCLE = '8h3Ovq1KmPA`08b8007P3ct5uAPmtlAkh000'

def testCircle(self):
msg = ais.decode(self.CIRCLE, 0)
self.assertEqual((8, 367, 22, 3669732),
(msg['id'], msg['dac'], msg['fi'], msg['mmsi']))
self.assertEqual((104, 0, 4, 10, 17, 0, 60),
(msg['link_id'], msg['notice_type'], msg['month'],
msg['day'], msg['hour'], msg['minute'],
msg['durations_minutes']))
self.assertEqual(1, len(msg['sub_areas']))
circle = msg['sub_areas'][0]
self.assertEqual('circle', circle['sub_area_type_str'])
self.assertAlmostEqual(-70.1184, circle['x'], places=4)
self.assertAlmostEqual(42.3113, circle['y'], places=4)
self.assertEqual(9260, circle['radius'])

def testText(self):
msg = ais.decode('803Ow2iKmPFJwP37P000bbHHsrPbJP000000', 0)
self.assertEqual('text', msg['sub_areas'][0]['sub_area_type_str'])
self.assertEqual('USCG-TEST@@@@@@', msg['sub_areas'][0]['text'])

def testPolylines(self):
msg = ais.decode(
'8h3Ovq1KmP@N<95=`2l01=dN<b7pGeP00000LL8PSV8RQ8cTs5H0LTHh477PRpus@000', 0)
self.assertEqual(['point', 'polyline', 'polyline'],
[area['sub_area_type_str'] for area in msg['sub_areas']])
self.assertEqual([225, 230, 265, 315], msg['sub_areas'][1]['angles'])
self.assertEqual([13000, 27300, 17400, 17200], msg['sub_areas'][1]['dists_m'])

def testTruncatedArea(self):
with self.assertRaisesRegex(ais.DecodeError, 'AIS_ERR_BAD_BIT_COUNT'):
ais.decode(self.CIRCLE[:-1], 0)

def testReservedAreaShape(self):
# Subarea shape 6 is reserved. Preserve the header and remaining bits.
payload = self.CIRCLE[:20] + 'h' + self.CIRCLE[21:]
with self.assertRaisesRegex(ais.DecodeError, 'AIS_ERR_BAD_SUB_SUB_MSG'):
ais.decode(payload, 0)


if __name__=='__main__':
unittest.main()