Reputation: 1
I need to change the receive and transmit gain on my source/sink respectively based on data that will be calculated in my own piece of code. What is the best way to do this? None of the tutorials describe how this is done.
Ideally the GNUradio python script would just call a couple functions in a loop, and they would return the gain values and the system would change dynamically.
Upvotes: 0
Views: 3108
Reputation: 494
I had a similar need for this functionality a few months ago. My implementation involved making a copy of the automatically generated Python 2.7 file, then editing it to add the desired functionality. In my case I needed a quick and simple way to generate multiple channels and setting variables when executing the file. This was accomplished through the use of the click module, which allowed for setting variables and executing the file via a terminal window.
If you are trying to dynamically calculate and change variables during execution, my suggestion would be to create a separate thread in the main()
function using the threading module (or equivalent). This new thread should call a separate function that loops through your piece of code. Inside this function your algorithm should make use of the variablename_get
and variablename_set
functions that have also been automatically generated by GRC.
It is unclear where the data you are using to calculate these changes in gain comes from, but hopefully this answer is helpful.
Upvotes: 0
Reputation: 66
UHD sink/source can be controlled by a specific command syntax at the message port. For details see https://gnuradio.org/doc/doxygen/page_uhd.html#uhd_command_syntax .
Here is an example embedded python block with an incoming message port for gain double values and outgoing port which have to be connected to the USRP Sink/Source
from gnuradio import gr
class tuning_uhd(gr.sync_block):
def __init__(self):
gr.sync_block.__init__(self,
name="Gain Tuning",
in_sig=[],
out_sig=[]
)
# Message ports
self.message_port_register_out(gr.pmt.intern("uhd"))
self.message_port_register_in(gr.pmt.intern("gain"))
self.set_msg_handler(gr.pmt.intern('gain'), self.handle_msg)
def handle_msg(self, msg):
self.message_port_pub(gr.pmt.intern('uhd'), gr.pmt.to_pmt({'gain': gr.pmt.to_double(msg) })
Upvotes: 0