diff --git a/apps/fft-multi-decoder_auto_freqs_slider-update.grc b/apps/fft-multi-decoder_auto_freqs_slider-update.grc index 675a38c..f10d783 100644 --- a/apps/fft-multi-decoder_auto_freqs_slider-update.grc +++ b/apps/fft-multi-decoder_auto_freqs_slider-update.grc @@ -3080,7 +3080,7 @@ class blk(gr.sync_block): # other base classes are basic_block, decim_block, in debug - False + True _enabled diff --git a/python/max_freq.py b/python/max_freq.py index 32ff34a..89bedbe 100644 --- a/python/max_freq.py +++ b/python/max_freq.py @@ -21,7 +21,7 @@ import numpy as np from gnuradio import gr -import code,math,pmt,time +import code,math,pmt,time,threading class max_freq(gr.sync_block): """ @@ -39,12 +39,13 @@ class max_freq(gr.sync_block): self.snapto=round_to self.debug=debug self.last_station_indices=[0]*self.num_decoders - self.message_port_register_out(pmt.intern('out')) - self.timer=time.time() - self.message_port_register_in(pmt.intern('ctrl')) - self.set_msg_handler(pmt.intern('ctrl'), self.handle_ctrl_msg) - self.searchMode=True - self.index_fixed=[False]*self.num_decoders + self.message_port_register_out(pmt.intern('out')) + self.timer=time.time() + self.message_port_register_in(pmt.intern('ctrl')) + self.set_msg_handler(pmt.intern('ctrl'), self.handle_ctrl_msg) + self.searchMode=True + self.index_fixed=[False]*self.num_decoders + self.search_thread=None def freq_to_index(self,freq): startfreq=self.center_freq-self.samp_rate/2 #freq=self.samp_rate*index/self.fft_len+startfreq @@ -61,26 +62,26 @@ class max_freq(gr.sync_block): try: m = pmt.pmt_to_python.pmt_to_dict(msg) if m.has_key("cmd") and m["cmd"]=="set_audio_freq": - #print(m) - #print(self.last_station_indices) - freq_index=self.freq_to_index(m["freq"]) - if m["chan"]=="left" and freq_index0:#add new stations to empty decoders - station_indices_tune[i]=new_stations.pop() - #print("tune2:%s"%station_indices_tune) + print("new_1:%s"%new_stations) + + for i,tune_freq in enumerate(station_indices_tune): + if tune_freq == 0 and len(new_stations)>0:#add new stations to empty decoders + station_indices_tune[i]=new_stations.pop() + #print("tune2:%s"%station_indices_tune) if self.debug: print("new_2:%s"%new_stations) @@ -216,19 +212,35 @@ class max_freq(gr.sync_block): station_freqs.append(round(freq,-num_decimals)) station_strength.append(round(numbers[index],-2)) for i in range(0,min(self.num_decoders,len(station_freqs))): - msg_string=str(i+1)+" "+str(station_freqs[i]) - send_pmt = pmt.string_to_symbol(msg_string) - self.message_port_pub(pmt.intern('out'), send_pmt) - if self.debug: - #print(max_indices) - #print(np.mean(numbers)) - #print(len(max_indices)) - #print(station_indices) - #print(station_indices_grouped) - #print(station_indices_sorted) - #print(station_indices_tune) - #print(station_strength) - print(station_freqs) + msg_string=str(i+1)+" "+str(station_freqs[i]) + send_pmt = pmt.string_to_symbol(msg_string) + self.message_port_pub(pmt.intern('out'), send_pmt) + if self.debug: + #print(max_indices) + #print(np.mean(numbers)) + #print(len(max_indices)) + #print(station_indices) + #print(station_indices_grouped) + #print(station_indices_sorted) + #print(station_indices_tune) + #print(station_strength) + print(station_freqs) + def work(self, input_items, output_items): + if time.time()-self.timer<2:#every 2 seconds + return len(input_items[0]) + elif self.searchMode: + inputvector=input_items[0] + if self.search_thread == None or self.search_thread.is_alive()==False: + if self.debug: + print("starting thread") + self.search_thread = threading.Thread(target=self.search, args=[inputvector], kwargs={}) + self.search_thread.start() + elif self.debug: + print("thread exists") + + #in0 = input_items[0] + #ii=input_items + return len(input_items[0]) else: diff --git a/python/tmc_classes.py b/python/tmc_classes.py index 71e62f5..fc9a8b4 100644 --- a/python/tmc_classes.py +++ b/python/tmc_classes.py @@ -40,7 +40,7 @@ from collections import namedtuple #Street(name='test', lcn=12) #Street(lcn=12,name="test").name import threading -#thr = threading.Thread(target=foo, args=(), kwargs={}) +#thr = threading.Thread(target=foo, args=(), kwargs={})#kwargs = keyword-arguments #thr.start() # will run "foo" #.... #thr.is_alive() # will return whether foo is running currently