""" Embedded Python Blocks: Each time this file is saved, GRC will instantiate the first class it finds to get ports and parameters of your block. The arguments to __init__ will be the parameters. All of them are required to have default values! """ import numpy as np from gnuradio import gr import time class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block """Embedded Python Block - debug sample rate""" def __init__(self, time_slot=5): # only default arguments here """arguments to this function show up as parameters in GRC""" gr.sync_block.__init__( self, name='Debug Sample Rate', # will show up in GRC in_sig=[np.complex64], out_sig=[np.complex64] ) self.time_slot = time_slot self.time_start=self.time_last=time.time() self.sum_items=0 def work(self, input_items, output_items): output_items[0][:] = input_items[0] self.sum_items += len(input_items[0]) if time.time()-self.time_last > self.time_slot: self.time_last=time.time() print u"SampRate:{:11,.0f} B/s, Elapsed:{:3,.0f} sec".format( float(self.sum_items)/(time.time()-self.time_start), time.time()-self.time_start ) return len(output_items[0])