0

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.

4
  • what source/sink are we talking about?= Jul 8, 2017 at 16:30
  • USRP N210 as the source and sink
    – padraig
    Jul 10, 2017 at 15:30
  • So it's the "UHD: USRP Source" block? Jul 10, 2017 at 17:28
  • Yes. I am using both the UHD: USRP source and UHD: USRP sink blocks. I need to dynamically change their attributes.
    – padraig
    Jul 10, 2017 at 22:02

2 Answers 2

0

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) })
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.