receive pocsag messages in pickled form
This commit is contained in:
parent
bf37dee78b
commit
72f925e537
@ -1,38 +1,15 @@
|
|||||||
from csdr.module import ThreadModule
|
from csdr.module import PickleModule
|
||||||
from pycsdr.types import Format
|
|
||||||
import pickle
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PocsagParser(ThreadModule):
|
class PocsagParser(PickleModule):
|
||||||
def getInputFormat(self) -> Format:
|
def process(self, meta):
|
||||||
return Format.CHAR
|
try:
|
||||||
|
if "address" in meta:
|
||||||
def getOutputFormat(self) -> Format:
|
meta["address"] = int(meta["address"])
|
||||||
return Format.CHAR
|
meta["mode"] = "Pocsag"
|
||||||
|
return meta
|
||||||
def run(self):
|
except Exception:
|
||||||
while self.doRun:
|
logger.exception("Exception while parsing Pocsag message")
|
||||||
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")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user