make sure there is actually enough data to parse

This commit is contained in:
Jakob Ketterl 2019-08-15 19:50:47 +02:00
parent 765f075576
commit 88bbb76752

View File

@ -150,54 +150,56 @@ class MicEParser(object):
return comment[4:], decodeBase91(comment[:3]) - 10000 return comment[4:], decodeBase91(comment[:3]) - 10000
def extractDevice(self, comment): def extractDevice(self, comment):
if comment[0] == ">": if len(comment) > 0:
if comment[-1] == "=": if comment[0] == ">":
return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D72"} if len(comment) > 1:
if comment[-1] == "^": if comment[-1] == "=":
return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D74"} return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D72"}
return comment[1:], {"manufacturer": "Kenwood", "device": "TH-D7A"} if comment[-1] == "^":
if comment[0] == "]": return comment[1:-1], {"manufacturer": "Kenwood", "device": "TH-D74"}
if comment[-1] == "=": return comment[1:], {"manufacturer": "Kenwood", "device": "TH-D7A"}
return comment[1:-1], {"manufacturer": "Kenwood", "device": "TM-D710"} if comment[0] == "]":
return comment[1:], {"manufacturer": "Kenwood", "device": "TM-D700"} if len(comment) > 1 and comment[-1] == "=":
if comment[0] == "`" or comment[0] == "'": return comment[1:-1], {"manufacturer": "Kenwood", "device": "TM-D710"}
if comment[-2] == "_": return comment[1:], {"manufacturer": "Kenwood", "device": "TM-D700"}
devices = { if len(comment) > 2 and (comment[0] == "`" or comment[0] == "'"):
"b": "VX-8", if comment[-2] == "_":
"\"": "FTM-350", devices = {
"#": "VX-8G", "b": "VX-8",
"$": "FT1D", "\"": "FTM-350",
"%": "FTM-400DR", "#": "VX-8G",
")": "FTM-100D", "$": "FT1D",
"(": "FT2D", "%": "FTM-400DR",
"0": "FT3D", ")": "FTM-100D",
} "(": "FT2D",
return comment[1:-2], {"manufacturer": "Yaesu", "device": devices.get(comment[-1], "Unknown")} "0": "FT3D",
if comment[-2:] == " X": }
return comment[1:-2], {"manufacturer": "SainSonic", "device": "AP510"} return comment[1:-2], {"manufacturer": "Yaesu", "device": devices.get(comment[-1], "Unknown")}
if comment[-2] == "(": if comment[-2:] == " X":
devices = { return comment[1:-2], {"manufacturer": "SainSonic", "device": "AP510"}
"5": "D578UV", if comment[-2] == "(":
"8": "D878UV" devices = {
} "5": "D578UV",
return comment[1:-2], {"manufacturer": "Anytone", "device": devices.get(comment[-1], "Unknown")} "8": "D878UV"
if comment[-2] == "|": }
devices = { return comment[1:-2], {"manufacturer": "Anytone", "device": devices.get(comment[-1], "Unknown")}
"3": "TinyTrack3", if comment[-2] == "|":
"4": "TinyTrack4" devices = {
} "3": "TinyTrack3",
return comment[1:-2], {"manufacturer": "Byonics", "device": devices.get(comment[-1], "Unknown")} "4": "TinyTrack4"
if comment[-2:] == "^v": }
return comment[1:-2], {"manufacturer": "HinzTec", "device": "anyfrog"} return comment[1:-2], {"manufacturer": "Byonics", "device": devices.get(comment[-1], "Unknown")}
if comment[-2] == ":": if comment[-2:] == "^v":
devices = { return comment[1:-2], {"manufacturer": "HinzTec", "device": "anyfrog"}
"4": "P4dragon DR-7400 modem", if comment[-2] == ":":
"8": "P4dragon DR-7800 modem" devices = {
} "4": "P4dragon DR-7400 modem",
return comment[1:-2], {"manufacturer": "SCS GmbH & Co.", "device": devices.get(comment[-1], "Unknown")} "8": "P4dragon DR-7800 modem"
if comment[-2:] == "~v": }
return comment[1:-2], {"manufacturer": "Other", "device": "Other"} return comment[1:-2], {"manufacturer": "SCS GmbH & Co.", "device": devices.get(comment[-1], "Unknown")}
return comment[1:-2], None if comment[-2:] == "~v":
return comment[1:-2], {"manufacturer": "Other", "device": "Other"}
return comment[1:-2], None
return comment, None return comment, None
def parse(self, data): def parse(self, data):