From 72f925e537916bb9b7905bcddf9526ec3be58677 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 10 Sep 2021 15:38:36 +0200 Subject: [PATCH] receive pocsag messages in pickled form --- owrx/pocsag.py | 43 ++++++++++--------------------------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/owrx/pocsag.py b/owrx/pocsag.py index 0317fff..70ad611 100644 --- a/owrx/pocsag.py +++ b/owrx/pocsag.py @@ -1,38 +1,15 @@ -from csdr.module import ThreadModule -from pycsdr.types import Format -import pickle - +from csdr.module import PickleModule import logging logger = logging.getLogger(__name__) -class PocsagParser(ThreadModule): - def getInputFormat(self) -> Format: - return Format.CHAR - - def getOutputFormat(self) -> Format: - return Format.CHAR - - def run(self): - while self.doRun: - data = self.reader.read() - if data is None: - self.doRun = False - else: - for frame in self.parse(data.tobytes()): - self.writer.write(pickle.dumps(frame)) - - def parse(self, raw): - for line in raw.split(b"\n"): - if not len(line): - continue - try: - fields = line.decode("ascii", "replace").split(";") - meta = {v[0]: "".join(v[1:]) for v in map(lambda x: x.split(":"), fields) if v[0] != ""} - if "address" in meta: - meta["address"] = int(meta["address"]) - meta["mode"] = "Pocsag" - yield meta - except Exception: - logger.exception("Exception while parsing Pocsag message") +class PocsagParser(PickleModule): + def process(self, meta): + try: + if "address" in meta: + meta["address"] = int(meta["address"]) + meta["mode"] = "Pocsag" + return meta + except Exception: + logger.exception("Exception while parsing Pocsag message")