some quick nudges to allow reconfiguration of the rtl_sdr command on the fly
This commit is contained in:
parent
fa05249a9d
commit
9fc77c2804
20
csdr.py
20
csdr.py
@ -26,6 +26,7 @@ import os
|
|||||||
import code
|
import code
|
||||||
import signal
|
import signal
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import threading
|
||||||
|
|
||||||
class dsp:
|
class dsp:
|
||||||
|
|
||||||
@ -282,6 +283,8 @@ class dsp:
|
|||||||
return float(line[:-1])
|
return float(line[:-1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return 0
|
return 0
|
||||||
|
else:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def mkfifo(self,path):
|
def mkfifo(self,path):
|
||||||
try:
|
try:
|
||||||
@ -351,6 +354,15 @@ class dsp:
|
|||||||
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: my_env["CSDR_PRINT_BUFSIZES"]="1";
|
if self.csdr_print_bufsizes: my_env["CSDR_PRINT_BUFSIZES"]="1";
|
||||||
self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env)
|
self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env)
|
||||||
|
|
||||||
|
def watch_thread():
|
||||||
|
rc = self.process.wait()
|
||||||
|
print("dsp thread ended with rc={0}".format(rc))
|
||||||
|
if (self.running):
|
||||||
|
self.restart()
|
||||||
|
|
||||||
|
threading.Thread(target = watch_thread).start()
|
||||||
|
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
#open control pipes for csdr and send initialization data
|
#open control pipes for csdr and send initialization data
|
||||||
@ -372,7 +384,13 @@ class dsp:
|
|||||||
return self.process.stdout.read(size)
|
return self.process.stdout.read(size)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.running = False
|
||||||
|
if hasattr(self, "process"):
|
||||||
|
try:
|
||||||
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
|
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
|
||||||
|
except ProcessLookupError:
|
||||||
|
# been killed by something else, ignore
|
||||||
|
pass
|
||||||
self.stop_secondary_demodulator()
|
self.stop_secondary_demodulator()
|
||||||
#if(self.process.poll()!=None):return # returns None while subprocess is running
|
#if(self.process.poll()!=None):return # returns None while subprocess is running
|
||||||
#while(self.process.poll()==None):
|
#while(self.process.poll()==None):
|
||||||
@ -403,8 +421,6 @@ class dsp:
|
|||||||
# try: os.unlink(self.iqtee2_pipe)
|
# try: os.unlink(self.iqtee2_pipe)
|
||||||
# except: print "[openwebrx-dsp-plugin:csdr] stop() :: unlink failed: " + self.iqtee2_pipe
|
# except: print "[openwebrx-dsp-plugin:csdr] stop() :: unlink failed: " + self.iqtee2_pipe
|
||||||
|
|
||||||
self.running = False
|
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
self.start()
|
self.start()
|
||||||
|
@ -72,6 +72,7 @@ class WebSocketMessageHandler(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.handshake = None
|
self.handshake = None
|
||||||
self.client = None
|
self.client = None
|
||||||
|
self.dsp = None
|
||||||
|
|
||||||
def handleTextMessage(self, conn, message):
|
def handleTextMessage(self, conn, message):
|
||||||
pm = PropertyManager.getSharedInstance()
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
@ -126,11 +126,12 @@ class SpectrumThread(threading.Thread):
|
|||||||
while self.doRun:
|
while self.doRun:
|
||||||
data=dsp.read(bytes_to_read)
|
data=dsp.read(bytes_to_read)
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
self.shutdown()
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
for c in self.clients:
|
for c in self.clients:
|
||||||
c.write_spectrum_data(data)
|
c.write_spectrum_data(data)
|
||||||
|
|
||||||
|
dsp.stop()
|
||||||
print("spectrum thread shut down")
|
print("spectrum thread shut down")
|
||||||
|
|
||||||
def add_client(self, c):
|
def add_client(self, c):
|
||||||
|
Loading…
Reference in New Issue
Block a user