Search code examples
gnuradio

GNU Radio block with variable number of intputs/outputs


I am currently trying to do the signal processing of multiple channels in parallel using a custom source block. Up to now I created an OOT-source block which streams data for only one channel into one output perfectly fine.

Now I am searching for a way to expand this module so that it can support a higher number of channels ( = outputs of the source block; up to 64) in parallel. Because the protocol used to pull the samples pulls them all at one it is not possible to use more instances of the same source block.

Things I have found so far:

  • A pdf which seems to explain exactly what to do already but it seems that it is outdated and that this functionality is no longer supported under GNU Radio.
  • The description of a feature which should be implemented in the future.

Is there are known solution or workaround for this problem?


Solution

  • Look at the add block: It has configurable many inputs!

    Two different input configurations of the add block

    Now, the trick here is threefold:

    1. define an io_signature as input and output that allows for adjustable numbers. If you use gr_modtool add to create a new block, your io_signatures will be filled with <+MIN_IN+>, <+MAX_IN+>, <+MIN_OUT+> and <+MAX_OUT+>. Adjust these to reflect your actual minimum and maximum in- and output port numbers. If you want to have 1 to infinity inputs, use 1, -1.
    2. in your (general_)work method, check for the number of inputs by doing something like ninputs = input_items.size(), and for the number of outputs by doing noutputs = output_items.size().
    3. (optionally, if you want to use GRC) modify the <sink>/<source> definitions in your block GRC XML:

      <sink>
              <name>in</name>
              <type>complex</type>
              <nports>$num_inputs</nports>
      </sink>
      

    num_inputs could be a block parameter; compare the add_XX block source code.