#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2019 Jay Arrowfield. # # 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 import pmt from gnuradio import gr class peak_manager(gr.basic_block): """ docstring for block peak_manager """ def __init__(self): gr.basic_block.__init__(self, name="peak_manager", in_sig=None, out_sig=None) # Register in / out message ports self.message_port_register_in(pmt.intern("control")) self.message_port_register_out(pmt.intern("status")) # Register in message handler self.set_msg_handler(pmt.intern("control"), self.msg_handler) #self.message_port_pub(pmt.intern("port name"), < pmt message >) def msg_handler(self, msg): print ("Message received:") if pmt.is_dict(msg): items = pmt.dict_items(msg) for n in range(0, pmt.length(items)): pair = pmt.nth(n, items) key = pmt.car(pair) val = pmt.cdr(pair) if pmt.is_integer(val): print("{}={}".format(pmt.symbol_to_string(key), pmt.to_long(val))) elif pmt.is_real(val): print("{}={}".format(pmt.symbol_to_string(key), pmt.to_float(val))) elif pmt.is_bool(val): print("{}={}".format(pmt.symbol_to_string(key), pmt.to_bool(val))) else: print(pmt.symbol_to_string(msg)) 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): output_items[0][:] = input_items[0] consume(0, len(input_items[0])) #self.consume_each(len(input_items[0])) return len(output_items[0])