filter out problematic spots instead of breaking completely

This commit is contained in:
Jakob Ketterl 2020-12-09 23:38:27 +01:00
parent eef61f9d1e
commit fcff9d16ff
1 changed files with 16 additions and 10 deletions

View File

@ -115,6 +115,8 @@ class Uploader(object):
def getPackets(self, spots): def getPackets(self, spots):
encoded = [self.encodeSpot(spot) for spot in spots] encoded = [self.encodeSpot(spot) for spot in spots]
# filter out any erroneous encodes
encoded = [e for e in encoded if e is not None]
def chunks(l, n): def chunks(l, n):
"""Yield successive n-sized chunks from l.""" """Yield successive n-sized chunks from l."""
@ -150,16 +152,20 @@ class Uploader(object):
return [len(s)] + list(s.encode("utf-8")) return [len(s)] + list(s.encode("utf-8"))
def encodeSpot(self, spot): def encodeSpot(self, spot):
return bytes( try:
self.encodeString(spot["callsign"]) return bytes(
+ list(int(spot["freq"]).to_bytes(4, "big")) self.encodeString(spot["callsign"])
+ list(int(spot["db"]).to_bytes(1, "big", signed=True)) + list(int(spot["freq"]).to_bytes(4, "big"))
+ self.encodeString(spot["mode"]) + list(int(spot["db"]).to_bytes(1, "big", signed=True))
+ self.encodeString(spot["locator"]) + self.encodeString(spot["mode"])
# informationsource. 1 means "automatically extracted + self.encodeString(spot["locator"])
+ [0x01] # informationsource. 1 means "automatically extracted
+ list(int(spot["timestamp"] / 1000).to_bytes(4, "big")) + [0x01]
) + list(int(spot["timestamp"] / 1000).to_bytes(4, "big"))
)
except Exception:
logger.exception("Error while encoding spot for pskreporter")
return None
def getReceiverInformationHeader(self): def getReceiverInformationHeader(self):
return bytes( return bytes(