2020-01-09 14:11:53 +00:00
|
|
|
from owrx.parser import Parser
|
|
|
|
|
2021-01-22 18:48:31 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-01-09 14:11:53 +00:00
|
|
|
|
|
|
|
class PocsagParser(Parser):
|
|
|
|
def parse(self, raw):
|
2021-01-22 18:48:31 +00:00
|
|
|
try:
|
|
|
|
fields = raw.decode("ascii", "replace").rstrip("\n").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"])
|
|
|
|
self.handler.write_pocsag_data(meta)
|
|
|
|
except Exception:
|
|
|
|
logger.exception("Exception while parsing Pocsag message")
|