2

I have a GRC project with multiple functionalities, but not all of them must be called at the same time. It would be a solution to divide it into several independent projects, but I'd prefer a more flexible solution which dynamically activate/deactivate some blocks in the top level flow graph.

So my idea is to enable/disable the blocks according to the value of a variable. It this possible? Or is there any alternative similar solution?

Bin Han
  • 51
  • 2
  • 5

2 Answers2

3


EDIT If you're using GNU Radio 3.7 (and have good reason not to use any more recent release, which you really should!): Please don't use selector. It's "stop everything, reconnect blocks internally, continue everything" has terrible side effects.

If you're using GNU Radio 3.8.0.0 or later: We've replaced the above mechanism by a simple point-to-point copy, which is way more robust (but comes at a copying overhead). So, starting with 3.8-techpreview, selector is safe to use.


Try the "Selector" block. You can set the active in/output ports with two variables.

Internally, selector is a hierarchical block, and it will pause your flowgraph, disconnect the formerly active in- and output blocks connect the now active blocks, and then continue operation of the flow graph.

In that manner, it's not sample-accurate, and might not be the tool of choice. You might want to look into message passing instead of using variables, and go for the "Multiply (with) Matrix" block.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
1

You might use an epy block with one input and n outputs. In the work function you can map input as you wish. The example_parameter (which can be set by a variable from your flowgraph) can determine the output index. Insert a python block in your flowgraph, double click it, open in editor, ctrl+a ,ctrl+v. Good luck!

 import numpy as np
 from gnuradio import gr
 import time

 class blk(gr.sync_block):  # other base classes are basic_block, 
 decim_block, 
 interp_block
"""Embedded Python Block example - a simple multiply const"""

def __init__(self, example_param=1.0):  # only default arguments here
    """arguments to this function show up as parameters in GRC"""
    gr.sync_block.__init__(
        self,
        name='EPY demux',   # will show up in GRC
        in_sig=[np.complex64],
        out_sig=[np.complex64,np.complex64] # ADD HERE HOW MANY OUTPUTS YOU WANT
    )
    # if an attribute with the same name as a parameter is found,
    # a callback is registered (properties work, too).
    self.example_param = example_param

def work(self, input_items, output_items):
    """example: multiply with constant"""
    output_items[int(self.example_param)][:] = input_items[0]
    return len(input_items[0])`