improve lock handling
This commit is contained in:
parent
c325368be8
commit
d36be799d0
37
csdr/csdr.py
37
csdr/csdr.py
@ -111,7 +111,11 @@ class dsp(object):
|
||||
self.unvoiced_quality = 1
|
||||
self.modification_lock = threading.Lock()
|
||||
self.output = output
|
||||
self.temporary_directory = "/tmp"
|
||||
|
||||
self.temporary_directory = None
|
||||
self.pipe_base_path = None
|
||||
self.set_temporary_directory("/tmp")
|
||||
|
||||
self.is_service = False
|
||||
self.direwolf_config = None
|
||||
self.direwolf_port = None
|
||||
@ -122,6 +126,7 @@ class dsp(object):
|
||||
|
||||
def set_temporary_directory(self, what):
|
||||
self.temporary_directory = what
|
||||
self.pipe_base_path = "{tmp_dir}/openwebrx_pipe_{myid}_".format(tmp_dir=self.temporary_directory, myid=id(self))
|
||||
|
||||
def chain(self, which):
|
||||
chain = ["nc -v 127.0.0.1 {nc_port}"]
|
||||
@ -528,21 +533,19 @@ class dsp(object):
|
||||
def set_offset_freq(self, offset_freq):
|
||||
self.offset_freq = offset_freq
|
||||
if self.running:
|
||||
self.modification_lock.acquire()
|
||||
with self.modification_lock:
|
||||
self.pipe_files["shift_pipe"].write("%g\n" % (-float(self.offset_freq) / self.samp_rate))
|
||||
self.pipe_files["shift_pipe"].flush()
|
||||
self.modification_lock.release()
|
||||
|
||||
def set_bpf(self, low_cut, high_cut):
|
||||
self.low_cut = low_cut
|
||||
self.high_cut = high_cut
|
||||
if self.running:
|
||||
self.modification_lock.acquire()
|
||||
with self.modification_lock:
|
||||
self.pipe_files["bpf_pipe"].write(
|
||||
"%g %g\n" % (float(self.low_cut) / self.if_samp_rate(), float(self.high_cut) / self.if_samp_rate())
|
||||
)
|
||||
self.pipe_files["bpf_pipe"].flush()
|
||||
self.modification_lock.release()
|
||||
|
||||
def get_bpf(self):
|
||||
return [self.low_cut, self.high_cut]
|
||||
@ -555,10 +558,9 @@ class dsp(object):
|
||||
# no squelch required on digital voice modes
|
||||
actual_squelch = -150 if self.isDigitalVoice() or self.isPacket() or self.isPocsag() else self.squelch_level
|
||||
if self.running:
|
||||
self.modification_lock.acquire()
|
||||
with self.modification_lock:
|
||||
self.pipe_files["squelch_pipe"].write("%g\n" % (self.convertToLinear(actual_squelch)))
|
||||
self.pipe_files["squelch_pipe"].flush()
|
||||
self.modification_lock.release()
|
||||
|
||||
def set_unvoiced_quality(self, q):
|
||||
self.unvoiced_quality = q
|
||||
@ -633,17 +635,14 @@ class dsp(object):
|
||||
self.direwolf_config = None
|
||||
|
||||
def start(self):
|
||||
self.modification_lock.acquire()
|
||||
with self.modification_lock:
|
||||
if self.running:
|
||||
self.modification_lock.release()
|
||||
return
|
||||
self.running = True
|
||||
|
||||
command_base = " | ".join(self.chain(self.demodulator))
|
||||
|
||||
# create control pipes for csdr
|
||||
self.pipe_base_path = "{tmp_dir}/openwebrx_pipe_{myid}_".format(tmp_dir=self.temporary_directory, myid=id(self))
|
||||
|
||||
self.try_create_pipes(self.pipe_names, command_base)
|
||||
|
||||
# run the command
|
||||
@ -700,13 +699,12 @@ class dsp(object):
|
||||
),
|
||||
)
|
||||
|
||||
# open control pipes for csdr
|
||||
for p in ["bpf_pipe", "shift_pipe", "squelch_pipe"]:
|
||||
if self.has_pipe(p):
|
||||
self.pipe_files[p] = open(self.pipes[p], "w")
|
||||
self.start_secondary_demodulator()
|
||||
|
||||
self.modification_lock.release()
|
||||
# open control pipes for csdr
|
||||
for p in ["bpf_pipe", "shift_pipe", "squelch_pipe", "dmr_control_pipe"]:
|
||||
if self.has_pipe(p):
|
||||
self.pipe_files[p] = open(self.pipes[p], "w")
|
||||
|
||||
# send initial config through the pipes
|
||||
if self.has_pipe("squelch_pipe"):
|
||||
@ -739,11 +737,8 @@ class dsp(object):
|
||||
|
||||
self.output.send_output("meta", read_meta)
|
||||
|
||||
if self.has_pipe("dmr_control_pipe"):
|
||||
self.pipe_files["dmr_control_pipe"] = open(self.pipes["dmr_control_pipe"], "w")
|
||||
|
||||
def stop(self):
|
||||
self.modification_lock.acquire()
|
||||
with self.modification_lock:
|
||||
self.running = False
|
||||
if self.process is not None:
|
||||
try:
|
||||
@ -756,8 +751,6 @@ class dsp(object):
|
||||
|
||||
self.try_delete_pipes(self.pipe_names)
|
||||
|
||||
self.modification_lock.release()
|
||||
|
||||
def restart(self):
|
||||
if not self.running:
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user