streamline sdr and dsp integration
This commit is contained in:
parent
03049b79dd
commit
117d0483f7
@ -151,6 +151,14 @@ class SdrSource(object):
|
|||||||
self.process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setpgrp)
|
self.process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setpgrp)
|
||||||
logger.info("Started rtl source: " + cmd)
|
logger.info("Started rtl source: " + cmd)
|
||||||
|
|
||||||
|
def wait_for_process_to_end():
|
||||||
|
rc = self.process.wait()
|
||||||
|
logger.debug("shut down with RC={0}".format(rc))
|
||||||
|
self.monitor = None
|
||||||
|
|
||||||
|
self.monitor = threading.Thread(target = wait_for_process_to_end)
|
||||||
|
self.monitor.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
testsock = socket.socket()
|
testsock = socket.socket()
|
||||||
try:
|
try:
|
||||||
@ -160,15 +168,6 @@ class SdrSource(object):
|
|||||||
except:
|
except:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
def wait_for_process_to_end():
|
|
||||||
rc = self.process.wait()
|
|
||||||
logger.debug("shut down with RC={0}".format(rc))
|
|
||||||
self.monitor = None
|
|
||||||
|
|
||||||
self.monitor = threading.Thread(target = wait_for_process_to_end)
|
|
||||||
self.monitor.start()
|
|
||||||
|
|
||||||
self.modificationLock.release()
|
self.modificationLock.release()
|
||||||
|
|
||||||
for c in self.clients:
|
for c in self.clients:
|
||||||
@ -254,7 +253,6 @@ class SpectrumThread(csdr.output):
|
|||||||
self.sdrSource = sdrSource
|
self.sdrSource = sdrSource
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def start(self):
|
|
||||||
props = self.sdrSource.props.collect(
|
props = self.sdrSource.props.collect(
|
||||||
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression",
|
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression",
|
||||||
"csdr_dynamic_bufsize", "csdr_print_bufsizes", "csdr_through"
|
"csdr_dynamic_bufsize", "csdr_print_bufsizes", "csdr_through"
|
||||||
@ -282,11 +280,17 @@ class SpectrumThread(csdr.output):
|
|||||||
dsp.csdr_print_bufsizes = props["csdr_print_bufsizes"]
|
dsp.csdr_print_bufsizes = props["csdr_print_bufsizes"]
|
||||||
dsp.csdr_through = props["csdr_through"]
|
dsp.csdr_through = props["csdr_through"]
|
||||||
logger.debug("Spectrum thread initialized successfully.")
|
logger.debug("Spectrum thread initialized successfully.")
|
||||||
dsp.start()
|
|
||||||
if props["csdr_dynamic_bufsize"]:
|
def start(self):
|
||||||
dsp.read(8) #dummy read to skip bufsize & preamble
|
self.sdrSource.addClient(self)
|
||||||
logger.debug("Note: CSDR_DYNAMIC_BUFSIZE_ON = 1")
|
if self.sdrSource.isAvailable():
|
||||||
logger.debug("Spectrum thread started.")
|
self.dsp.start()
|
||||||
|
# TODO this does not work any more
|
||||||
|
'''
|
||||||
|
if props["csdr_dynamic_bufsize"]:
|
||||||
|
dsp.read(8) #dummy read to skip bufsize & preamble
|
||||||
|
logger.debug("Note: CSDR_DYNAMIC_BUFSIZE_ON = 1")
|
||||||
|
'''
|
||||||
|
|
||||||
def add_output(self, type, read_fn):
|
def add_output(self, type, read_fn):
|
||||||
if type != "audio":
|
if type != "audio":
|
||||||
@ -306,14 +310,17 @@ class SpectrumThread(csdr.output):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
|
self.sdrSource.removeClient(self)
|
||||||
|
|
||||||
|
def onSdrAvailable(self):
|
||||||
|
self.dsp.start()
|
||||||
|
def onSdrUnavailable(self):
|
||||||
|
self.dsp.stop()
|
||||||
|
|
||||||
class DspManager(csdr.output):
|
class DspManager(csdr.output):
|
||||||
def __init__(self, handler, sdrSource):
|
def __init__(self, handler, sdrSource):
|
||||||
self.doRun = False
|
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.sdrSource = sdrSource
|
self.sdrSource = sdrSource
|
||||||
self.dsp = None
|
|
||||||
self.sdrSource.addClient(self)
|
|
||||||
|
|
||||||
self.localProps = self.sdrSource.getProps().collect(
|
self.localProps = self.sdrSource.getProps().collect(
|
||||||
"audio_compression", "fft_compression", "digimodes_fft_size", "csdr_dynamic_bufsize",
|
"audio_compression", "fft_compression", "digimodes_fft_size", "csdr_dynamic_bufsize",
|
||||||
@ -371,11 +378,12 @@ class DspManager(csdr.output):
|
|||||||
|
|
||||||
self.localProps.getProperty("secondary_offset_freq").wire(self.dsp.set_secondary_offset_freq)
|
self.localProps.getProperty("secondary_offset_freq").wire(self.dsp.set_secondary_offset_freq)
|
||||||
|
|
||||||
|
self.sdrSource.addClient(self)
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.doRun = self.sdrSource.isAvailable()
|
if self.sdrSource.isAvailable():
|
||||||
if self.doRun:
|
|
||||||
self.dsp.start()
|
self.dsp.start()
|
||||||
|
|
||||||
def add_output(self, t, read_fn):
|
def add_output(self, t, read_fn):
|
||||||
@ -404,7 +412,6 @@ class DspManager(csdr.output):
|
|||||||
threading.Thread(target=pump(read_fn, write)).start()
|
threading.Thread(target=pump(read_fn, write)).start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.doRun = False
|
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
self.sdrSource.removeClient(self)
|
self.sdrSource.removeClient(self)
|
||||||
|
|
||||||
@ -413,15 +420,11 @@ class DspManager(csdr.output):
|
|||||||
|
|
||||||
def onSdrAvailable(self):
|
def onSdrAvailable(self):
|
||||||
logger.debug("received onSdrAvailable, attempting DspSource restart")
|
logger.debug("received onSdrAvailable, attempting DspSource restart")
|
||||||
if not self.doRun:
|
self.dsp.start()
|
||||||
self.doRun = True
|
|
||||||
if self.dsp is not None:
|
|
||||||
self.dsp.start()
|
|
||||||
|
|
||||||
def onSdrUnavailable(self):
|
def onSdrUnavailable(self):
|
||||||
logger.debug("received onSdrUnavailable, shutting down DspSource")
|
logger.debug("received onSdrUnavailable, shutting down DspSource")
|
||||||
if self.dsp is not None:
|
self.dsp.stop()
|
||||||
self.dsp.stop()
|
|
||||||
|
|
||||||
class CpuUsageThread(threading.Thread):
|
class CpuUsageThread(threading.Thread):
|
||||||
sharedInstance = None
|
sharedInstance = None
|
||||||
|
Loading…
Reference in New Issue
Block a user