Friday, October 12, 2012

Understanding a Singal Processing Block in GNU Radio : SWIG Interface : Files

SWIG Interface files :

Once we have created our .cc and .h files its the time to create the SWIG (.i) file, so that our new block can be called form python 

SWIG is used as a necessary "glue ", to allow python and C++ to "stick" together in a complete GNU Radio application

The purpose of the .i file is to tell SWIG how it should go about creating this glue

A .i file is very similar to a .cc or .h file where several functions are declared
However in .i file only those functions are declared which we want to access from python

Its typically quite short in length

lets see an example of an .i file gr_multiply_const_ff.i


gr_make_multiply_const_ff (float k, size_t vlen=1);

class gr_multiply_const_ff : public gr_sync_block
  float k() const;
  void set_k(float k);

Lets notice some important facts ,

we have invoked GR_SWIG_BLOCK_MAGIC with parameters "gr" and "multiply_const_ff" and it has direct relevance to how we invoke the block from python

Practically this means that in python, when we seek to invoke our blocks, we would first use the command

import gr

and when we wish to instantiate our block, we would use the python command

block = gr.multiply_const_ff()

In summary, from within python, gr is a package multiply_const_ff is a function within this package

The way which we have created the .i files specifies the particular names that python ascribes to the package (gr) and function (multiply_const_ff)

Reference :

No comments:

Post a Comment