This commit is contained in:
Jakob Ketterl 2019-08-15 19:56:59 +02:00
parent 88bbb76752
commit 21591ad6b8
6 changed files with 35 additions and 57 deletions

View File

@ -437,7 +437,7 @@ class dsp(object):
demodulator = self.get_secondary_demodulator()
return demodulator in ["ft8", "wspr", "jt65", "jt9", "ft4"]
def isPacket(self, demodulator = None):
def isPacket(self, demodulator=None):
if demodulator is None:
demodulator = self.get_secondary_demodulator()
return demodulator == "packet"

View File

@ -12,26 +12,25 @@ def decodeBase91(input):
class Ax25Parser(object):
def parse(self, ax25frame):
control_pid = ax25frame.find(bytes([0x03, 0xf0]))
control_pid = ax25frame.find(bytes([0x03, 0xF0]))
if control_pid % 7 > 0:
logger.warning("aprs packet framing error: control/pid position not aligned with 7-octet callsign data")
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
yield l[i : i + n]
return {
"destination": self.extractCallsign(ax25frame[0:7]),
"source": self.extractCallsign(ax25frame[7:14]),
"path": [self.extractCallsign(c) for c in chunks(ax25frame[14:control_pid], 7)],
"data": ax25frame[control_pid+2:]
"data": ax25frame[control_pid + 2 :],
}
def extractCallsign(self, input):
cs = bytes([b >> 1 for b in input[0:6]]).decode('us-ascii').strip()
cs = bytes([b >> 1 for b in input[0:6]]).decode("us-ascii").strip()
ssid = (input[6] & 0b00011110) >> 1
if ssid > 0:
return "{callsign}-{ssid}".format(callsign=cs, ssid=ssid)
@ -40,7 +39,6 @@ class Ax25Parser(object):
class AprsParser(object):
def __init__(self, handler):
self.ax25parser = Ax25Parser()
self.deframer = KissDeframer()
@ -62,7 +60,9 @@ class AprsParser(object):
logger.debug(aprsData)
if "lat" in aprsData and "lon" in aprsData:
loc = LatLngLocation(aprsData["lat"], aprsData["lon"], aprsData["comment"] if "comment" in aprsData else None)
loc = LatLngLocation(
aprsData["lat"], aprsData["lon"], aprsData["comment"] if "comment" in aprsData else None
)
Map.getSharedInstance().updateLocation(data["source"], loc, "APRS", self.band)
self.handler.write_aprs_data(aprsData)
@ -79,34 +79,26 @@ class AprsParser(object):
lon = int(raw[9:12]) + float(raw[12:17]) / 60
if raw[17] == "W":
lon *= -1
return {
"lat": lat,
"lon": lon,
"symbol": raw[18]
}
return {"lat": lat, "lon": lon, "symbol": raw[18]}
def parseCompressedCoordinates(self, raw):
return {
"lat": 90 - decodeBase91(raw[1:5]) / 380926,
"lon": -180 + decodeBase91(raw[5:9]) / 190463,
"symbol": raw[9]
"symbol": raw[9],
}
def parseAprsData(self, data):
information = data["data"]
# forward some of the ax25 data
aprsData = {
"source": data["source"],
"destination": data["destination"],
"path": data["path"]
}
aprsData = {"source": data["source"], "destination": data["destination"], "path": data["path"]}
if information[0] == 0x1c or information[0] == 0x60:
if information[0] == 0x1C or information[0] == 0x60:
aprsData.update(MicEParser().parse(data))
return aprsData
information = information.decode('us-ascii')
information = information.decode("us-ascii")
logger.debug(information)
if information[0] == "!" or information[0] == "=":
@ -166,7 +158,7 @@ class MicEParser(object):
if comment[-2] == "_":
devices = {
"b": "VX-8",
"\"": "FTM-350",
'"': "FTM-350",
"#": "VX-8G",
"$": "FT1D",
"%": "FTM-400DR",
@ -178,25 +170,19 @@ class MicEParser(object):
if comment[-2:] == " X":
return comment[1:-2], {"manufacturer": "SainSonic", "device": "AP510"}
if comment[-2] == "(":
devices = {
"5": "D578UV",
"8": "D878UV"
}
devices = {"5": "D578UV", "8": "D878UV"}
return comment[1:-2], {"manufacturer": "Anytone", "device": devices.get(comment[-1], "Unknown")}
if comment[-2] == "|":
devices = {
"3": "TinyTrack3",
"4": "TinyTrack4"
}
devices = {"3": "TinyTrack3", "4": "TinyTrack4"}
return comment[1:-2], {"manufacturer": "Byonics", "device": devices.get(comment[-1], "Unknown")}
if comment[-2:] == "^v":
return comment[1:-2], {"manufacturer": "HinzTec", "device": "anyfrog"}
if comment[-2] == ":":
devices = {
"4": "P4dragon DR-7400 modem",
"8": "P4dragon DR-7800 modem"
}
return comment[1:-2], {"manufacturer": "SCS GmbH & Co.", "device": devices.get(comment[-1], "Unknown")}
devices = {"4": "P4dragon DR-7400 modem", "8": "P4dragon DR-7800 modem"}
return (
comment[1:-2],
{"manufacturer": "SCS GmbH & Co.", "device": devices.get(comment[-1], "Unknown")},
)
if comment[-2:] == "~v":
return comment[1:-2], {"manufacturer": "Other", "device": "Other"}
return comment[1:-2], None
@ -233,7 +219,7 @@ class MicEParser(object):
if ord(destination[5]) >= ord("P"):
lon *= -1
comment = information[9:].decode('us-ascii').strip()
comment = information[9:].decode("us-ascii").strip()
(comment, altitude) = self.extractAltitude(comment)
(comment, device) = self.extractDevice(comment)
@ -242,11 +228,4 @@ class MicEParser(object):
(comment, insideAltitude) = self.extractAltitude(comment)
altitude = next((a for a in [altitude, insideAltitude] if a is not None), None)
return {
"lat": lat,
"lon": lon,
"comment": comment,
"altitude": altitude,
"device": device,
"type": "Mic-E",
}
return {"lat": lat, "lon": lon, "comment": comment, "altitude": altitude, "device": device, "type": "Mic-E"}

View File

@ -25,7 +25,7 @@ class FeatureDetector(object):
"digital_voice_digiham": ["digiham", "sox"],
"digital_voice_dsd": ["dsd", "sox", "digiham"],
"wsjt-x": ["wsjtx", "sox"],
"packet": [ "direwolf" ],
"packet": ["direwolf"],
}
def feature_availability(self):

View File

@ -7,7 +7,7 @@ logger = logging.getLogger(__name__)
FEND = 0xC0
FESC = 0xDB
TFEND = 0xDC
TFESC = 0XDD
TFESC = 0xDD
class KissClient(object):

View File

@ -92,14 +92,15 @@ class Map(object):
class LatLngLocation(Location):
def __init__(self, lat: float, lon: float, comment = None):
def __init__(self, lat: float, lon: float, comment=None):
self.lat = lat
self.lon = lon
self.comment = comment
def __dict__(self):
res = {"type": "latlon", "lat": self.lat, "lon": self.lon}
if self.comment is not None: res["comment"] = self.comment
if self.comment is not None:
res["comment"] = self.comment
return res

View File

@ -27,7 +27,6 @@ class ServiceOutput(output):
class WsjtServiceOutput(ServiceOutput):
def getParser(self):
return WsjtParser(WsjtHandler())
@ -36,7 +35,6 @@ class WsjtServiceOutput(ServiceOutput):
class AprsServiceOutput(ServiceOutput):
def getParser(self):
return AprsParser(AprsHandler())