Sie sind auf Seite 1von 3

How to create your own module in GRC :

A. Using C++
Referensi :
- https://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules
- https://www.youtube.com/watch?v=BW8o9ZgFJ5I

• Use Out of Tree module to create our own module gr-howto. gr_modtool script is used to
create files automatically.
• Use command in terminal to create module “gr-howto”
$ gr_modtool newmod howto
this is will create new directory called gr-howto

• to see created files, go to gr-howto directory and type ls command


$ cd gr-howto
gr-howto$ ls

• to create empty files for block, go to directory gr-howto and type the command below :
gr-howto$ gr_modtool add -t general square_ff

GNU Radio module name identified: howto


Language: C++
Block/code identifier: square_ff
Enter valid argument list, including default arguments:
Add Python QA code? [Y/n] y
Add C++ QA code? [y/N] n
Adding file 'square_ff_impl.h'...
Adding file 'square_ff_impl.cc'...
Adding file 'square_ff.h'...
Editing swig/howto_swig.i...
Adding file 'qa_square_ff.py'...
Editing python/CMakeLists.txt...
Adding file 'howto_square_ff.xml'...
Editing grc/CMakeLists.txt...

• open python/qa_square_ff.py and edit it accordingly :


gr-howto$ cd python
gr-howto/python$ ls
gr-howto/python$ sudo gedit qa_square_ff.py
gr-howto/python$ ls

• test_001_square_ff builds a small graph that contains three nodes.


◦ blocks.vector_source_f(scr_data) will source the elements of scr_data
◦ howto.square_ff is the block we're testing
◦ blocks.vector_sink_f gathers the output of howto.square_ff

• the run() method runs the graph until all the blocks indicate they are finished.
• Finally, we check that the result of executing square_ff on scr_data matches what we expect.
• Now we need to modify lib/square_ff_impl.cc
◦ gr_modtool hints at where you have to change code by adding <++> symbols
◦ open the file and modify it accordingly :
gr-howto/python$ cd ..
gr-howto$ cd lib
gr-howto/lib$ ls
gr-howto/lib$ sudo gedit square_ff_impl.cc
◦ input and output signature specifies min and max no of input and output ports along this
type of ports
◦ here we have only 1 input and 1 output port and that of type float.
◦ Forecast() is a function which tells the scheduler how many input items are required to
produce noutput_items output items.
◦ Here they are same and hence input_items_required[0] = noutput_items;
◦ the index 0 indicates that this is for the first port.
◦ general_work() is the method that does the actual signal processing
◦ let's modify it to get square of input value
• now lets build and compile our files using Cmake
◦ first go to directory gr-howto and type commands below :
r-howto$ mkdir build
r-howto$ cd build
r-howto/build$ cmake ../
r-howto/build$ make
◦ lets try running 'make test', type command below :
gr-howto/build$ make test
• lets try running 'make test', type command below :
gr-howto/build$ make test
• if everything is fine, then create XML code using gr_modtool script
◦ go to gr-howto directory and type below command :
gr-howto$ gr_modtool makexml square_ff
gr-howto$ gr_modtool makexml square_ff
GNU Radio module name identified: howto
Warning: This is an experimental feature. Don't expect any magic.
Searching for matching files in lib/:
Making GRC bindings for lib/square2_ff_impl.cc...
Overwrite existing GRC file? [y/N] y

◦ let's install the module for that type command in terminal


gr-howto$ cd build
gr-howto/build$ sudo make install
gr-howto/build$ sudo ldconfig
• That's it, the block is created. Let's try to use in GRC
B. Using Python
Referensi :
- https://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules

Das könnte Ihnen auch gefallen