put the socketclient on the source so it can be shared

This commit is contained in:
Jakob Ketterl 2020-12-19 16:28:18 +01:00
parent 1bd6aa73f3
commit efe80a75f5
5 changed files with 27 additions and 4 deletions

View File

@ -12,5 +12,8 @@ class Chain(object):
for w in self.workers: for w in self.workers:
w.stop() w.stop()
def setInput(self, buffer):
self.workers[0].setInput(buffer)
def getBuffer(self): def getBuffer(self):
return self.buffer return self.buffer

View File

@ -1,11 +1,10 @@
from csdr.chain import Chain from csdr.chain import Chain
from pycsdr import SocketClient, Fft, LogAveragePower, FftExchangeSides, CompressFftAdpcm from pycsdr import Fft, LogAveragePower, FftExchangeSides, CompressFftAdpcm
class FftChain(Chain): class FftChain(Chain):
def __init__(self, port, fft_size, fft_block_size, fft_averages, fft_compression): def __init__(self, fft_size, fft_block_size, fft_averages, fft_compression):
workers = [ workers = [
SocketClient(port=port),
Fft(size=fft_size, every_n_samples=int(fft_block_size)), Fft(size=fft_size, every_n_samples=int(fft_block_size)),
LogAveragePower(add_db=-70, fft_size=fft_size, avg_number=fft_averages), LogAveragePower(add_db=-70, fft_size=fft_size, avg_number=fft_averages),
FftExchangeSides(fft_size=fft_size), FftExchangeSides(fft_size=fft_size),

View File

@ -77,6 +77,7 @@ class dsp(object):
def __init__(self, output): def __init__(self, output):
self.pycsdr_enabled = True self.pycsdr_enabled = True
self.pycsdr_chain = None self.pycsdr_chain = None
self.socketClient = None
self.samp_rate = 250000 self.samp_rate = 250000
self.output_rate = 11025 self.output_rate = 11025
@ -137,6 +138,11 @@ class dsp(object):
self.direwolf_port = None self.direwolf_port = None
self.process = None self.process = None
def setSocketClient(self, socketClient):
self.socketClient = socketClient
if self.pycsdr_chain is not None:
self.pycsdr_chain.setInput(socketClient.getBuffer())
def set_service(self, flag=True): def set_service(self, flag=True):
self.is_service = flag self.is_service = flag
@ -766,13 +772,15 @@ class dsp(object):
self.running = True self.running = True
self.pycsdr_chain = FftChain( self.pycsdr_chain = FftChain(
port=self.nc_port,
fft_size=self.fft_size, fft_size=self.fft_size,
fft_block_size=self.fft_block_size(), fft_block_size=self.fft_block_size(),
fft_averages=self.fft_averages, fft_averages=self.fft_averages,
fft_compression=self.fft_compression fft_compression=self.fft_compression
) )
if self.socketClient is not None:
self.pycsdr_chain.setInput(self.socketClient.getBuffer())
self.output.send_output("audio", self.pycsdr_chain.getBuffer().read) self.output.send_output("audio", self.pycsdr_chain.getBuffer().read)
return return

View File

@ -31,6 +31,7 @@ class SpectrumThread(csdr.output, SdrSourceEventClient):
self.dsp = dsp = csdr.dsp(self) self.dsp = dsp = csdr.dsp(self)
dsp.nc_port = self.sdrSource.getPort() dsp.nc_port = self.sdrSource.getPort()
dsp.setSocketClient(self.sdrSource.getSocketClient())
dsp.set_demodulator("fft") dsp.set_demodulator("fft")
def set_fft_averages(key, value): def set_fft_averages(key, value):

View File

@ -11,6 +11,8 @@ from owrx.command import CommandMapper
from owrx.socket import getAvailablePort from owrx.socket import getAvailablePort
from owrx.property import PropertyStack, PropertyLayer from owrx.property import PropertyStack, PropertyLayer
from pycsdr import SocketClient
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -48,6 +50,7 @@ class SdrSource(ABC):
self.id = id self.id = id
self.commandMapper = None self.commandMapper = None
self.socketClient = None
self.props = PropertyStack() self.props = PropertyStack()
# layer 0 reserved for profile properties # layer 0 reserved for profile properties
@ -141,6 +144,12 @@ class SdrSource(ABC):
def getPort(self): def getPort(self):
return self.port return self.port
def getSocketClient(self):
with self.modificationLock:
if self.socketClient is None:
self.socketClient = SocketClient(self.port)
return self.socketClient
def getCommandValues(self): def getCommandValues(self):
dict = self.sdrProps.__dict__() dict = self.sdrProps.__dict__()
if "lfo_offset" in dict and dict["lfo_offset"] is not None: if "lfo_offset" in dict and dict["lfo_offset"] is not None:
@ -249,6 +258,9 @@ class SdrSource(ABC):
pass pass
if self.monitor: if self.monitor:
self.monitor.join() self.monitor.join()
if self.socketClient is not None:
self.socketClient.stop()
self.socketClient = None
def hasClients(self, *args): def hasClients(self, *args):
clients = [c for c in self.clients if c.getClientClass() in args] clients = [c for c in self.clients if c.getClientClass() in args]