restore s-meter display

This commit is contained in:
Jakob Ketterl 2021-07-25 00:05:48 +02:00
parent c50da15bfd
commit 207ada70fd
3 changed files with 19 additions and 2 deletions

View File

@ -36,6 +36,7 @@ from owrx.audio.chopper import AudioChopper
from csdr.pipe import Pipe from csdr.pipe import Pipe
from pycsdr.modules import Buffer from pycsdr.modules import Buffer
from pycsdr.types import Format
from csdr.chain.demodulator import DemodulatorChain from csdr.chain.demodulator import DemodulatorChain
from csdr.chain.fm import Fm from csdr.chain.fm import Fm
from csdr.chain.am import Am from csdr.chain.am import Am
@ -51,6 +52,7 @@ class Dsp(DirewolfConfigSubscriber):
self.pycsdr_enabled = True self.pycsdr_enabled = True
self.pycsdr_chain = None self.pycsdr_chain = None
self.pycsdr_reader = None self.pycsdr_reader = None
self.pycsdr_power_reader = None
self.buffer = None self.buffer = None
self.samp_rate = 250000 self.samp_rate = 250000
@ -735,6 +737,10 @@ class Dsp(DirewolfConfigSubscriber):
chain.setWriter(outputBuffer) chain.setWriter(outputBuffer)
self.pycsdr_reader = outputBuffer.getReader() self.pycsdr_reader = outputBuffer.getReader()
self.output.send_output("audio", self.pycsdr_reader.read) 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 return
command_base = " | ".join(chain) command_base = " | ".join(chain)
@ -831,6 +837,8 @@ class Dsp(DirewolfConfigSubscriber):
self.pycsdr_chain = None self.pycsdr_chain = None
self.pycsdr_reader.stop() self.pycsdr_reader.stop()
self.pycsdr_reader = None self.pycsdr_reader = None
self.pycsdr_power_reader.stop()
self.pycsdr_power_reader = None
if self.process is not None: if self.process is not None:
try: try:
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)

View File

@ -1,5 +1,5 @@
from csdr.chain import Chain 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 from pycsdr.types import Format
@ -15,7 +15,7 @@ class DemodulatorChain(Chain):
bp_transition = 320.0 / if_samp_rate bp_transition = 320.0 / if_samp_rate
self.bandpass = Bandpass(transition=bp_transition, use_fft=True) 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] workers = [self.shift, self.decimation]
@ -35,6 +35,9 @@ class DemodulatorChain(Chain):
def setBandpass(self, low_cut: float, high_cut: float): def setBandpass(self, low_cut: float, high_cut: float):
self.bandpass.setBandpass(low_cut, high_cut) self.bandpass.setBandpass(low_cut, high_cut)
def setPowerWriter(self, writer: Writer):
self.squelch.setPowerWriter(writer)
def _getDecimation(self, input_rate, output_rate): def _getDecimation(self, input_rate, output_rate):
if output_rate <= 0: if output_rate <= 0:
raise ValueError("invalid output rate: {rate}".format(rate=output_rate)) raise ValueError("invalid output rate: {rate}".format(rate=output_rate))

View File

@ -19,6 +19,7 @@ from js8py import Js8Frame
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import json import json
import threading import threading
import struct
import logging import logging
@ -376,6 +377,11 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
self.send(bytes([0x04]) + data) self.send(bytes([0x04]) + data)
def write_s_meter_level(self, level): 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: try:
self.send({"type": "smeter", "value": level}) self.send({"type": "smeter", "value": level})
except ValueError: except ValueError: