de-duplicate; better logging

This commit is contained in:
Jakob Ketterl 2019-07-28 11:40:58 +02:00
parent 7689e31640
commit a15e625692
3 changed files with 20 additions and 37 deletions

25
csdr.py
View File

@ -39,6 +39,18 @@ class output(object):
def reset(self): def reset(self):
pass 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): class dsp(object):
def __init__(self, output): def __init__(self, output):
@ -233,7 +245,7 @@ class dsp(object):
def start_secondary_demodulator(self): def start_secondary_demodulator(self):
if not self.secondary_demodulator: if not self.secondary_demodulator:
return 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_fft = self.secondary_chain("fft")
secondary_command_demod = self.secondary_chain(self.secondary_demodulator) secondary_command_demod = self.secondary_chain(self.secondary_demodulator)
self.try_create_pipes(self.secondary_pipe_names, secondary_command_demod + secondary_command_fft) 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, last_decimation=self.last_decimation,
) )
logger.debug("[openwebrx-dsp-plugin:csdr] secondary command (fft) = %s", secondary_command_fft) logger.debug("secondary command (fft) = %s", secondary_command_fft)
logger.debug("[openwebrx-dsp-plugin:csdr] secondary command (demod) = %s", secondary_command_demod) logger.debug("secondary command (demod) = %s", secondary_command_demod)
my_env = os.environ.copy() my_env = os.environ.copy()
# if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1"; # if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1";
if self.csdr_print_bufsizes: if self.csdr_print_bufsizes:
@ -264,11 +276,9 @@ class dsp(object):
self.secondary_process_fft = subprocess.Popen( self.secondary_process_fft = subprocess.Popen(
secondary_command_fft, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env 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( self.secondary_process_demod = subprocess.Popen(
secondary_command_demod, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env 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.secondary_processes_running = True
self.output.add_output( self.output.add_output(
@ -500,7 +510,6 @@ class dsp(object):
self.running = True self.running = True
command_base = " | ".join(self.chain(self.demodulator)) command_base = " | ".join(self.chain(self.demodulator))
logger.debug(command_base)
# create control pipes for csdr # create control pipes for csdr
self.pipe_base_path = "{tmp_dir}/openwebrx_pipe_{myid}_".format(tmp_dir=self.temporary_directory, myid=id(self)) 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(), 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() my_env = os.environ.copy()
if self.csdr_dynamic_bufsize: if self.csdr_dynamic_bufsize:
my_env["CSDR_DYNAMIC_BUFSIZE_ON"] = "1" my_env["CSDR_DYNAMIC_BUFSIZE_ON"] = "1"

View File

@ -16,27 +16,14 @@ class ServiceOutput(output):
def add_output(self, t, read_fn): def add_output(self, t, read_fn):
logger.debug("got output of type {0}".format(t)) 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": if t == "wsjt_demod":
parser = WsjtParser(WsjtHandler()) parser = WsjtParser(WsjtHandler())
parser.setDialFrequency(self.frequency) parser.setDialFrequency(self.frequency)
target = pump(read_fn, parser.parse) target = self.pump(read_fn, parser.parse)
else: else:
# dump everything else # dump everything else
# TODO rewrite the output mechanism in a way that avoids producing unnecessary data # 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() threading.Thread(target=target).start()

View File

@ -515,20 +515,7 @@ class DspManager(csdr.output):
} }
write = writers[t] write = writers[t]
def pump(read, write): threading.Thread(target=self.pump(read_fn, write)).start()
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()
def stop(self): def stop(self):
self.dsp.stop() self.dsp.stop()