get altitude from comment

This commit is contained in:
Jakob Ketterl 2019-08-17 20:35:32 +02:00
parent 1eb28d6aee
commit 82eaff5da6
1 changed files with 19 additions and 7 deletions

View File

@ -2,21 +2,27 @@ from owrx.kiss import KissDeframer
from owrx.map import Map, LatLngLocation from owrx.map import Map, LatLngLocation
from owrx.bands import Bandplan from owrx.bands import Bandplan
from datetime import datetime, timezone from datetime import datetime, timezone
import re
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def decodeBase91(input):
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
return base + (ord(input[-1]) - 33)
# speed is in knots... convert to metric (km/h) # speed is in knots... convert to metric (km/h)
speedConversionFactor = 1.852 knotsToKilometers = 1.852
feetToMeters = 0.3048
# not sure what the correct encoding is. it seems TAPR has set utf-8 as a standard, but not everybody is following it. # not sure what the correct encoding is. it seems TAPR has set utf-8 as a standard, but not everybody is following it.
encoding = "utf-8" encoding = "utf-8"
# regex for altitute in comment field
altitudeRegex = re.compile("(^.*)\\/A=([0-9]{6})(.*$)")
def decodeBase91(input):
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
return base + (ord(input[-1]) - 33)
class Ax25Parser(object): class Ax25Parser(object):
def parse(self, ax25frame): def parse(self, ax25frame):
@ -164,7 +170,7 @@ class AprsParser(object):
else: else:
aprsData["course"] = (ord(information[10]) - 33) * 4 aprsData["course"] = (ord(information[10]) - 33) * 4
# speed is in knots... convert to metric (km/h) # speed is in knots... convert to metric (km/h)
aprsData["speed"] = (1.08 ** (ord(information[11]) - 33) - 1) * speedConversionFactor aprsData["speed"] = (1.08 ** (ord(information[11]) - 33) - 1) * knotsToKilometers
# compression type # compression type
t = ord(information[12]) t = ord(information[12])
aprsData["fix"] = (t & 0b00100000) > 0 aprsData["fix"] = (t & 0b00100000) > 0
@ -186,6 +192,12 @@ class AprsParser(object):
aprsData = self.parseUncompressedCoordinates(information[0:19]) aprsData = self.parseUncompressedCoordinates(information[0:19])
aprsData["type"] = "regular" aprsData["type"] = "regular"
aprsData["comment"] = information[19:] aprsData["comment"] = information[19:]
matches = altitudeRegex.match(aprsData["comment"])
if matches:
aprsData["altitude"] = int(matches[2]) * feetToMeters
aprsData["comment"] = matches[1] + matches[3]
return aprsData return aprsData
@ -290,7 +302,7 @@ class MicEParser(object):
if course >= 400: if course >= 400:
course -= 400 course -= 400
# speed is in knots... convert to metric (km/h) # speed is in knots... convert to metric (km/h)
speed *= speedConversionFactor speed *= knotsToKilometers
comment = information[9:].decode(encoding, "replace").strip() comment = information[9:].decode(encoding, "replace").strip()
(comment, altitude) = self.extractAltitude(comment) (comment, altitude) = self.extractAltitude(comment)