diff --git a/csdr/chain/m17.py b/csdr/chain/m17.py index 2f12cca..a54ecd7 100644 --- a/csdr/chain/m17.py +++ b/csdr/chain/m17.py @@ -1,18 +1,19 @@ -from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain +from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, MetaProvider from csdr.module.m17 import M17Module -from pycsdr.modules import FmDemod, Limit, Convert +from pycsdr.modules import FmDemod, Limit, Convert, Writer from pycsdr.types import Format from digiham.modules import DcBlock -class M17(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain): +class M17(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, MetaProvider): def __init__(self): + self.module = M17Module() workers = [ FmDemod(), DcBlock(), Limit(), Convert(Format.FLOAT, Format.SHORT), - M17Module(), + self.module, ] super().__init__(workers) @@ -24,3 +25,6 @@ class M17(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain): def supportsSquelch(self) -> bool: return False + + def setMetaWriter(self, writer: Writer) -> None: + self.module.setMetaWriter(writer) diff --git a/csdr/module/__init__.py b/csdr/module/__init__.py index 64374a6..1fea434 100644 --- a/csdr/module/__init__.py +++ b/csdr/module/__init__.py @@ -118,8 +118,11 @@ class PopenModule(AutoStartModule, metaclass=ABCMeta): def getCommand(self): pass + def _getProcess(self): + return Popen(self.getCommand(), stdin=PIPE, stdout=PIPE) + def start(self): - self.process = Popen(self.getCommand(), stdin=PIPE, stdout=PIPE) + self.process = self._getProcess() # resume in case the reader has been stop()ed before self.reader.resume() Thread(target=self.pump(self.reader.read, self.process.stdin.write)).start() diff --git a/csdr/module/m17.py b/csdr/module/m17.py index e58402a..5bcf544 100644 --- a/csdr/module/m17.py +++ b/csdr/module/m17.py @@ -1,8 +1,20 @@ from csdr.module import PopenModule from pycsdr.types import Format +from pycsdr.modules import Writer +from subprocess import Popen, PIPE +from threading import Thread + +import re +import pickle class M17Module(PopenModule): + lsfRegex = re.compile("SRC: ([a-zA-Z0-9]+), DEST: ([a-zA-Z0-9]+)") + + def __init__(self): + super().__init__() + self.metawriter = None + def getInputFormat(self) -> Format: return Format.SHORT @@ -10,4 +22,37 @@ class M17Module(PopenModule): return Format.SHORT def getCommand(self): - return ["m17-demod"] + return ["m17-demod", "-l"] + + def _getProcess(self): + return Popen(self.getCommand(), stdin=PIPE, stdout=PIPE, stderr=PIPE) + + def start(self): + super().start() + Thread(target=self._readOutput).start() + + def _readOutput(self): + while True: + line = self.process.stderr.readline() + if not line: + break + self.parseOutput(line.decode()) + + def parseOutput(self, line): + if self.metawriter is None: + return + matches = self.lsfRegex.match(line) + msg = {"protocol": "M17"} + if matches: + # fake sync + msg["sync"] = "voice" + msg["source"] = matches.group(1) + msg["destination"] = matches.group(2) + elif line.startswith("EOS"): + pass + else: + return + self.metawriter.write(pickle.dumps(msg)) + + def setMetaWriter(self, writer: Writer) -> None: + self.metawriter = writer diff --git a/htdocs/css/openwebrx.css b/htdocs/css/openwebrx.css index be84038..cbbacdb 100644 --- a/htdocs/css/openwebrx.css +++ b/htdocs/css/openwebrx.css @@ -1025,7 +1025,8 @@ img.openwebrx-mirror-img .openwebrx-meta-slot.active.direct .openwebrx-meta-user-image .directcall, .openwebrx-meta-slot.active.individual .openwebrx-meta-user-image .directcall, #openwebrx-panel-metadata-ysf .openwebrx-meta-slot.active .openwebrx-meta-user-image .directcall, -#openwebrx-panel-metadata-dstar .openwebrx-meta-slot.active .openwebrx-meta-user-image .directcall { +#openwebrx-panel-metadata-dstar .openwebrx-meta-slot.active .openwebrx-meta-user-image .directcall, +#openwebrx-panel-metadata-m17 .openwebrx-meta-slot.active .openwebrx-meta-user-image .directcall { display: initial; } @@ -1059,6 +1060,14 @@ img.openwebrx-mirror-img content: "Down: "; } +.openwebrx-m17-source:not(:empty):before { + content: "SRC: "; +} + +.openwebrx-m17-destination:not(:empty):before { + content: "DEST: "; +} + .openwebrx-dstar-yourcall:not(:empty):before { content: "UR: "; } diff --git a/htdocs/index.html b/htdocs/index.html index 9ba65eb..18834b3 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -74,6 +74,15 @@ +