diff --git a/csdr/__init__.py b/csdr/__init__.py index 1677fb8..5c882a0 100644 --- a/csdr/__init__.py +++ b/csdr/__init__.py @@ -56,6 +56,7 @@ class Dsp(DirewolfConfigSubscriber): self.pycsdr_client_chain = None self.pycsdr_reader = None self.pycsdr_power_reader = None + self.pycsdr_meta_reader = None self.buffer = None self.samp_rate = 250000 @@ -764,6 +765,22 @@ class Dsp(DirewolfConfigSubscriber): chain.setPowerWriter(powerBuffer) self.pycsdr_power_reader = powerBuffer.getReader() self.output.send_output("smeter", self.pycsdr_power_reader.read) + + if self.isDigitalVoice(): + metaBuffer = Buffer(Format.CHAR) + chain.setMetaWriter(metaBuffer) + self.pycsdr_meta_reader = metaBuffer.getReader() + + def read_meta(): + raw = self.pycsdr_meta_reader.read() + if raw is None or len(raw) == 0: + return None + else: + raw = raw.tobytes().decode("cp437") + return raw.rstrip("\n") + + self.output.send_output("meta", read_meta) + return command_base = " | ".join(chain) @@ -864,6 +881,9 @@ class Dsp(DirewolfConfigSubscriber): self.pycsdr_power_reader = None self.pycsdr_client_chain.stop() self.pycsdr_client_chain = None + if self.pycsdr_meta_reader is not None: + self.pycsdr_meta_reader.stop() + self.pycsdr_meta_reader = None if self.process is not None: try: os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) diff --git a/csdr/chain/demodulator.py b/csdr/chain/demodulator.py index ba23161..88ac813 100644 --- a/csdr/chain/demodulator.py +++ b/csdr/chain/demodulator.py @@ -5,6 +5,8 @@ from pycsdr.types import Format class DemodulatorChain(Chain): def __init__(self, samp_rate: int, audioRate: int, shiftRate: float, demodulator: Chain): + self.demodulator = demodulator + self.shift = Shift(shiftRate) decimation, fraction = self._getDecimation(samp_rate, audioRate) @@ -44,6 +46,9 @@ class DemodulatorChain(Chain): def setPowerWriter(self, writer: Writer): self.squelch.setPowerWriter(writer) + def setMetaWriter(self, writer: Writer): + self.demodulator.setMetaWriter(writer) + def _getDecimation(self, input_rate, output_rate): if output_rate <= 0: raise ValueError("invalid output rate: {rate}".format(rate=output_rate)) diff --git a/csdr/chain/digiham.py b/csdr/chain/digiham.py index 110d8a5..29a0370 100644 --- a/csdr/chain/digiham.py +++ b/csdr/chain/digiham.py @@ -1,44 +1,46 @@ from csdr.chain import Chain -from pycsdr.modules import FmDemod, Agc +from pycsdr.modules import FmDemod, Agc, Writer from pycsdr.types import Format from digiham.modules import DstarDecoder, DcBlock, FskDemodulator, GfskDemodulator, DigitalVoiceFilter, MbeSynthesizer, NarrowRrcFilter, NxdnDecoder from digiham.ambe import Modes -class Dstar(Chain): +class DigihamChain(Chain): def __init__(self, codecserver: str = ""): if codecserver is None: codecserver = "" - agc = Agc(Format.SHORT) - agc.setMaxGain(30) - agc.setInitialGain(3) workers = [ FmDemod(), DcBlock(), - FskDemodulator(samplesPerSymbol=10), - DstarDecoder(), - MbeSynthesizer(Modes.DStarMode, codecserver), + self.fskDemodulator, + self.decoder, + MbeSynthesizer(self.mbeMode, codecserver), DigitalVoiceFilter(), - agc + self.agc ] super().__init__(*workers) + def setMetaWriter(self, writer: Writer): + self.decoder.setMetaWriter(writer) -class Nxdn(Chain): + +class Dstar(DigihamChain): def __init__(self, codecserver: str = ""): - if codecserver is None: - codecserver = "" - agc = Agc(Format.SHORT) - agc.setMaxGain(30) - agc.setInitialGain(3) - workers = [ - FmDemod(), - DcBlock(), - NarrowRrcFilter(), - GfskDemodulator(samplesPerSymbol=20), - NxdnDecoder(), - MbeSynthesizer(Modes.NxdnMode, codecserver), - DigitalVoiceFilter(), - agc, - ] - super().__init__(*workers) + self.fskDemodulator = FskDemodulator(samplesPerSymbol=10) + self.decoder = DstarDecoder() + self.mbeMode = Modes.DStarMode + self.agc = Agc(Format.SHORT) + self.agc.setMaxGain(30) + self.agc.setInitialGain(3) + super().__init__(codecserver) + + +class Nxdn(DigihamChain): + def __init__(self, codecserver: str = ""): + self.fskDemodulator = GfskDemodulator(samplesPerSymbol=20) + self.decoder = NxdnDecoder() + self.mbeMode = Modes.NxdnMode + self.agc = Agc(Format.SHORT) + self.agc.setMaxGain(30) + self.agc.setInitialGain(3) + super().__init__(codecserver)