""" Embedded Python Blocks: Each 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 pmt from random import uniform class blk(gr.basic_block): def __init__(self, initial_gain=5, stop_gain=15, step=0.5):# only default arguments here gr.basic_block.__init__( self, name='Gain Sweeper', in_sig=[np.complex64], out_sig=[np.complex64] ) self.message_port_register_out(pmt.intern('msg_out')) self.gain = initial_gain self.step = step self.stop = stop_gain self.count = 0 self.a = 000000000000 def forecast(self, noutput_items, ninput_items_required): #setup size of input_items[i] for work call for i in range(len(ninput_items_required)): ninput_items_required[i] = noutput_items + a def general_work(self, input_items, output_items): #creating variables equal to the number of input & output items in0 = input_items[0] out = output_items[0] # loop that will count the number of input items. Once 10^7 input items is reached # a command will be sent to increase the gain. for x in len(in0): self.count = count + len(in0) if self.count == 100000000: self.count = 0 self.message_port_pub(pmt.intern('msg_out'),pmt.cons(pmt.intern("gain"),pmt.to_pmt(self.gain))) self.gain+=self.step return len(output_items[0])