Exemplo n.º 1
0
 def __init__(self):
     tkinter.Tk.__init__(self)
     self.nmeatracker = nmea.NMEAtracker()
     self.aistracker = ais.AISTracker()
     self.messagelog = allmessages.AISMessageLog()
     self.protocol("WM_DELETE_WINDOW", self.quit)
     self.title('PY AIS NMEA - ' + version.VERSION)
     self.statuslabel = tkinter.Label(self, text='', bg='light grey')
     self.statuslabel.pack(fill=tkinter.X)
     self.tabcontrol = TabControl(self)
     self.tabcontrol.pack(expand=1, fill='both')
     self.top_menu()
     self.mpq = multiprocessing.Queue()
     self.updateguithread = None
     self.refreshguithread = None
     self.serverprocess = None
     self.serverrunning = False
     self.stopevent = threading.Event()
     self.forwardsentences = tkinter.BooleanVar()
     self.forwardsentences.set(0)
     self.kmzlivemap = tkinter.BooleanVar()
     self.kmzlivemap.set(0)
     self.livemap = None
     self.timingsources = []
     self.currentupdatethreadid = None
     self.currentrefreshthreadid = None
Exemplo n.º 2
0
def aistracker_from_file(filepath, debug=False, timingsource=None):
    """
    open a file, read all nmea sentences and return an ais.AISTracker object

    Note:
        if debug is set then individual messages are saved into the messagelog

    Args:
        filepath(str): full path to nmea file
        debug(bool): save all message payloads and decoded attributes into
                     messagelog
        timingsource(list): MMSIs of the base stations you wish to use
                           as a time reference, type 4 base station reports
                           from this base station will be used for times.
                           default is None and all base stations will be used
                           for times. list of strings

    Raises:
        NoSuitableMessagesFound: if there are no AIS messages in the file

    Returns:
        aistracker(ais.AISTracker): object that keeps track of all the
                                    ships we have seen
        nmeatracker(nmea.NMEAtracker): object that organises the nmea sentences
        messagelog(allmessages.AISMessageLog): object with all the AIS messages
    """
    messagelog = allmessages.AISMessageLog()
    aistracker = ais.AISTracker()
    aistracker.timingsource = timingsource
    nmeatracker = nmea.NMEAtracker()
    msgnumber = 1
    for line in open_file_generator(filepath):
        try:
            payload = nmeatracker.process_sentence(line)
            if payload:
                msg = aistracker.process_message(payload)
                if debug:
                    messagelog.store(msgnumber, payload, msg)
                msgnumber += 1
        except (nmea.NMEAInvalidSentence, nmea.NMEACheckSumFailed,
                ais.UnknownMessageType, ais.InvalidMMSI, binary.NoBinaryData,
                IndexError) as err:
            AISLOGGER.debug(str(err))
            continue
    if aistracker.messagesprocessed == 0:
        raise NoSuitableMessagesFound('No AIS messages detected in this file')
    return (aistracker, nmeatracker, messagelog)
Exemplo n.º 3
0
def aistracker_from_json(filepath, debug=True):
    """
    get an aistracker object from a debug messages JSON that was previously
    exported from pyaisnmea

    Args:
        filepath(str): full path to json file
        debug(bool): save all message payloads and decoded attributes into
                     messagelog

    Raises:
        NoSuitableMessagesFound: if there are no AIS messages in the file

    Returns:
        aistracker(ais.AISTracker): object that keeps track of all the
                                    ships we have seen
        messagelog(allmessages.AISMessageLog): object with all the AIS messages
    """
    messagelog = allmessages.AISMessageLog()
    aistracker = ais.AISTracker()
    msgnumber = 1
    for line in open_file_generator(filepath):
        try:
            linemsgdict = json.loads(line)
            payload = linemsgdict['payload']
            msgtime = linemsgdict['rxtime']
            msg = aistracker.process_message(payload, timestamp=msgtime)
            if debug:
                messagelog.store(msgnumber, payload, msg)
            msgnumber += 1
        except (ais.UnknownMessageType, ais.InvalidMMSI,
                json.decoder.JSONDecodeError, KeyError,
                binary.NoBinaryData) as err:
            AISLOGGER.debug(str(err))
            continue
    if aistracker.messagesprocessed == 0:
        raise NoSuitableMessagesFound('No AIS messages detected in this file')
    return (aistracker, messagelog)
Exemplo n.º 4
0
def aistracker_from_csv(filepath, debug=True):
    """
    get an aistracker object from a debug messages CSV that was previously
    exported from pyaisnmea

    Args:
        filepath(str): full path to csv file
        debug(bool): save all message payloads and decoded attributes into
                     messagelog

    Raises:
        NoSuitableMessagesFound: if there are no AIS messages in the file

    Returns:
        aistracker(ais.AISTracker): object that keeps track of all the
                                    ships we have seen
        messagelog(allmessages.AISMessageLog): object with all the AIS messages
    """
    messagelog = allmessages.AISMessageLog()
    aistracker = ais.AISTracker()
    msgnumber = 1
    for line in open_file_generator(filepath):
        try:
            linelist = line.split(',')
            if kml.DATETIMEREGEX.match(linelist[3]):
                payload = linelist[0]
                msgtime = linelist[3]
                msg = aistracker.process_message(payload, timestamp=msgtime)
                if debug:
                    messagelog.store(msgnumber, payload, msg)
                msgnumber += 1
        except (ais.UnknownMessageType, ais.InvalidMMSI, IndexError,
                binary.NoBinaryData) as err:
            AISLOGGER.debug(str(err))
            continue
    if aistracker.messagesprocessed == 0:
        raise NoSuitableMessagesFound('No AIS messages detected in this file')
    return (aistracker, messagelog)