From 207ada70fd8af48f5181f227491fd59bff5a8fab Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 25 Jul 2021 00:05:48 +0200 Subject: [PATCH] restore s-meter display --- csdr/__init__.py | 8 ++++++++ csdr/chain/demodulator.py | 7 +++++-- owrx/connection.py | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/csdr/__init__.py b/csdr/__init__.py index 162e5ea..757aead 100644 --- a/csdr/__init__.py +++ b/csdr/__init__.py @@ -36,6 +36,7 @@ from owrx.audio.chopper import AudioChopper from csdr.pipe import Pipe from pycsdr.modules import Buffer +from pycsdr.types import Format from csdr.chain.demodulator import DemodulatorChain from csdr.chain.fm import Fm from csdr.chain.am import Am @@ -51,6 +52,7 @@ class Dsp(DirewolfConfigSubscriber): self.pycsdr_enabled = True self.pycsdr_chain = None self.pycsdr_reader = None + self.pycsdr_power_reader = None self.buffer = None self.samp_rate = 250000 @@ -735,6 +737,10 @@ class Dsp(DirewolfConfigSubscriber): chain.setWriter(outputBuffer) self.pycsdr_reader = outputBuffer.getReader() self.output.send_output("audio", self.pycsdr_reader.read) + powerBuffer = Buffer(Format.FLOAT) + chain.setPowerWriter(powerBuffer) + self.pycsdr_power_reader = powerBuffer.getReader() + self.output.send_output("smeter", self.pycsdr_power_reader.read) return command_base = " | ".join(chain) @@ -831,6 +837,8 @@ class Dsp(DirewolfConfigSubscriber): self.pycsdr_chain = None self.pycsdr_reader.stop() self.pycsdr_reader = None + self.pycsdr_power_reader.stop() + self.pycsdr_power_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 2960a6f..4214c4d 100644 --- a/csdr/chain/demodulator.py +++ b/csdr/chain/demodulator.py @@ -1,5 +1,5 @@ from csdr.chain import Chain -from pycsdr.modules import Shift, FirDecimate, Bandpass, Squelch, FractionalDecimator +from pycsdr.modules import Shift, FirDecimate, Bandpass, Squelch, FractionalDecimator, Writer from pycsdr.types import Format @@ -15,7 +15,7 @@ class DemodulatorChain(Chain): bp_transition = 320.0 / if_samp_rate self.bandpass = Bandpass(transition=bp_transition, use_fft=True) - self.squelch = Squelch(5) + self.squelch = Squelch(5, int(if_samp_rate / 6000)) workers = [self.shift, self.decimation] @@ -35,6 +35,9 @@ class DemodulatorChain(Chain): def setBandpass(self, low_cut: float, high_cut: float): self.bandpass.setBandpass(low_cut, high_cut) + def setPowerWriter(self, writer: Writer): + self.squelch.setPowerWriter(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/owrx/connection.py b/owrx/connection.py index a991eb8..3347bca 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -19,6 +19,7 @@ from js8py import Js8Frame from abc import ABCMeta, abstractmethod import json import threading +import struct import logging @@ -376,6 +377,11 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): self.send(bytes([0x04]) + data) def write_s_meter_level(self, level): + if isinstance(level, memoryview): + level, = struct.unpack('f', level) + if not isinstance(level, float): + logger.warning("s-meter value has unexpected type") + return try: self.send({"type": "smeter", "value": level}) except ValueError: