""" 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 pmt global param_1 class my_block(gr.sync_block): # other base classes are basic_block, decim_block, interp_block """my msg splitter""" def __init__(self, LO_1=1.0): gr.sync_block.__init__(self, name = "Message splitter", in_sig = None, out_sig = None) self.message_port_register_in(pmt.intern('msg_in')) self.message_port_register_out(pmt.intern('LO_1')) #self.message_port_register_out(pmt.intern('LO_2')) self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg) # if an attribute with the same name as a parameter is found, # a callback is registered (properties work, too). self.param_1= LO_1 #self.param_2= LO_2 def handle_msg(self, msg): print ("in--> ", (msg), pmt.cdr(msg)) #freq_in_tag = pmt.car(msg) freq_in_value = pmt.to_double(pmt.cdr(msg)) new_freq = freq_in_value - self.param_1 + 0.5 #new_freq = freq_in_value #new_msg = pmt.set_cdr(msg, pmt.from_double(new_freq)) x = pmt.string_to_symbol("freq") y = pmt.from_double(new_freq) new_msg = pmt.cons(x, y) print ("out--> ", new_msg, freq_in_value) self.message_port_pub(pmt.intern('LO_1'), msg) #self.message_port_pub(pmt.intern('LO_2'), new_msg) def work(self, input_items, output_items): output_items[0][:] = input_items[0] return len(output_items[0])