decode basic aprs frames

This commit is contained in:
Jakob Ketterl 2019-08-11 17:18:02 +02:00
parent 2053e5f521
commit cbb65e8d79

View File

@ -55,7 +55,11 @@ class KissClient(object):
elif input[0] == FEND: elif input[0] == FEND:
logger.debug("decoded frame: " + str(buf)) logger.debug("decoded frame: " + str(buf))
if len(buf) > 0: if len(buf) > 0:
try:
return self.parseFrame(buf) return self.parseFrame(buf)
except Exception:
logger.exception("failed to decode packet data")
return {}
else: else:
buf += input buf += input
@ -74,18 +78,45 @@ class KissClient(object):
yield l[i:i + n] yield l[i:i + n]
information = ax25frame[control_pid+2:] information = ax25frame[control_pid+2:]
self.parseAprsData(information) aprsData = self.parseAprsData(information)
data = { data = {
"destination": self.extractCallsign(ax25frame[0:7]), "destination": self.extractCallsign(ax25frame[0:7]),
"source": self.extractCallsign(ax25frame[7:14]), "source": self.extractCallsign(ax25frame[7:14]),
"path": [self.extractCallsign(c) for c in chunks(ax25frame[14:control_pid], 7)] "path": [self.extractCallsign(c) for c in chunks(ax25frame[14:control_pid], 7)]
} }
data.update(aprsData)
logger.debug(data) logger.debug(data)
return data return data
def parseAprsData(self, data): def parseAprsData(self, data):
hexdump(data) hexdump(data)
data = data.decode()
def parseCoordinates(raw):
return {
"lat": int(raw[0:2]) + float(raw[2:7]) / 60,
"lon": int(raw[9:12]) + float(raw[12:17]) / 60
}
if data[0] == "!":
# fixed
coords = parseCoordinates(data[1:19])
coords["comment"] = data[20:]
return coords
elif data[0] == "/":
# APRS TNC
coords = parseCoordinates(data[8:26])
coords["comment"] = data[27:]
return coords
elif data[0] == "@":
# TODO CSE, SPD, BRG, 90Q, comments
if data[26] == "$":
# MOBILE
return parseCoordinates(data[8:26])
elif data[26] == "\\":
# DF
return parseCoordinates(data[8:26])
return {} return {}
def extractCallsign(self, input): def extractCallsign(self, input):