From 88bbb767526588eba698529e4155734fa1234dd0 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 15 Aug 2019 19:50:47 +0200 Subject: [PATCH] make sure there is actually enough data to parse --- owrx/aprs.py | 98 +++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/owrx/aprs.py b/owrx/aprs.py index 77f3ef2..2d9e48c 100644 --- a/owrx/aprs.py +++ b/owrx/aprs.py @@ -150,54 +150,56 @@ class MicEParser(object): return comment[4:], decodeBase91(comment[:3]) - 10000 def extractDevice(self, comment): - if comment[0] == ">": - if comment[-1] == "=": - return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D72"} - if comment[-1] == "^": - return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D74"} - return comment[1:], {"manufacturer": "Kenwood", "device": "TH-D7A"} - if comment[0] == "]": - if comment[-1] == "=": - return comment[1:-1], {"manufacturer": "Kenwood", "device": "TM-D710"} - return comment[1:], {"manufacturer": "Kenwood", "device": "TM-D700"} - if comment[0] == "`" or comment[0] == "'": - if comment[-2] == "_": - devices = { - "b": "VX-8", - "\"": "FTM-350", - "#": "VX-8G", - "$": "FT1D", - "%": "FTM-400DR", - ")": "FTM-100D", - "(": "FT2D", - "0": "FT3D", - } - return comment[1:-2], {"manufacturer": "Yaesu", "device": devices.get(comment[-1], "Unknown")} - if comment[-2:] == " X": - return comment[1:-2], {"manufacturer": "SainSonic", "device": "AP510"} - if comment[-2] == "(": - 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" - } - 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")} - if comment[-2:] == "~v": - return comment[1:-2], {"manufacturer": "Other", "device": "Other"} - return comment[1:-2], None + if len(comment) > 0: + if comment[0] == ">": + if len(comment) > 1: + if comment[-1] == "=": + return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D72"} + if comment[-1] == "^": + return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D74"} + return comment[1:], {"manufacturer": "Kenwood", "device": "TH-D7A"} + if comment[0] == "]": + if len(comment) > 1 and comment[-1] == "=": + return comment[1:-1], {"manufacturer": "Kenwood", "device": "TM-D710"} + return comment[1:], {"manufacturer": "Kenwood", "device": "TM-D700"} + if len(comment) > 2 and (comment[0] == "`" or comment[0] == "'"): + if comment[-2] == "_": + devices = { + "b": "VX-8", + "\"": "FTM-350", + "#": "VX-8G", + "$": "FT1D", + "%": "FTM-400DR", + ")": "FTM-100D", + "(": "FT2D", + "0": "FT3D", + } + return comment[1:-2], {"manufacturer": "Yaesu", "device": devices.get(comment[-1], "Unknown")} + if comment[-2:] == " X": + return comment[1:-2], {"manufacturer": "SainSonic", "device": "AP510"} + if comment[-2] == "(": + 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" + } + 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")} + if comment[-2:] == "~v": + return comment[1:-2], {"manufacturer": "Other", "device": "Other"} + return comment[1:-2], None return comment, None def parse(self, data):