In Part 1 of this series, we created a new module called my_module for use in a simple cognitive radio application that required a basic state machine. In Part 2 of this blog series, we modified the following files:
• Auto-generated header file – Declared a private class variable, which is the state of our state machine
• Auto-generated source file – Implemented the actual state machine
In this blog post, Part 3, we wrap things up by compiling our project using CMake.
The first step is to make sure that the current directory is ‘gr-my_module’. Next, we create the build directory using the following command:
Switch to the new directory:
Now, it’s time to start the CMake compilation process:
This command tells CMake to use the compilation file called CMakeList.txt, which is located one directory above in the hierarchy tree in gr-my_module/.
The last step is to launch the actual CMake compilation process:
The compilation process should not show any errors. If any errors appear, repeat the above steps but as root user instead. Also, if the GNU Radio runtime cannot be found, make sure that the GNU Radio environment variables are correctly instantiated (see Part 1 of this series).
Now that the compilation is done, you can install your module. However, it will not be available yet in the GNU Radio Companion (GRC) software. This is because the gr_modtool command doesn’t create the necessary XML files, it simply adds some skeleton code. To create the XML code for the block, run the following command from the gr-my_module folder:
Note that gr_modtool add creates an invalid GRC file, so this is why we are overwriting it. In most cases, gr_modtool can’t determine all parameters by itself and you will have to edit the appropriate XML file by hand. The GRC wiki page has a description of the parameters. In this case however, because the block is simple, the XML is actually valid.
The last step to make our block available in GRC is to run the following command in the build directory:
That’s it! You should now see in your GRC block library a block called ‘cognitive’, with float input and output ports.
To test and debug a block, you can use the good old printf() function. For example, let’s say want to output at runtime the chosen frequency to transmit/receive. First, add the following line of code after the state verification section in the cognitive_impl.cc file:
printf(“%f, n”, out