#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2017 <+YOU OR YOUR COMPANY+>. # # This is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # import numpy as np from gnuradio import gr import pmt class set_gain(gr.basic_block): """ docstring for block set_gain """ def __init__(self, num_values, max_gain, min_gain, def_gain): gr.basic_block.__init__(self, name="set_gain", in_sig=[np.complex64], out_sig=[]) self.message_port_register_out(pmt.intern("gain_port")) ##name must match ##name in XML file, I think self.num_values = num_values self.max_gain = max_gain self.min_gain = min_gain self.cur_gain = def_gain self.seen = 0 #keeps a count of how many samples have been seen 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 def general_work(self, input_items, output_items): in0 = input_items[0] self.seen+=in0.shape[0] if self.seen>self.num_values: self.cur_gain = (self.cur_gain + 1)%self.max_gain self.cur_gain = max(self.min_gain, self.cur_gain) key = pmt.to_pmt("gain") value = pmt.to_pmt(self.cur_gain) self.message_port_pub(pmt.intern('gain_port'), pmt.cons(key, value)) self.seen = 0 self.consume_each(in0.shape[0]) #consume everything you've account for # tell system to move on to next samples return 0 ##return 0 samples generated ## as the block doesn't have an output stream