diff --git a/csdr.py b/csdr.py index 2d0d310..b9fc6a0 100755 --- a/csdr.py +++ b/csdr.py @@ -93,7 +93,7 @@ class dsp: return secondary_chain_base+"csdr realpart_cf | csdr fft_fc {secondary_fft_input_size} {secondary_fft_block_size} | csdr logpower_cf -70 " + (" | csdr compress_fft_adpcm_f_u8 {secondary_fft_size}" if self.fft_compression=="adpcm" else "") elif which == "bpsk31": return secondary_chain_base + "csdr shift_addition_cc --fifo {secondary_shift_pipe} | " + \ - "csdr bandpass_fir_fft_cc $(csdr '=-(31.25)/{if_samp_rate}') $(csdr '=(31.25)/{if_samp_rate}') $(csdr '=31.25/{if_samp_rate}') | " + \ + "csdr bandpass_fir_fft_cc -{secondary_bpf_cutoff} {secondary_bpf_cutoff} {secondary_bpf_cutoff} | " + \ "csdr simple_agc_cc 0.001 0.5 | " + \ "csdr timing_recovery_cc GARDNER {secondary_samples_per_bits} 0.5 2 --add_q | " + \ "CSDR_FIXED_BUFSIZE=1 csdr dbpsk_decoder_c_u8 | " + \ @@ -110,12 +110,12 @@ class dsp: def secondary_bpf_cutoff(self): if self.secondary_demodulator == "bpsk31": - return (31.25/2) / self.if_samp_rate() + return 31.25 / self.if_samp_rate() return 0 def secondary_bpf_transition_bw(self): if self.secondary_demodulator == "bpsk31": - return (31.25/2) / self.if_samp_rate() + return 31.25 / self.if_samp_rate() return 0 def secondary_samples_per_bits(self): @@ -171,9 +171,6 @@ class dsp: self.set_secondary_offset_freq(self.secondary_offset_freq) #TODO digimodes # print "==========> 4" - self.set_pipe_nonblocking(self.secondary_process_demod.stdout) - self.set_pipe_nonblocking(self.secondary_process_fft.stdout) - def set_secondary_offset_freq(self, value): self.secondary_offset_freq=value if self.secondary_processes_running: @@ -286,7 +283,10 @@ class dsp: def get_smeter_level(self): if self.running: line=self.smeter_pipe_file.readline() - return float(line[:-1]) + try: + return float(line[:-1]) + except ValueError: + return 0 def mkfifo(self,path): try: @@ -315,10 +315,6 @@ class dsp: try: os.unlink(pipe_path) except Exception as e: print("[openwebrx-dsp-plugin:csdr] try_delete_pipes() ::", e) - def set_pipe_nonblocking(self, pipe): - flags = fcntl.fcntl(pipe, fcntl.F_GETFL) - fcntl.fcntl(pipe, fcntl.F_SETFL, flags | os.O_NONBLOCK) - def start(self): command_base=self.chain(self.demodulator) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index be3a143..f3ed329 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1182,6 +1182,12 @@ function on_ws_recv(evt) waterfall_init(); audio_preinit(); break; + case "secondary_config": + window.secondary_fft_size = json.value.secondary_fft_size; + window.secondary_bw = json.value.secondary_bw; + window.if_samp_rate = json.value.if_samp_rate; + secondary_demod_init_canvases(); + break; case "receiver_details": var r = json.value; e('webrx-rx-title').innerHTML = r.receiver_name; @@ -1236,6 +1242,23 @@ function on_ws_recv(evt) audio_buffer_all_size_debug += audio_data.length; if (!(ios||is_chrome) && (audio_initialized==0 && audio_prepared_buffers.length>audio_buffering_fill_to)) audio_init() break; + case 3: + // secondary FFT + if (fft_compression == "none") { + secondary_demod_waterfall_add_queue(new Float32Array(data)); + } else if (fft_compression == "adpcm") { + fft_codec.reset(); + + var waterfall_i16=fft_codec.decode(new Uint8Array(data)); + var waterfall_f32=new Float32Array(waterfall_i16.length-COMPRESS_FFT_PAD_N); + for(var i=0;i= fft_fps: - spectrum_thread_counter=0 - else: spectrum_thread_counter+=1 for c in self.clients: c.write_spectrum_data(data) @@ -138,15 +136,24 @@ class DspManager(object): if (pm.getPropertyValue("digimodes_enable")): def set_secondary_mod(mod): + self.stopSecondaryThreads() self.dsp.stop() if mod == False: self.dsp.set_secondary_demodulator(None) else: self.dsp.set_secondary_demodulator(mod) + self.handler.write_secondary_dsp_config({ + "secondary_fft_size":pm.getPropertyValue("digimodes_fft_size"), + "if_samp_rate":self.dsp.if_samp_rate(), + "secondary_bw":self.dsp.secondary_bw() + }) # TODO frontend will probably miss this #rxws.send(self, "MSG secondary_fft_size={0} if_samp_rate={1} secondary_bw={2} secondary_setup".format(cfg.digimodes_fft_size, dsp.if_samp_rate(), dsp.secondary_bw())) self.dsp.start() + if mod: + self.startSecondaryThreads() + self.localProps.getProperty("secondary_mod").wire(set_secondary_mod) self.localProps.getProperty("secondary_offset_freq").wire(self.dsp.set_secondary_offset_freq) @@ -158,6 +165,18 @@ class DspManager(object): threading.Thread(target = self.readDspOutput).start() threading.Thread(target = self.readSMeterOutput).start() + def startSecondaryThreads(self): + self.runSecondary = True + self.secondaryDemodThread = threading.Thread(target = self.readSecondaryDemod) + self.secondaryDemodThread.start() + self.secondaryFftThread = threading.Thread(target = self.readSecondaryFft) + self.secondaryFftThread.start() + + def stopSecondaryThreads(self): + self.runSecondary = False + self.secondaryDemodThread = None + self.secondaryFftThread = None + def readDspOutput(self): while (self.doRun): data = self.dsp.read(256) @@ -168,6 +187,16 @@ class DspManager(object): level = self.dsp.get_smeter_level() self.handler.write_s_meter_level(level) + def readSecondaryDemod(self): + while (self.runSecondary): + data = self.dsp.read_secondary_demod(1) + self.handler.write_secondary_demod(data) + + def readSecondaryFft(self): + while (self.runSecondary): + data = self.dsp.read_secondary_fft(int(self.dsp.get_secondary_fft_bytes_to_read())) + self.handler.write_secondary_fft(data) + def stop(self): self.doRun = False self.dsp.stop() diff --git a/server.py b/server.py index 436983f..d8530cf 100644 --- a/server.py +++ b/server.py @@ -30,7 +30,8 @@ def main(): print(e) return - RtlNmuxSource() + if (pm.getPropertyValue("start_rtl_thread")): + RtlNmuxSource().start() server = ThreadedHttpServer(('0.0.0.0', pm.getPropertyValue("web_port")), RequestHandler) server.serve_forever()