ogn-python/ogn/aprs_parser.py

32 wiersze
799 B
Python
Czysty Zwykły widok Historia

from .model import Beacon, AircraftBeacon, ReceiverBeacon
2015-11-15 18:21:19 +00:00
from ogn.exceptions import AprsParseError
2015-10-24 21:13:21 +00:00
2015-11-19 22:17:12 +00:00
2015-11-15 18:21:19 +00:00
def parse_aprs(packet):
if not isinstance(packet, str):
raise TypeError("Expected packet to be str, got %s" % type(packet))
elif packet == "":
2015-11-19 22:17:12 +00:00
raise AprsParseError("(empty string)")
2015-11-15 18:21:19 +00:00
elif packet[0] == "#":
2015-10-24 21:13:21 +00:00
return None
beacon = Beacon()
2015-11-15 18:21:19 +00:00
beacon.parse(packet)
2015-10-24 21:13:21 +00:00
# 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 beacon.symboltable == "I" and beacon.symbolcode == "&":
return ReceiverBeacon(beacon)
2015-10-24 21:13:21 +00:00
else:
return AircraftBeacon(beacon)