diff --git a/config_rtl.py b/config_rtl.py index c759978..99bc5b8 100755 --- a/config_rtl.py +++ b/config_rtl.py @@ -70,7 +70,7 @@ Example DSP commands: * Decompress FLAC-coded I/Q data: flac --force-raw-format --decode --endian=little --sign=unsigned - - ''' -watchdog_interval=1.5 +watchdog_interval=0 reconnect_interval=10 ''' If there's no input I/Q data after N seconds, input will be filled with zero samples, diff --git a/config_webrx.py b/config_webrx.py index 230e349..f4f3de5 100755 --- a/config_webrx.py +++ b/config_webrx.py @@ -53,7 +53,7 @@ center_freq = 145525000 rf_gain = 5 start_rtl_thread=True #rtl_sdr is more stable than rtl_tcp... -start_rtl_command="rtl_sdr -s {samp_rate} -f {center_freq} - | nc -vvl 127.0.0.1 -p 8888".format(rf_gain=rf_gain, center_freq=center_freq, samp_rate=samp_rate) +start_rtl_command="rtl_sdr -s {samp_rate} -f {center_freq} - | nc -vvl 127.0.0.1 -p 8888".format(rf_gain=rf_gain, center_freq=center_freq, samp_rate=samp_rate) #start_rtl_tcp_command="rtl_tcp -s 250000 -f 145525000 -g 0 -p 8888" #You can use other SDR hardware as well, but if the command above outputs samples in a format other than [unsigned char], then the dsp plugin has to be slightly modified (at the csdr convert_u8_f part). diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 3947f5d..b62ac66 100755 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1297,8 +1297,8 @@ var color_scale=[0x2e6893ff, 0x69a5d0ff, 0x214b69ff, 0x9dc4e0ff, 0xfff775ff, 0x function waterfall_mkcolor(db_value) { - min_value=-100; //in dB - max_value=10 + min_value=-115; //in dB + max_value=0 if(db_valuemax_value) db_value=max_value full_scale=max_value-min_value; diff --git a/openwebrx.py b/openwebrx.py index 37e09e4..1d7b44a 100755 --- a/openwebrx.py +++ b/openwebrx.py @@ -219,6 +219,7 @@ def generate_client_id(ip): new_client.spectrum_queue=Queue.Queue(1000) new_client.ip=ip new_client.closed=[False] #byref, not exactly sure if required + new_client.dsp=None clients_mutex.acquire() clients.append(new_client) log_client(new_client,"client added. Clients now: {0}".format(len(clients))) @@ -231,6 +232,12 @@ def close_client(i, use_mutex=True): global clients log_client(clients[i],"client being closed.") if use_mutex: clients_mutex.acquire() + try: + clients[i].dsp.stop() + except: + exc_type, exc_value, exc_traceback = sys.exc_info() + print "[openwebrx] close_client dsp.stop() :: error -",exc_type,exc_value + traceback.print_tb(exc_traceback) clients[i].closed[0]=True del clients[i] if use_mutex: clients_mutex.release() @@ -289,6 +296,7 @@ class WebRXHandler(BaseHTTPRequestHandler): dsp.set_offset_freq(0) dsp.set_bpf(-4000,4000) dsp.start() + myclient.dsp=dsp while True: if myclient.closed[0]: diff --git a/plugins/dsp/csdr/plugin.py b/plugins/dsp/csdr/plugin.py index 01e6eec..f2b0aac 100644 --- a/plugins/dsp/csdr/plugin.py +++ b/plugins/dsp/csdr/plugin.py @@ -2,6 +2,7 @@ import subprocess import time import os import code +import signal class dsp_plugin: @@ -26,7 +27,7 @@ class dsp_plugin: self.demodulator = "nfm" self.name = "csdr" try: - subprocess.Popen("nc",stdout=subprocess.PIPE,stderr=subprocess.PIPE) + subprocess.Popen("nc",stdout=subprocess.PIPE,stderr=subprocess.PIPE).kill() except: print "[openwebrx-plugin:csdr] error: netcat not found, please install netcat!" @@ -106,7 +107,7 @@ class dsp_plugin: command=command_base.format(bpf_pipe=self.bpf_pipe,shift_pipe=self.shift_pipe,decimation=self.decimation,last_decimation=self.last_decimation,fft_size=self.fft_size,fft_block_size=self.fft_block_size(),bpf_transition_bw=float(self.bpf_transition_bw)/self.if_samp_rate(),ddc_transition_bw=self.ddc_transition_bw()) print "[openwebrx-dsp-plugin:csdr] Command =",command #code.interact(local=locals()) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) + self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp) self.running = True #open control pipes for csdr and send initialization data @@ -121,10 +122,7 @@ class dsp_plugin: return self.process.stdout.read(size) def stop(self): - if(self.process!=None):return # returns None while subprocess is running - while(self.process.poll()==None): - self.process.kill() - time.sleep(0.1) + os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) os.unlink(self.bpf_pipe) os.unlink(self.shift_pipe) self.running = False diff --git a/rtl_mus.py b/rtl_mus.py index c244380..3193165 100644 --- a/rtl_mus.py +++ b/rtl_mus.py @@ -87,7 +87,7 @@ def add_data_to_clients(new_data): elif cfg.cache_full_behaviour == 1: #rather closing client: log.error("client cache full, dropping client: "+str(client[0].ident)+"@"+client[0].socket[1][0]) - client[0].close() + client[0].close(False) elif cfg.cache_full_behaviour == 2: pass #client cache full, just not taking care else: log.error("invalid value for cfg.cache_full_behaviour") @@ -131,6 +131,7 @@ class client_handler(asyncore.dispatcher): self.sent_dongle_id=False self.last_waiting_buffer="" asyncore.dispatcher.__init__(self, self.client[0].socket[0]) + self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) def handle_read(self): global commands @@ -174,6 +175,7 @@ class server_asyncore(asyncore.dispatcher): self.set_reuse_addr() self.bind((cfg.my_ip, cfg.my_listening_port)) self.listen(5) + self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) log.info("Server listening on port: "+str(cfg.my_listening_port)) def handle_accept(self): @@ -188,7 +190,7 @@ class server_asyncore(asyncore.dispatcher): my_client[0].ident=max_client_id max_client_id+=1 my_client[0].start_time=time.time() - my_client[0].waiting_data=multiprocessing.Queue(250) + my_client[0].waiting_data=multiprocessing.Queue(500) clients_mutex.acquire() clients.append(my_client) clients_mutex.release() @@ -278,9 +280,9 @@ class rtl_tcp_asyncore(asyncore.dispatcher): if(len(rtl_dongle_identifier)==0): rtl_dongle_identifier=self.recv(12) return - new_data_buffer=self.recv(16348) + new_data_buffer=self.recv(1024*16) if cfg.watchdog_interval: - watchdog_data_count+=16348 + watchdog_data_count+=1024*16 if cfg.use_dsp_command: dsp_input_queue.put(new_data_buffer) #print "did put anyway" @@ -418,11 +420,13 @@ class client: socket=None asyncore=None - def close(self): + def close(self, use_mutex=True): global clients_mutex global clients - clients_mutex.acquire() + if use_mutex: clients_mutex.acquire() + correction=0 for i in range(0,len(clients)): + i-=correction if clients[i][0].ident==self.ident: try: self.socket.close() @@ -433,8 +437,9 @@ class client: del self.asyncore except: pass - break - clients_mutex.release() + del clients[i] + correction+=1 + if use_mutex: clients_mutex.release() def main():