-1

I want to write a OOT-Module for GNU Radio in c++.

In order to familiarize myself with the matter, I want to write the existing Block 'add_xx' myself.

I do not know how I can do it that a drop-down menu appears in the block settings for the IO-Type .

Can anyone give a simple example how I'd have to write it in the _impl.cc and _impl.h file?

I have the code skeleton created with gr_modtool. Would be nice if the sample is based on this.

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

1 Answers1

0

So, the trick is that the different types of the add_XX blocks are actually different classes, and the dropdown menu actually makes the GNU Radio companion set a few variables, which in turn are used to decide which block is used; this is all relatively ugly code in the XML file that describes the add_xx:

<?xml version="1.0"?>
...
<block>
    <name>Add</name>
    <key>blocks_add_xx</key>
    <import>from gnuradio import blocks</import>
    <make>blocks.add_v$(type.fcn)($vlen)</make>
    <param>
        <name>IO Type</name>
        <key>type</key>
        <type>enum</type>
        <option>
            <name>Complex</name>
            <key>complex</key>
            <opt>fcn:cc</opt>
        </option>
        <option>
            <name>Float</name>
            <key>float</key>
            <opt>fcn:ff</opt>
        </option>
        ...
    </param>
    <param>
        <name>Num Inputs</name>
        <key>num_inputs</key>
        <value>2</value>
        <type>int</type>
    </param>
    <param>
        <name>Vec Length</name>
        <key>vlen</key>
        <value>1</value>
        <type>int</type>
    </param>
    <check>$num_inputs &gt; 1</check>
    <check>$vlen &gt; 0</check>
    <sink>
        <name>in</name>
        <type>$type</type>
        <vlen>$vlen</vlen>
        <nports>$num_inputs</nports>
    </sink>
    <source>
        <name>out</name>
        <type>$type</type>
        <vlen>$vlen</vlen>
    </source>
</block>

So, there's an add_cc class for complex, an add_ff for float and so on. In fact, GNU Radio's build system generates these implementations from a single text template.

So, whilst I do think it's a very good idea to recreate a simple block like add_cc, the type variability is as much a feature seldom necessary when implementing new stuff, as hard to do right for a beginner.

So: start with a single type, and follow the official GNU Radio Guided Tutorials from 1 to 5. They were made especially for people like you, and they cover C++ blocks!

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