Beispiel #1
0
def add_beacon_to_db(beacon):
    if type(beacon == ReceiverBeacon):
        # connect beacon with receiver
        receiver = session.query(Receiver.id).filter(Receiver.name == beacon.name).first()
        if receiver is None:
            receiver = Receiver()
            receiver.name = beacon.name
            session.add(receiver)
        beacon.receiver_id = receiver.id
    elif type(beacon == AircraftBeacon):
        # connect beacon with device
        device = session.query(Device).filter(Device.address == beacon.address).first()
        if device is None:
            device = Device()
            device.address = beacon.address
            session.add(device)
        beacon.device_id = device.id

        # update device
        device.aircraft_type = beacon.aircraft_type
        device.stealth = beacon.stealth
        if beacon.hardware_version is not None:
            device.hardware_version = beacon.hardware_version
        if beacon.software_version is not None:
            device.software_version = beacon.software_version
        if beacon.real_address is not None:
            device.real_address = beacon.real_address

        # connect beacon with receiver
        receiver = session.query(Receiver.id).filter(Receiver.name == beacon.receiver_name).first()
        if receiver is None:
            receiver = Receiver()
            receiver.name = beacon.receiver_name
            session.add(receiver)
        beacon.receiver_id = receiver.id

    session.add(beacon)
    session.commit()
Beispiel #2
0
def process_beacon(raw_message):
    if raw_message[0] == '#':
        return
    try:
        message = parse_aprs(raw_message)

        # symboltable / symbolcodes used by OGN:
        # I&: used as receiver
        # /X: helicopter_rotorcraft
        # /': glider_or_motorglider
        # \^: powered_aircraft
        # /g: para_glider
        # /O: ?
        # /^: ?
        # \n: ?
        # /z: ?
        # /o: ?
        if message['symboltable'] == "I" and message['symbolcode'] == '&':
            # ... we have a receiver_beacon
            message.update(parse_ogn_receiver_beacon(message['comment']))
            message = replace_lonlat_with_wkt(message)
            beacon = ReceiverBeacon(**message)

            # connect beacon with receiver
            receiver = session.query(Receiver.id) \
                .filter(Receiver.name == beacon.name) \
                .first()
            if receiver is None:
                receiver = Receiver()
                receiver.name = beacon.name
                session.add(receiver)
            beacon.receiver_id = receiver.id
        else:
            # ... we have a aircraft_beacon
            message.update(parse_ogn_aircraft_beacon(message['comment']))
            message = replace_lonlat_with_wkt(message)
            beacon = AircraftBeacon(**message)

            # connect beacon with device
            device = session.query(Device) \
                .filter(Device.address == beacon.address) \
                .first()
            if device is None:
                device = Device()
                device.address = beacon.address
                session.add(device)
            beacon.device_id = device.id

            # update device
            device.aircraft_type = beacon.aircraft_type
            device.stealth = beacon.stealth
            if beacon.hardware_version is not None:
                device.hardware_version = beacon.hardware_version
            if beacon.software_version is not None:
                device.software_version = beacon.software_version
            if beacon.real_address is not None:
                device.real_address = beacon.real_address

            # connect beacon with receiver
            receiver = session.query(Receiver.id) \
                .filter(Receiver.name == beacon.receiver_name) \
                .first()
            if receiver is None:
                receiver = Receiver()
                receiver.name = beacon.receiver_name
                session.add(receiver)
            beacon.receiver_id = receiver.id

        session.add(beacon)
        session.commit()
        logger.debug('Received message: {}'.format(raw_message))
    except ParseError as e:
        logger.error('Received message: {}'.format(raw_message))
        logger.error('Drop packet, {}'.format(e.message))
    except TypeError as e:
        logger.error('TypeError: {}'.format(raw_message))
Beispiel #3
0
def process_beacon(raw_message, reference_date=None, reference_time=None):
    if raw_message[0] == '#':
        return
    try:
        message = parse_aprs(raw_message, reference_date, reference_time)
        # symboltable / symbolcodes used by OGN:
        # I&: used as receiver
        # /X: helicopter_rotorcraft
        # /': glider_or_motorglider
        # \^: powered_aircraft
        # /g: para_glider
        # /O: ?
        # /^: ?
        # \n: ?
        # /z: ?
        # /o: ?
        if 'symboltable' not in message and 'symbolcode' not in message:
            # we have a receiver_beacon (status message)
            message.update(parse_ogn_receiver_beacon(message['comment']))
            beacon = ReceiverBeacon(**message)

            # connect beacon with receiver
            receiver = session.query(Receiver.id) \
                .filter(Receiver.name == beacon.name) \
                .first()
            if receiver is None:
                receiver = Receiver()
                receiver.name = beacon.name
                session.add(receiver)
            beacon.receiver_id = receiver.id
        elif message['symboltable'] == "I" and message['symbolcode'] == '&':
            # ... we have a receiver_beacon
            message.update(parse_ogn_receiver_beacon(message['comment']))
            message = replace_lonlat_with_wkt(message)
            beacon = ReceiverBeacon(**message)

            # connect beacon with receiver
            receiver = session.query(Receiver.id) \
                .filter(Receiver.name == beacon.name) \
                .first()
            if receiver is None:
                receiver = Receiver()
                receiver.name = beacon.name
                session.add(receiver)
            beacon.receiver_id = receiver.id
        else:
            # ... we have a aircraft_beacon
            message.update(parse_ogn_aircraft_beacon(message['comment']))
            message = replace_lonlat_with_wkt(message)
            beacon = AircraftBeacon(**message)

            # connect beacon with device
            device = session.query(Device) \
                .filter(Device.address == beacon.address) \
                .first()
            if device is None:
                device = Device()
                device.address = beacon.address
                session.add(device)
            beacon.device_id = device.id

            # update device
            device.aircraft_type = beacon.aircraft_type
            device.stealth = beacon.stealth
            if beacon.hardware_version is not None:
                device.hardware_version = beacon.hardware_version
            if beacon.software_version is not None:
                device.software_version = beacon.software_version
            if beacon.real_address is not None:
                device.real_address = beacon.real_address

            # connect beacon with receiver
            receiver = session.query(Receiver.id) \
                .filter(Receiver.name == beacon.receiver_name) \
                .first()
            if receiver is None:
                receiver = Receiver()
                receiver.name = beacon.receiver_name
                session.add(receiver)
            beacon.receiver_id = receiver.id

        session.add(beacon)
        session.commit()
        logger.debug('Received message: {}'.format(raw_message))
    except ParseError as e:
        logger.error('Received message: {}'.format(raw_message))
        logger.error('Drop packet, {}'.format(e.message))
    except TypeError as e:
        logger.error('TypeError: {}'.format(raw_message))