In the following GNU Radio processing block, I can't figure out who/what passes the value of input_items
to the work
function in the first place. Is it possible to pass that value to the __init__
function instead?
I have a file xyz.py :
class xyz(gr.sync_block):
"""
docstring for block add_python
"""
def __init__(self, parent, title, order):
gr.sync_block.__init__(self,
name="xyz",
in_sig=[numpy.float32,numpy.float32],
out_sig=None)
................
................
//I want to access the value of input_items here
...............
...............
def work(self, input_items, output_items):
................
The
__init__
function is called only once to "initialize" the new instance of the class. It has nothing to do with moving data through the flowgraph, besides setting up input and output types so that the block can be successfully connected.So, in
top_block
, you might have:And later on, you run the flowgraph:
When you run the flowgraph, the GNU Radio scheduler takes a number of samples from the source block and puts them in a buffer. It then passes that buffer to the
work
function of the next block in the flowgraph, along with an "empty" buffer for output items.So the
work
function of each block is called automatically by the scheduler when there is data for it to process.__init__
can not have access to any of the parameters towork
, becauseinput_items
has not even been passed towork
at the time that__init__
is called.work
is a function that is entirely seperate from__init__
. Its parameters cannot be accessed outside of that function. If you want to accessinput_items
, add it to the__init__
parameter list and pass it when you call__init__
.