From a15e6256924a2695c12944223d52cdf0a5df4786 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 28 Jul 2019 11:40:58 +0200 Subject: [PATCH] de-duplicate; better logging --- csdr.py | 25 +++++++++++++++++-------- owrx/service.py | 17 ++--------------- owrx/source.py | 15 +-------------- 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/csdr.py b/csdr.py index 54fd13c..197f62c 100644 --- a/csdr.py +++ b/csdr.py @@ -39,6 +39,18 @@ class output(object): def reset(self): pass + def pump(self, read, write): + def copy(): + run = True + while run: + data = read() + if data is None or (isinstance(data, bytes) and len(data) == 0): + run = False + else: + write(data) + + return copy + class dsp(object): def __init__(self, output): @@ -233,7 +245,7 @@ class dsp(object): def start_secondary_demodulator(self): if not self.secondary_demodulator: return - logger.debug("[openwebrx] starting secondary demodulator from IF input sampled at %d" % self.if_samp_rate()) + logger.debug("starting secondary demodulator from IF input sampled at %d" % self.if_samp_rate()) secondary_command_fft = self.secondary_chain("fft") secondary_command_demod = self.secondary_chain(self.secondary_demodulator) self.try_create_pipes(self.secondary_pipe_names, secondary_command_demod + secondary_command_fft) @@ -255,8 +267,8 @@ class dsp(object): last_decimation=self.last_decimation, ) - logger.debug("[openwebrx-dsp-plugin:csdr] secondary command (fft) = %s", secondary_command_fft) - logger.debug("[openwebrx-dsp-plugin:csdr] secondary command (demod) = %s", secondary_command_demod) + logger.debug("secondary command (fft) = %s", secondary_command_fft) + logger.debug("secondary command (demod) = %s", secondary_command_demod) my_env = os.environ.copy() # if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1"; if self.csdr_print_bufsizes: @@ -264,11 +276,9 @@ class dsp(object): self.secondary_process_fft = subprocess.Popen( secondary_command_fft, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env ) - logger.debug("[openwebrx-dsp-plugin:csdr] Popen on secondary command (fft)") self.secondary_process_demod = subprocess.Popen( secondary_command_demod, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env - ) # TODO digimodes - logger.debug("[openwebrx-dsp-plugin:csdr] Popen on secondary command (demod)") # TODO digimodes + ) self.secondary_processes_running = True self.output.add_output( @@ -500,7 +510,6 @@ class dsp(object): self.running = True command_base = " | ".join(self.chain(self.demodulator)) - logger.debug(command_base) # create control pipes for csdr self.pipe_base_path = "{tmp_dir}/openwebrx_pipe_{myid}_".format(tmp_dir=self.temporary_directory, myid=id(self)) @@ -533,7 +542,7 @@ class dsp(object): audio_rate=self.get_audio_rate(), ) - logger.debug("[openwebrx-dsp-plugin:csdr] Command = %s", command) + logger.debug("Command = %s", command) my_env = os.environ.copy() if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"] = "1" diff --git a/owrx/service.py b/owrx/service.py index 641ddb4..8c997e3 100644 --- a/owrx/service.py +++ b/owrx/service.py @@ -16,27 +16,14 @@ class ServiceOutput(output): def add_output(self, t, read_fn): logger.debug("got output of type {0}".format(t)) - def pump(read, write): - def copy(): - run = True - while run: - data = read() - if data is None or (isinstance(data, bytes) and len(data) == 0): - logger.warning("zero read on {0}".format(t)) - run = False - else: - write(data) - - return copy - if t == "wsjt_demod": parser = WsjtParser(WsjtHandler()) parser.setDialFrequency(self.frequency) - target = pump(read_fn, parser.parse) + target = self.pump(read_fn, parser.parse) else: # dump everything else # TODO rewrite the output mechanism in a way that avoids producing unnecessary data - target = pump(read_fn, lambda x: None) + target = self.pump(read_fn, lambda x: None) threading.Thread(target=target).start() diff --git a/owrx/source.py b/owrx/source.py index 99f29ec..3191cc2 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -515,20 +515,7 @@ class DspManager(csdr.output): } write = writers[t] - def pump(read, write): - def copy(): - run = True - while run: - data = read() - if data is None or (isinstance(data, bytes) and len(data) == 0): - logger.warning("zero read on {0}".format(t)) - run = False - else: - write(data) - - return copy - - threading.Thread(target=pump(read_fn, write)).start() + threading.Thread(target=self.pump(read_fn, write)).start() def stop(self): self.dsp.stop()