def __init__(self, nmea_message: NMEAMessage): self.nmea: NMEAMessage = nmea_message self.msg_type: AISType = AISType(nmea_message.ais_id) self.content: dict = dict() self.content = decode(self.nmea)
def __init__(self, nmea_message: NMEAMessage) -> None: self.nmea: NMEAMessage = nmea_message self.msg_type: AISType = AISType(nmea_message.ais_id) self.content: typing.Dict = decode(self.nmea)
def decode(self) -> None: """Decodes the given message and extracts it's type and content. This function potentially fails, if the message is malformed.""" self.msg_type = AISType(self.nmea.ais_id) self.content = decode(self.nmea)
mmsidict[data['mmsi']] = data['shipname'] with open('mmsi.json', 'w') as json_file: json.dump( mmsidict, json_file ) #store vessel names for later use since they only get transmitted every 6 minutes if SerialPortName != '': try: serial = serial.Serial(SerialPortName, SerialPortBaud, timeout=1) except: #kill the program - couldn't open the serial port print("Unable to open the serial port " + SerialPortName + " - unable to proceed - exiting") os._exit(1) while True: line = serial.readline() if line != b'': print(line) message = NMEAMessage(line) data = decode(message) handle_ais_data(data) else: for msg in UDPStream(DEF_RX_ADDR, DEF_RX_PORT): #AIS data comes in from rtl-ais via UDP port print(msg) data = msg.decode() #print(data) handle_ais_data(data)