是否可以在 GNU Radio 块的 __init__ 中访问工作函数的变量?

Is it possible to access work function's variable in __init__ of a GNU Radio block?

在下面的 GNU Radio 处理块中,我想不出 who/what 首先将 input_items 的值传递给 work 函数。是否可以将该值传递给 __init__ 函数?

我有一个文件 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):
        ................

work 是一个完全独立于 __init__ 的函数。它的参数不能在该函数之外访问。如果要访问input_items,将其添加到__init__参数列表中,并在调用__init__时传递。

__init__ 函数仅被调用一次 "initialize" class 的新实例。除了设置输入和输出类型以便块可以成功连接之外,它与通过流程图移动数据无关。

因此,在 top_block 中,您可能有:

proc = xyz() # xyz's __init__ is called here
self.connect(source, proc, sink) # still no input_items, just connected flowgraph

稍后,您 运行 流程图:

tb = top_block()
tb.run() # 'input_items' are now passed to 'work' of each block in succession

当您 运行 流程图时,GNU Radio 调度程序从源块中获取一些样本并将它们放入缓冲区。然后将该缓冲区传递给流程图中下一个块的 work 函数,以及用于输出项的 "empty" 缓冲区。

因此,当有数据需要处理时,调度程序会自动调用每个块的 work 函数。 __init__ 无法访问 work 的任何参数,因为在调用 __init__input_items 甚至还没有传递给 work