diff --git a/csdr/chain/dumphfdl.py b/csdr/chain/dumphfdl.py new file mode 100644 index 00000000..8c7b08f7 --- /dev/null +++ b/csdr/chain/dumphfdl.py @@ -0,0 +1,14 @@ +from csdr.chain.demodulator import ServiceDemodulator +from owrx.hfdl.dumphfdl import DumpHFDLModule +from csdr.module import JsonParser + + +class DumpHFDL(ServiceDemodulator): + def __init__(self): + super().__init__([ + DumpHFDLModule(), + JsonParser("HFDL"), + ]) + + def getFixedAudioRate(self) -> int: + return 12000 diff --git a/csdr/chain/rtl433.py b/csdr/chain/rtl433.py index 6b9f5704..f1f95341 100644 --- a/csdr/chain/rtl433.py +++ b/csdr/chain/rtl433.py @@ -1,4 +1,5 @@ -from owrx.ism.rtl433 import Rtl433Module, JsonParser +from csdr.module import JsonParser +from owrx.ism.rtl433 import Rtl433Module from csdr.chain.demodulator import ServiceDemodulator @@ -10,6 +11,6 @@ class Rtl433(ServiceDemodulator): super().__init__( [ Rtl433Module(), - JsonParser(), + JsonParser("ISM"), ] ) diff --git a/csdr/module/__init__.py b/csdr/module/__init__.py index 3ee0d0ec..df79e8ed 100644 --- a/csdr/module/__init__.py +++ b/csdr/module/__init__.py @@ -8,6 +8,9 @@ from subprocess import Popen, PIPE from functools import partial import pickle import logging +import json + +logger = logging.getLogger(__name__) class Module(BaseModule, metaclass=ABCMeta): @@ -146,6 +149,21 @@ class LineBasedModule(ThreadModule, metaclass=ABCMeta): pass +class JsonParser(LineBasedModule): + def __init__(self, mode: str): + self.mode = mode + super().__init__() + + def process(self, line): + try: + msg = json.loads(line.decode()) + msg["mode"] = self.mode + logger.debug(msg) + return msg + except json.JSONDecodeError: + logger.exception("error parsing rtl433 json") + + class PopenModule(AutoStartModule, metaclass=ABCMeta): def __init__(self): self.process = None diff --git a/htdocs/index.html b/htdocs/index.html index 8a9b3535..960e5c96 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -76,6 +76,7 @@ +