Hello!
I’m developing a TV enconder, and I need to extract information from my
input data, and this will be used to determine the parameters of other
blocks on the flow graph.
How can I change the value of a variable of the python (or grc)
environment
from the block general_work() method?
Thanks!
On 01/24/2012 10:42 AM, Andr S. wrote:
Hello!
I’m developing a TV enconder, and I need to extract information from my
input data, and this will be used to determine the parameters of other
blocks on the flow graph.
How can I change the value of a variable of the python (or grc) environment
from the block general_work() method?
Well, you generally cant call a python function from c++… but heres a
few ways that may accomplish what you need:
-
Using swig directors is a possibility. Rather than figure out the
intricacies of directors, gnuradio already makes use of them in the
gr.feval_* class, which you can use to call into a python object. Your
general_work() calls the feval object in c++; and then feval object
(from python) directly calls into other variables in the python-domain
of your flow graph.
-
Another possibility is passing messages into a message queue object.
A python thread can pop the messages and act upon them.
-
A related possibility, depending upon how your block operates would
be to have a python thread periodically poll the getter methods of your
custom block and act upon those values. There is already a block in grc
that will poll another block’s getter function and update a variable.
-
You could write the general work in python, which means all of the
parameter calculation and setting occurs entirely in python (this
functionality is not yet officially accepted).
http://gnuradio.org/redmine/projects/gnuradio/wiki/WriteBlocksInPython
-
And if thats not possible for performance reasons, you might consider
a hybrid approach where you write general work in python, but you call
into a function implemented in c++; where this function processes the
input data and returns the “determined parameters”, which you can act on
in python.
-Josh