Friday, March 20, 2020

Frequency Xlating Fir Filter issue passing message

"""
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])

Good evening,
I'm trying to make a multimode receiver using a PlutoSDR; all the demodulation and visualization parts work correctly.  Now I would like to use a click'n-point tuning and as a result I have tried to understand something more about the use of controlports.  I followed some tutorials and made a custom block (myblock.py "Message splitter") which receives the message generated by double clicking on the waterfallas an input and
generates a message to be sent to the Frequency Xlating Fir Filter block, which consists of an offset between the center frequency (fx) and the frequency generated by the double click. I state that by controlling this block with a slider (fx_tune) everything works correctly, but using the outgoing message the set frequency is completely incorrect. In the embedeed block I perform an output of the variables involved directly on the console and everything "apparently" is correct. Any ideas / suggestions? Attached is the .grc file, the source of the "Message splitter" block and a printscreen of the blocks (I have eliminated what is unnecessary and already functional). Thanks in advance, Vittorio, I3VFJ

No comments:

Post a Comment