Skip to content

Commit

Permalink
filter out problematic spots instead of breaking completely
Browse files Browse the repository at this point in the history
  • Loading branch information
lazywalker committed Jan 14, 2021
1 parent 21e0133 commit dc36475
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions digiskr/pskreporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def upload(self, spots):

def getPackets(self, 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):
"""Yield successive n-sized chunks from l."""
Expand Down Expand Up @@ -161,17 +163,22 @@ def encodeString(self, s):
return [len(s)] + list(s.encode("utf-8"))

def encodeSpot(self, spot):
return bytes(
self.encodeString(spot["callsign"])
# freq in Hz to pskreporter
+ list(int(spot["freq"]*1e6).to_bytes(4, "big"))
+ list(int(spot["db"]).to_bytes(1, "big", signed=True))
+ self.encodeString(spot["mode"])
+ self.encodeString(spot["locator"])
# informationsource. 1 means "automatically extracted
+ [0x01]
+ list(spot["timestamp"].to_bytes(4, "big"))
)
try:
return bytes(
self.encodeString(spot["callsign"])
# freq in Hz to pskreporter
+ list(int(spot["freq"]*1e6).to_bytes(4, "big"))
+ list(int(spot["db"]).to_bytes(1, "big", signed=True))
+ self.encodeString(spot["mode"])
+ self.encodeString(spot["locator"])
# informationsource. 1 means "automatically extracted
+ [0x01]
+ list(spot["timestamp"].to_bytes(4, "big"))
)
except Exception:
logging.exception("Error while encoding spot for pskreporter")
return None


def getReceiverInformationHeader(self):
return bytes(
Expand Down

0 comments on commit dc36475

Please sign in to comment.