def decode_msg_24(bit_arr: bitarray) -> dict: """ Static Data Report Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_24_static_data_report """ get_int_from_data = partial(get_int, bit_arr) data = { 'type': get_int_from_data(0, 6), 'repeat': get_int_from_data(8, 8), 'mmsi': get_int_from_data(8, 38), 'partno': get_int_from_data(38, 40) } # Part A if len(bit_arr) == 160: d = { 'shipname': encode_bin_as_ascii6(bit_arr[40: 160]) } # Part B else: d = { 'shiptype': ShipType(get_int_from_data(40, 48)), 'vendorid': encode_bin_as_ascii6(bit_arr[48: 66]), 'model': get_int_from_data(66, 70), 'serial': get_int_from_data(70, 90), 'callsign': encode_bin_as_ascii6(bit_arr[90: 132]), 'to_bow': get_int_from_data(132, 141), 'to_stern': get_int_from_data(141, 150), 'to_port': get_int_from_data(150, 156), 'to_starboard': get_int_from_data(156, 162), 'mothership_mmsi': get_int_from_data(132, 162) } data.update(d) return data
def decode_msg_19(bit_arr: bitarray) -> dict: """ Extended Class B CS Position Report Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_19_extended_class_b_cs_position_report """ get_int_from_data = partial(get_int, bit_arr) return { 'type': get_int_from_data(0, 6), 'repeat': get_int_from_data(8, 8), 'mmsi': get_int_from_data(8, 38), 'speed': get_int_from_data(46, 56) * 0.1, 'accuracy': bit_arr[56], 'lon': get_int_from_data(57, 85, signed=True) / 600000.0, 'lat': get_int_from_data(85, 112, signed=True) / 600000.0, 'course': get_int_from_data(112, 124) * 0.1, 'heading': get_int_from_data(124, 133), 'second': get_int_from_data(133, 139), 'regional': get_int_from_data(139, 143), 'shipname': encode_bin_as_ascii6(bit_arr[143:263]), 'shiptype': ShipType(get_int_from_data(263, 271)), 'to_bow': get_int_from_data(271, 280), 'to_stern': get_int_from_data(280, 289), 'to_port': get_int_from_data(289, 295), 'to_starboard': get_int_from_data(295, 301), 'epfd': EpfdType(get_int_from_data(301, 305)), 'raim': bit_arr[305], 'dte': bit_arr[306], 'assigned': bit_arr[307], }
def decode_msg_5(bit_arr: bitarray.bitarray) -> Dict[str, Any]: """ Static and Voyage Related Data Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_5_static_and_voyage_related_data """ get_int_from_data = partial(get_int, bit_arr) return { 'type': get_int_from_data(0, 6), 'repeat': get_int_from_data(6, 8), 'mmsi': get_int_from_data(8, 38), 'ais_version': get_int_from_data(38, 40), 'imo': get_int_from_data(40, 70), 'callsign': encode_bin_as_ascii6(bit_arr[70:112]), 'shipname': encode_bin_as_ascii6(bit_arr[112:232]), 'shiptype': ShipType(get_int_from_data(232, 240)), 'to_bow': get_int_from_data(240, 249), 'to_stern': get_int_from_data(249, 258), 'to_port': get_int_from_data(258, 264), 'to_starboard': get_int_from_data(264, 270), 'epfd': EpfdType(get_int_from_data(270, 274)), 'month': get_int_from_data(274, 278), 'day': get_int_from_data(278, 283), 'hour': get_int_from_data(283, 288), 'minute': get_int_from_data(288, 294), 'draught': get_int_from_data(294, 302) / 10.0, 'destination': encode_bin_as_ascii6(bit_arr[302:422]), 'dte': bit_arr[-2] }
def test_ship_types(self): self.assertEqual(ShipType(25), ShipType.WIG_Reserved) self.assertEqual(ShipType(46), ShipType.HSC_Reserved) self.assertEqual(ShipType(57), ShipType.SPARE) self.assertEqual(ShipType(68), ShipType.Passenger_Reserved) self.assertEqual(ShipType(78), ShipType.Cargo_Reserved) self.assertEqual(ShipType(85), ShipType.Tanker_Reserved) self.assertEqual(ShipType(96), ShipType.OtherType_Reserved) self.assertEqual(ShipType(100), ShipType.NotAvailable)
def test_msg_type_19(self): msg = NMEAMessage(b"!AIVDM,1,1,,B,C5N3SRgPEnJGEBT>NhWAwwo862PaLELTBJ:V00000000S0D:R220,0*0B").decode() assert msg['type'] == 19 assert msg['mmsi'] == "367059850" assert round(msg['speed'], 1) == 8.7 assert msg['accuracy'] == 0 assert round(msg['lat'], 2) == 29.54 assert round(msg['lon'], 2) == -88.81 assert round(msg['course'], 2) == 335.9 assert msg['heading'] == 511 assert msg['second'] == 46 assert msg['shipname'] == "CAPT.J.RIMES" assert msg['shiptype'] == ShipType(70) assert msg['to_bow'] == 5 assert msg['to_stern'] == 21 assert msg['to_port'] == 4 assert msg['to_starboard'] == 4
def decode_msg_23(bit_arr: bitarray.bitarray) -> typing.Dict: """ Group Assignment Command Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_23_group_assignment_command """ get_int_from_data = partial(get_int, bit_arr) return { 'type': get_int_from_data(0, 6), 'repeat': get_int_from_data(8, 8), 'mmsi': get_int_from_data(8, 38), 'ne_lon': get_int_from_data(40, 58, signed=True) * 0.1, 'ne_lat': get_int_from_data(58, 75, signed=True) * 0.1, 'sw_lon': get_int_from_data(75, 93, signed=True) * 0.1, 'sw_lat': get_int_from_data(93, 110, signed=True) * 0.1, 'station_type': StationType(get_int_from_data(110, 114)), 'ship_type': ShipType(get_int_from_data(114, 122)), 'txrx': TransmitMode(get_int_from_data(144, 146)), 'interval': StationIntervals(get_int_from_data(146, 150)), 'quiet': get_int_from_data(150, 154), }
def decode_msg_5(bit_arr: bitarray) -> dict: get_int_from_data = partial(get_int, bit_arr) return { 'type': get_int_from_data(0, 6), 'repeat': get_int_from_data(6, 8), 'mmsi': get_int_from_data(8, 38), 'ais_version': get_int_from_data(38, 40), 'imo': get_int_from_data(40, 70), 'callsign': encode_bin_as_ascii6(bit_arr[70:112]), 'shipname': encode_bin_as_ascii6(bit_arr[112:232]), 'shiptype': ShipType(get_int_from_data(232, 240)), 'to_bow': get_int_from_data(240, 249), 'to_stern': get_int_from_data(249, 258), 'to_port': get_int_from_data(258, 264), 'to_starboard': get_int_from_data(264, 270), 'epfd': EpfdType(get_int_from_data(270, 274)), 'month': get_int_from_data(274, 278), 'day': get_int_from_data(278, 283), 'hour': get_int_from_data(283, 288), 'minute': get_int_from_data(288, 294), 'draught': get_int_from_data(294, 302) / 10.0, 'destination': encode_bin_as_ascii6(bit_arr[302:422]), 'dte': bit_arr[-2] }