def __init__(self, parent, size=histo_window.DEFAULT_WIN_SIZE, title="", num_bins=11, frame_size=1000): # init gr.hier_block2.__init__(self, "histo_sink", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) # blocks msgq = gr.msg_queue(2) histo = gr.histo_sink_f(msgq) histo.set_num_bins(num_bins) histo.set_frame_size(frame_size) # connect self.connect(self, histo) # controller self.controller = pubsub() self.controller.subscribe(NUM_BINS_KEY, histo.set_num_bins) self.controller.publish(NUM_BINS_KEY, histo.get_num_bins) self.controller.subscribe(FRAME_SIZE_KEY, histo.set_frame_size) self.controller.publish(FRAME_SIZE_KEY, histo.get_frame_size) # start input watcher common.input_watcher(msgq, self.controller, MSG_KEY, arg1_key=MINIMUM_KEY, arg2_key=MAXIMUM_KEY) # create window self.win = histo_window.histo_window( parent=parent, controller=self.controller, size=size, title=title, maximum_key=MAXIMUM_KEY, minimum_key=MINIMUM_KEY, num_bins_key=NUM_BINS_KEY, frame_size_key=FRAME_SIZE_KEY, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win)
def __init__(self, args=None): self.args = args if args: self.simulate = args.simulate self.time_dilution = args.time_dilution if self.simulate else 1 else: self.simulate = False self.time_dilution = 1 self.real_interval = constants.dispatch_interval / self.time_dilution \ if self.time_dilution>0 else 0 self.my_class = "dispatcher" self.name = "single" self.tick_subs = pubsub() self.one_second_subs = pubsub() self.ten_second_subs = pubsub() self.stopping = False stop_server.listen(self._stop) dispatcher.the_dispatcher = self
class stop_server(object) : my_pubsub = pubsub() @staticmethod def listen(fn, *args) : stop_server.my_pubsub.listen(fn, *args) @staticmethod def stop() : stop_server.my_pubsub.signal()
def __init__(self) : self.last_message = 0 self.lost_messages = 0 self.bad_messages = 0 self.good_messages = 0 self.my_pubsub = pubsub() self.last_trigger = None self.my_class = "sensor_listener" self.prev_values = None sensor_listener.listeners[self.name] = self dispatcher.add_tick_client(self.tick)
def __init__(self, name, **args): self.name = name try: int(name) except ValueError: raise ValueError("sensor names must be numeric, not '%s'" % (name, )) self.last_triggered = None self.my_pubsub = pubsub() self.my_class = "sensor" self.active = False self.owner = None self.last_triggered = 0 sensor.sensors[name] = self dispatcher.add_tick_client(self.tick)
def __init__( self, parent, size=histo_window.DEFAULT_WIN_SIZE, title='', num_bins=11, frame_size=1000, ): #init gr.hier_block2.__init__( self, "histo_sink", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0), ) #blocks msgq = gr.msg_queue(2) histo = wxgui.histo_sink_f(msgq) histo.set_num_bins(num_bins) histo.set_frame_size(frame_size) #controller self.controller = pubsub() self.controller.subscribe(NUM_BINS_KEY, histo.set_num_bins) self.controller.publish(NUM_BINS_KEY, histo.get_num_bins) self.controller.subscribe(FRAME_SIZE_KEY, histo.set_frame_size) self.controller.publish(FRAME_SIZE_KEY, histo.get_frame_size) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY, arg1_key=MINIMUM_KEY, arg2_key=MAXIMUM_KEY) #create window self.win = histo_window.histo_window( parent=parent, controller=self.controller, size=size, title=title, maximum_key=MAXIMUM_KEY, minimum_key=MINIMUM_KEY, num_bins_key=NUM_BINS_KEY, frame_size_key=FRAME_SIZE_KEY, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win) #connect self.wxgui_connect(self, histo)
def __init__( self, parent, title='', sample_rate=1, size=scope_window.DEFAULT_WIN_SIZE, v_scale=0, t_scale=0, v_offset=0, xy_mode=False, ac_couple=False, num_inputs=1, trig_mode=scope_window.DEFAULT_TRIG_MODE, y_axis_label='Counts', frame_rate=scope_window.DEFAULT_FRAME_RATE, use_persistence=False, persist_alpha=None, **kwargs #do not end with a comma ): #ensure analog alpha if persist_alpha is None: actual_frame_rate = float(frame_rate) analog_cutoff_freq = 0.5 # Hertz #calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp( -2.0 * math.pi * analog_cutoff_freq / actual_frame_rate) if not t_scale: t_scale = 10.0 / sample_rate #init gr.hier_block2.__init__( self, "scope_sink", gr.io_signature(num_inputs, num_inputs, self._item_size), gr.io_signature(0, 0, 0), ) #scope msgq = gr.msg_queue(2) scope = gr.oscope_sink_f(sample_rate, msgq) #controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, scope.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate) self.controller.subscribe(DECIMATION_KEY, scope.set_decimation_count) self.controller.publish(DECIMATION_KEY, scope.get_decimation_count) self.controller.subscribe(TRIGGER_LEVEL_KEY, scope.set_trigger_level) self.controller.publish(TRIGGER_LEVEL_KEY, scope.get_trigger_level) self.controller.subscribe(TRIGGER_MODE_KEY, scope.set_trigger_mode) self.controller.publish(TRIGGER_MODE_KEY, scope.get_trigger_mode) self.controller.subscribe(TRIGGER_SLOPE_KEY, scope.set_trigger_slope) self.controller.publish(TRIGGER_SLOPE_KEY, scope.get_trigger_slope) self.controller.subscribe(TRIGGER_CHANNEL_KEY, scope.set_trigger_channel) self.controller.publish(TRIGGER_CHANNEL_KEY, scope.get_trigger_channel) actual_num_inputs = self._real and num_inputs or num_inputs * 2 #init ac couple for i in range(actual_num_inputs): self.controller[common.index_key(AC_COUPLE_KEY, i)] = ac_couple #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = scope_window.scope_window( parent=parent, controller=self.controller, size=size, title=title, frame_rate=frame_rate, num_inputs=actual_num_inputs, sample_rate_key=SAMPLE_RATE_KEY, t_scale=t_scale, v_scale=v_scale, v_offset=v_offset, xy_mode=xy_mode, trig_mode=trig_mode, y_axis_label=y_axis_label, ac_couple_key=AC_COUPLE_KEY, trigger_level_key=TRIGGER_LEVEL_KEY, trigger_mode_key=TRIGGER_MODE_KEY, trigger_slope_key=TRIGGER_SLOPE_KEY, trigger_channel_key=TRIGGER_CHANNEL_KEY, decimation_key=DECIMATION_KEY, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, ) common.register_access_methods(self, self.win) #connect if self._real: for i in range(num_inputs): self.wxgui_connect( (self, i), ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, i), SAMPLE_RATE_KEY), (scope, i), ) else: for i in range(num_inputs): c2f = gr.complex_to_float() self.wxgui_connect((self, i), c2f) for j in range(2): self.connect( (c2f, j), ac_couple_block( self.controller, common.index_key(AC_COUPLE_KEY, 2 * i + j), SAMPLE_RATE_KEY), (scope, 2 * i + j), )
def __init__( self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=fft_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title="", size=fft_window.DEFAULT_WIN_SIZE, peak_hold=False, win=None, use_persistence=False, persist_alpha=None, **kwargs # do not end with a comma ): # ensure avg alpha if avg_alpha is None: avg_alpha = 2.0 / fft_rate # ensure analog alpha if persist_alpha is None: actual_fft_rate = float(sample_rate / fft_size) / float( max(1, int(float((sample_rate / fft_size) / fft_rate))) ) # print "requested_fft_rate ",fft_rate # print "actual_fft_rate ",actual_fft_rate analog_cutoff_freq = 0.5 # Hertz # calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp(-2.0 * math.pi * analog_cutoff_freq / actual_fft_rate) # init gr.hier_block2.__init__(self, "fft_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0)) # blocks fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = gr.message_sink(gr.sizeof_float * fft_size, msgq, True) # controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, fft.set_average) self.controller.publish(AVERAGE_KEY, fft.average) self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate) # start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) # create window self.win = fft_window.fft_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, baseband_freq=baseband_freq, sample_rate_key=SAMPLE_RATE_KEY, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, ) common.register_access_methods(self, self.win) setattr(self.win, "set_baseband_freq", getattr(self, "set_baseband_freq")) # BACKWARDS setattr(self.win, "set_peak_hold", getattr(self, "set_peak_hold")) # BACKWARDS # connect self.wxgui_connect(self, fft, sink)
def __init__( self, parent, baseband_freq=0, ref_level=50, sample_rate=1, fft_size=512, fft_rate=waterfall_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=waterfall_window.DEFAULT_WIN_SIZE, ref_scale=2.0, dynamic_range=80, num_lines=256, win=None, **kwargs #do not end with a comma ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0 / fft_rate #init gr.hier_block2.__init__( self, "waterfall_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = blocks.message_sink(gr.sizeof_float * fft_size, msgq, True) #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, fft.set_average) self.controller.publish(AVERAGE_KEY, fft.average) self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate) self.controller.subscribe(DECIMATION_KEY, fft.set_decimation) self.controller.publish(DECIMATION_KEY, fft.decimation) self.controller.subscribe(FRAME_RATE_KEY, fft.set_vec_rate) self.controller.publish(FRAME_RATE_KEY, fft.frame_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = waterfall_window.waterfall_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, num_lines=num_lines, baseband_freq=baseband_freq, decimation_key=DECIMATION_KEY, sample_rate_key=SAMPLE_RATE_KEY, frame_rate_key=FRAME_RATE_KEY, dynamic_range=dynamic_range, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS #connect self.wxgui_connect(self, fft, sink)
def __init__( self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=fft_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=fft_window.DEFAULT_WIN_SIZE, peak_hold=False, win=None, **kwargs #do not end with a comma ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/fft_rate #init gr.hier_block2.__init__( self, "fft_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = gr.message_sink(gr.sizeof_float*fft_size, msgq, True) #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, fft.set_average) self.controller.publish(AVERAGE_KEY, fft.average) self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = fft_window.fft_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, baseband_freq=baseband_freq, sample_rate_key=SAMPLE_RATE_KEY, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS #connect self.wxgui_connect(self, fft, sink)
def __init__( self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=fft_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=fft_window.DEFAULT_WIN_SIZE, peak_hold=False, analog_sig_source = None, blocks_throttle = None, win=None, use_persistence=False, persist_alpha=None, functionCallbackWhenHandleMessageSink = None, **kwargs #do not end with a comma ): if functionCallbackWhenHandleMessageSink is None: print 'function callback is null' functionCallbackWhenHandleMessageSink = self.defaultHandleMessageCallback #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/fft_rate #ensure analog alpha if persist_alpha is None: actual_fft_rate=float(sample_rate/fft_size)/float(max(1,int(float((sample_rate/fft_size)/fft_rate)))) #print "requested_fft_rate ",fft_rate #print "actual_fft_rate ",actual_fft_rate analog_cutoff_freq=0.5 # Hertz #calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_fft_rate) #init gr.hier_block2.__init__( self, "fft_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = blocks.message_sink(gr.sizeof_float*fft_size, msgq, True) analog_sig_source_fromconstructor = analog_sig_source blocks_throttle_fromconstructor = blocks_throttle #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, fft.set_average) self.controller.publish(AVERAGE_KEY, fft.average) self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = fft_window.fft_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, baseband_freq=baseband_freq, sample_rate_key=SAMPLE_RATE_KEY, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, functionCallbackWhenHandleMessage = functionCallbackWhenHandleMessageSink, analog_sig_source = analog_sig_source_fromconstructor, blocks_throttle = blocks_throttle_fromconstructor ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS #connect self.wxgui_connect(self, fft, sink)
def __init__( self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=fft_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=fft_window.DEFAULT_WIN_SIZE, peak_hold=False, win=None, use_persistence=False, persist_alpha=None, **kwargs #do not end with a comma ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/fft_rate #ensure analog alpha if persist_alpha is None: actual_fft_rate=float(sample_rate/fft_size)/float(max(1,int(float((sample_rate/fft_size)/fft_rate)))) #print "requested_fft_rate ",fft_rate #print "actual_fft_rate ",actual_fft_rate analog_cutoff_freq=0.5 # Hertz #calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_fft_rate) #init gr.hier_block2.__init__( self, "fft_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) self.integrating = integrating = 0 #blocks self.fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = blocks.message_sink(gr.sizeof_float*fft_size, msgq, True) # For graphical display only self._log=self.fft.get_log() # For saving data (integration) int_filename="integration_data2.txt" self.vect2str= blocks.vector_to_stream(gr.sizeof_float*1, fft_size) self.integrate = blocks.integrate_ff(fft_size, 1) self.file_sink_int= blocks.file_sink(gr.sizeof_float*1, int_filename, False) #controls data streaming #self.integrating=1 #if the valve is open (1) or closed (0). Open valve stops data #self._valve = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(self.integrating)) # self.selec = grc_blks2.selector( #item_size=gr.sizeof_float*1, # num_inputs=2, # num_outputs=2, # input_index=integrating, # output_index=integrating, #) #just for not leave ports disconnected #self.null_source = blocks.null_source(gr.sizeof_float*1) #self.null_sink = blocks.null_sink(gr.sizeof_float*1) #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, self.fft.set_average) self.controller.publish(AVERAGE_KEY, self.fft.average) self.controller.subscribe(AVG_ALPHA_KEY, self.fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, self.fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, self.fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, self.fft.sample_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = fft_window.fft_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, baseband_freq=baseband_freq, sample_rate_key=SAMPLE_RATE_KEY, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS #connect self.wxgui_connect(self,self.fft, self._log, sink)# GUI #Save data #self.connect(self.null_source,(self.selec,0))#selector is in ports 0 by default #self.connect((self.selec,0),self.null_sink) #self.connect(self.fft, self.vect2str, self.integrate, (self.selec,1)) #port 1 os select is to save data #self.connect((self.selec,1), self.file_sink_int)#SAVE DATA self.connect(self.fft, self.vect2str, self.integrate, self.file_sink_int)
def __init__( self, parent, title='', sample_rate=1, size=const_window.DEFAULT_WIN_SIZE, frame_rate=const_window.DEFAULT_FRAME_RATE, const_size=const_window.DEFAULT_CONST_SIZE, #mpsk recv params M=4, theta=0, loop_bw=6.28/100.0, fmax=0.06, mu=0.5, gain_mu=0.005, symbol_rate=1, omega_limit=0.005, ): #init gr.hier_block2.__init__( self, "const_sink", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0), ) #blocks sd = blks2.stream_to_vector_decimator( item_size=gr.sizeof_gr_complex, sample_rate=sample_rate, vec_rate=frame_rate, vec_len=const_size, ) fmin = -fmax gain_omega = .25*gain_mu**2 #redundant, will be updated omega = 1 #set_sample_rate will update this # Costas frequency/phase recovery loop # Critically damped 2nd order PLL self._costas = digital.costas_loop_cc(loop_bw, M) # Timing recovery loop # Critically damped 2nd order DLL self._retime = digital.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_limit) #sync = gr.mpsk_receiver_cc( # M, #psk order # theta, # alpha, # beta, # fmin, # fmax, # mu, # gain_mu, # omega, # gain_omega, # omega_limit, #) agc = gr.feedforward_agc_cc(16, 1) msgq = gr.msg_queue(2) sink = gr.message_sink(gr.sizeof_gr_complex*const_size, msgq, True) #controller def setter(p, k, x): p[k] = x self.controller = pubsub() self.controller.subscribe(LOOP_BW_KEY, self._costas.set_loop_bandwidth) self.controller.publish(LOOP_BW_KEY, self._costas.get_loop_bandwidth) self.controller.subscribe(GAIN_MU_KEY, self._retime.set_gain_mu) self.controller.publish(GAIN_MU_KEY, self._retime.gain_mu) self.controller.subscribe(OMEGA_KEY, self._retime.set_omega) self.controller.publish(OMEGA_KEY, self._retime.omega) self.controller.subscribe(GAIN_OMEGA_KEY, self._retime.set_gain_omega) self.controller.publish(GAIN_OMEGA_KEY, self._retime.gain_omega) self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate) self.controller.subscribe(SAMPLE_RATE_KEY, lambda x: setter(self.controller, OMEGA_KEY, float(x)/symbol_rate)) self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate) #initial update self.controller[SAMPLE_RATE_KEY] = sample_rate #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = const_window.const_window( parent=parent, controller=self.controller, size=size, title=title, msg_key=MSG_KEY, loop_bw_key=LOOP_BW_KEY, gain_mu_key=GAIN_MU_KEY, gain_omega_key=GAIN_OMEGA_KEY, omega_key=OMEGA_KEY, sample_rate_key=SAMPLE_RATE_KEY, ) common.register_access_methods(self, self.win) #connect self.wxgui_connect(self, self._costas, self._retime, agc, sd, sink)
def __init__( self, parent, unit="units", minval=0, maxval=1, factor=1, decimal_places=3, ref_level=0, sample_rate=1, number_rate=number_window.DEFAULT_NUMBER_RATE, average=False, avg_alpha=None, label="Number Plot", size=number_window.DEFAULT_WIN_SIZE, peak_hold=False, show_gauge=True, **kwargs # catchall for backwards compatibility ): # ensure avg alpha if avg_alpha is None: avg_alpha = 2.0 / number_rate # init gr.hier_block2.__init__(self, "number_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0)) # blocks sd = blks2.stream_to_vector_decimator( item_size=self._item_size, sample_rate=sample_rate, vec_rate=number_rate, vec_len=1 ) if self._real: mult = gr.multiply_const_ff(factor) add = gr.add_const_ff(ref_level) avg = gr.single_pole_iir_filter_ff(1.0) else: mult = gr.multiply_const_cc(factor) add = gr.add_const_cc(ref_level) avg = gr.single_pole_iir_filter_cc(1.0) msgq = gr.msg_queue(2) sink = gr.message_sink(self._item_size, msgq, True) # controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate) self.controller[AVERAGE_KEY] = average self.controller[AVG_ALPHA_KEY] = avg_alpha def update_avg(*args): if self.controller[AVERAGE_KEY]: avg.set_taps(self.controller[AVG_ALPHA_KEY]) else: avg.set_taps(1.0) update_avg() self.controller.subscribe(AVERAGE_KEY, update_avg) self.controller.subscribe(AVG_ALPHA_KEY, update_avg) # start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) # create window self.win = number_window.number_window( parent=parent, controller=self.controller, size=size, title=label, units=unit, real=self._real, minval=minval, maxval=maxval, decimal_places=decimal_places, show_gauge=show_gauge, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, sample_rate_key=SAMPLE_RATE_KEY, ) common.register_access_methods(self, self.controller) # backwards compadibility self.set_show_gauge = self.win.show_gauges # connect self.wxgui_connect(self, sd, mult, add, avg, sink)
def __init__( self, parent, title='', sample_rate=1, size=scope_window.DEFAULT_WIN_SIZE, v_scale=0, t_scale=0, xy_mode=False, ac_couple=False, num_inputs=1, frame_rate=scope_window.DEFAULT_FRAME_RATE, **kwargs #do not end with a comma ): if not t_scale: t_scale = 10.0/sample_rate #init gr.hier_block2.__init__( self, "scope_sink", gr.io_signature(num_inputs, num_inputs, self._item_size), gr.io_signature(0, 0, 0), ) #scope msgq = gr.msg_queue(2) scope = gr.oscope_sink_f(sample_rate, msgq) #controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, scope.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate) self.controller.subscribe(DECIMATION_KEY, scope.set_decimation_count) self.controller.publish(DECIMATION_KEY, scope.get_decimation_count) self.controller.subscribe(TRIGGER_LEVEL_KEY, scope.set_trigger_level) self.controller.publish(TRIGGER_LEVEL_KEY, scope.get_trigger_level) self.controller.subscribe(TRIGGER_MODE_KEY, scope.set_trigger_mode) self.controller.publish(TRIGGER_MODE_KEY, scope.get_trigger_mode) self.controller.subscribe(TRIGGER_SLOPE_KEY, scope.set_trigger_slope) self.controller.publish(TRIGGER_SLOPE_KEY, scope.get_trigger_slope) self.controller.subscribe(TRIGGER_CHANNEL_KEY, scope.set_trigger_channel) self.controller.publish(TRIGGER_CHANNEL_KEY, scope.get_trigger_channel) #connect if self._real: for i in range(num_inputs): self.connect( (self, i), ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, i), ac_couple, SAMPLE_RATE_KEY), (scope, i), ) else: for i in range(num_inputs): c2f = gr.complex_to_float() self.connect((self, i), c2f) for j in range(2): self.connect( (c2f, j), ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, 2*i+j), ac_couple, SAMPLE_RATE_KEY), (scope, 2*i+j), ) num_inputs *= 2 #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = scope_window.scope_window( parent=parent, controller=self.controller, size=size, title=title, frame_rate=frame_rate, num_inputs=num_inputs, sample_rate_key=SAMPLE_RATE_KEY, t_scale=t_scale, v_scale=v_scale, xy_mode=xy_mode, ac_couple_key=AC_COUPLE_KEY, trigger_level_key=TRIGGER_LEVEL_KEY, trigger_mode_key=TRIGGER_MODE_KEY, trigger_slope_key=TRIGGER_SLOPE_KEY, trigger_channel_key=TRIGGER_CHANNEL_KEY, decimation_key=DECIMATION_KEY, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win)
def __init__( self, parent, unit='units', minval=0, maxval=1, factor=1, decimal_places=3, ref_level=0, sample_rate=1, number_rate=number_window.DEFAULT_NUMBER_RATE, average=False, avg_alpha=None, label='Number Plot', size=number_window.DEFAULT_WIN_SIZE, peak_hold=False, show_gauge=True, **kwargs #catchall for backwards compatibility ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0 / number_rate #init gr.hier_block2.__init__( self, "number_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks sd = blocks.stream_to_vector_decimator( item_size=self._item_size, sample_rate=sample_rate, vec_rate=number_rate, vec_len=1, ) if self._real: mult = blocks.multiply_const_ff(factor) add = blocks.add_const_ff(ref_level) avg = filter.single_pole_iir_filter_ff(1.0) else: mult = blocks.multiply_const_cc(factor) add = blocks.add_const_cc(ref_level) avg = filter.single_pole_iir_filter_cc(1.0) msgq = gr.msg_queue(2) sink = blocks.message_sink(self._item_size, msgq, True) #controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate) self.controller[AVERAGE_KEY] = average self.controller[AVG_ALPHA_KEY] = avg_alpha def update_avg(*args): if self.controller[AVERAGE_KEY]: avg.set_taps(self.controller[AVG_ALPHA_KEY]) else: avg.set_taps(1.0) update_avg() self.controller.subscribe(AVERAGE_KEY, update_avg) self.controller.subscribe(AVG_ALPHA_KEY, update_avg) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = number_window.number_window( parent=parent, controller=self.controller, size=size, title=label, units=unit, real=self._real, minval=minval, maxval=maxval, decimal_places=decimal_places, show_gauge=show_gauge, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, sample_rate_key=SAMPLE_RATE_KEY, ) common.register_access_methods(self, self.controller) #backwards compadibility self.set_show_gauge = self.win.show_gauges #connect self.wxgui_connect(self, sd, mult, add, avg, sink)
def __init__( self, parent, baseband_freq=0, ref_level=50, sample_rate=1, fft_size=512, fft_rate=waterfall_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=waterfall_window.DEFAULT_WIN_SIZE, ref_scale=2.0, dynamic_range=80, num_lines=256, **kwargs #do not end with a comma ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/fft_rate #init gr.hier_block2.__init__( self, "waterfall_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, ) msgq = gr.msg_queue(2) sink = gr.message_sink(gr.sizeof_float*fft_size, msgq, True) #connect self.connect(self, fft, sink) #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, fft.set_average) self.controller.publish(AVERAGE_KEY, fft.average) self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate) self.controller.subscribe(DECIMATION_KEY, fft.set_decimation) self.controller.publish(DECIMATION_KEY, fft.decimation) self.controller.subscribe(FRAME_RATE_KEY, fft.set_vec_rate) self.controller.publish(FRAME_RATE_KEY, fft.frame_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = waterfall_window.waterfall_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, num_lines=num_lines, baseband_freq=baseband_freq, decimation_key=DECIMATION_KEY, sample_rate_key=SAMPLE_RATE_KEY, frame_rate_key=FRAME_RATE_KEY, dynamic_range=dynamic_range, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, msg_key=MSG_KEY, ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS
def __init__( self, parent, title='', sample_rate=1, size=scope_window.DEFAULT_WIN_SIZE, v_scale=0, t_scale=0, v_offset=0, xy_mode=False, ac_couple=False, num_inputs=1, trig_mode=scope_window.DEFAULT_TRIG_MODE, y_axis_label='Counts', frame_rate=scope_window.DEFAULT_FRAME_RATE, use_persistence=False, persist_alpha=None, **kwargs #do not end with a comma ): #ensure analog alpha if persist_alpha is None: actual_frame_rate=float(frame_rate) analog_cutoff_freq=0.5 # Hertz #calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_frame_rate) if not t_scale: t_scale = 10.0/sample_rate #init gr.hier_block2.__init__( self, "scope_sink", gr.io_signature(num_inputs, num_inputs, self._item_size), gr.io_signature(0, 0, 0), ) #scope msgq = gr.msg_queue(2) scope = gr.oscope_sink_f(sample_rate, msgq) #controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, scope.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate) self.controller.subscribe(DECIMATION_KEY, scope.set_decimation_count) self.controller.publish(DECIMATION_KEY, scope.get_decimation_count) self.controller.subscribe(TRIGGER_LEVEL_KEY, scope.set_trigger_level) self.controller.publish(TRIGGER_LEVEL_KEY, scope.get_trigger_level) self.controller.subscribe(TRIGGER_MODE_KEY, scope.set_trigger_mode) self.controller.publish(TRIGGER_MODE_KEY, scope.get_trigger_mode) self.controller.subscribe(TRIGGER_SLOPE_KEY, scope.set_trigger_slope) self.controller.publish(TRIGGER_SLOPE_KEY, scope.get_trigger_slope) self.controller.subscribe(TRIGGER_CHANNEL_KEY, scope.set_trigger_channel) self.controller.publish(TRIGGER_CHANNEL_KEY, scope.get_trigger_channel) actual_num_inputs = self._real and num_inputs or num_inputs*2 #init ac couple for i in range(actual_num_inputs): self.controller[common.index_key(AC_COUPLE_KEY, i)] = ac_couple #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = scope_window.scope_window( parent=parent, controller=self.controller, size=size, title=title, frame_rate=frame_rate, num_inputs=actual_num_inputs, sample_rate_key=SAMPLE_RATE_KEY, t_scale=t_scale, v_scale=v_scale, v_offset=v_offset, xy_mode=xy_mode, trig_mode=trig_mode, y_axis_label=y_axis_label, ac_couple_key=AC_COUPLE_KEY, trigger_level_key=TRIGGER_LEVEL_KEY, trigger_mode_key=TRIGGER_MODE_KEY, trigger_slope_key=TRIGGER_SLOPE_KEY, trigger_channel_key=TRIGGER_CHANNEL_KEY, decimation_key=DECIMATION_KEY, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, ) common.register_access_methods(self, self.win) #connect if self._real: for i in range(num_inputs): self.wxgui_connect( (self, i), ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, i), SAMPLE_RATE_KEY), (scope, i), ) else: for i in range(num_inputs): c2f = gr.complex_to_float() self.wxgui_connect((self, i), c2f) for j in range(2): self.connect( (c2f, j), ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, 2*i+j), SAMPLE_RATE_KEY), (scope, 2*i+j), )
def __init__( self, parent, title='', sample_rate=1, size=const_window.DEFAULT_WIN_SIZE, frame_rate=const_window.DEFAULT_FRAME_RATE, const_size=const_window.DEFAULT_CONST_SIZE, #mpsk recv params M=4, theta=0, alpha=0.005, fmax=0.06, mu=0.5, gain_mu=0.005, symbol_rate=1, omega_limit=0.005, ): #init gr.hier_block2.__init__( self, "const_sink", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0), ) #blocks sd = blks2.stream_to_vector_decimator( item_size=gr.sizeof_gr_complex, sample_rate=sample_rate, vec_rate=frame_rate, vec_len=const_size, ) beta = .25 * alpha**2 #redundant, will be updated fmin = -fmax gain_omega = .25 * gain_mu**2 #redundant, will be updated omega = 1 #set_sample_rate will update this # Costas frequency/phase recovery loop # Critically damped 2nd order PLL self._costas = gr.costas_loop_cc(alpha, beta, fmax, fmin, M) # Timing recovery loop # Critically damped 2nd order DLL self._retime = gr.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_limit) #sync = gr.mpsk_receiver_cc( # M, #psk order # theta, # alpha, # beta, # fmin, # fmax, # mu, # gain_mu, # omega, # gain_omega, # omega_limit, #) agc = gr.feedforward_agc_cc(16, 1) msgq = gr.msg_queue(2) sink = gr.message_sink(gr.sizeof_gr_complex * const_size, msgq, True) #controller def setter(p, k, x): p[k] = x self.controller = pubsub() self.controller.subscribe(ALPHA_KEY, self._costas.set_alpha) self.controller.publish(ALPHA_KEY, self._costas.alpha) self.controller.subscribe(BETA_KEY, self._costas.set_beta) self.controller.publish(BETA_KEY, self._costas.beta) self.controller.subscribe(GAIN_MU_KEY, self._retime.set_gain_mu) self.controller.publish(GAIN_MU_KEY, self._retime.gain_mu) self.controller.subscribe(OMEGA_KEY, self._retime.set_omega) self.controller.publish(OMEGA_KEY, self._retime.omega) self.controller.subscribe(GAIN_OMEGA_KEY, self._retime.set_gain_omega) self.controller.publish(GAIN_OMEGA_KEY, self._retime.gain_omega) self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate) self.controller.subscribe( SAMPLE_RATE_KEY, lambda x: setter(self.controller, OMEGA_KEY, float(x) / symbol_rate)) self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate) #initial update self.controller[SAMPLE_RATE_KEY] = sample_rate #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = const_window.const_window( parent=parent, controller=self.controller, size=size, title=title, msg_key=MSG_KEY, alpha_key=ALPHA_KEY, beta_key=BETA_KEY, gain_mu_key=GAIN_MU_KEY, gain_omega_key=GAIN_OMEGA_KEY, omega_key=OMEGA_KEY, sample_rate_key=SAMPLE_RATE_KEY, ) common.register_access_methods(self, self.win) #connect self.wxgui_connect(self, self._costas, self._retime, agc, sd, sink)