additional types; parse messages
This commit is contained in:
parent
707fcdb1ab
commit
1d8fea891a
31
owrx/aprs.py
31
owrx/aprs.py
@ -25,6 +25,9 @@ altitudeRegex = re.compile("(^.*)\\/A=([0-9]{6})(.*$)")
|
|||||||
# regex for parsing third-party headers
|
# regex for parsing third-party headers
|
||||||
thirdpartyeRegex = re.compile("^([a-zA-Z0-9-]+)>((([a-zA-Z0-9-]+\\*?,)*)([a-zA-Z0-9-]+\\*?)):(.*)$")
|
thirdpartyeRegex = re.compile("^([a-zA-Z0-9-]+)>((([a-zA-Z0-9-]+\\*?,)*)([a-zA-Z0-9-]+\\*?)):(.*)$")
|
||||||
|
|
||||||
|
# regex for getting the message id out of message
|
||||||
|
messageIdRegex = re.compile("^(.*){([0-9]{1,5})$")
|
||||||
|
|
||||||
|
|
||||||
def decodeBase91(input):
|
def decodeBase91(input):
|
||||||
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
|
base = decodeBase91(input[:-1]) * 91 if len(input) > 1 else 0
|
||||||
@ -231,9 +234,37 @@ class AprsParser(object):
|
|||||||
elif dti == "}":
|
elif dti == "}":
|
||||||
# third party
|
# third party
|
||||||
aprsData.update(self.parseThirdpartyAprsData(information[1:]))
|
aprsData.update(self.parseThirdpartyAprsData(information[1:]))
|
||||||
|
elif dti == ":":
|
||||||
|
# message
|
||||||
|
aprsData.update(self.parseMessage(information[1:]))
|
||||||
|
elif dti == ";":
|
||||||
|
# object
|
||||||
|
aprsData["type"] = "object"
|
||||||
|
elif dti == ")":
|
||||||
|
# item
|
||||||
|
aprsData["type"] = "item"
|
||||||
|
|
||||||
return aprsData
|
return aprsData
|
||||||
|
|
||||||
|
def parseMessage(self, information):
|
||||||
|
result = {"type": "message"}
|
||||||
|
if len(information) > 10 and information[10] == ":":
|
||||||
|
result["adressee"] = information[0:9]
|
||||||
|
message = information[10:]
|
||||||
|
if len(message) > 3 and message[0:3] == "ack":
|
||||||
|
result["type"] = "messageacknowledgement"
|
||||||
|
result["messageid"] = int(message[3:8])
|
||||||
|
elif len(message) > 3 and message[0:3] == "rej":
|
||||||
|
result["type"] = "messagerejection"
|
||||||
|
result["messageid"] = int(message[3:8])
|
||||||
|
else:
|
||||||
|
matches = messageIdRegex.match(message)
|
||||||
|
if matches:
|
||||||
|
result["messageid"] = int(matches[2])
|
||||||
|
message = matches[1]
|
||||||
|
result["message"] = message
|
||||||
|
return result
|
||||||
|
|
||||||
def parseThirdpartyAprsData(self, information):
|
def parseThirdpartyAprsData(self, information):
|
||||||
matches = thirdpartyeRegex.match(information)
|
matches = thirdpartyeRegex.match(information)
|
||||||
if matches:
|
if matches:
|
||||||
|
Loading…
Reference in New Issue
Block a user