使用 _post 测试 GNU Radio 消息接受块

Testing a GNU Radio message accepting block with _post

我正在尝试为概念上与 message_debug 非常相似的 GNU Radio 消息块编写 python 单元测试。我注意到 _post 将消息发送到块 returns 没有错误,但没有任何效果。这里 message_debug 显示相同的行为:

>>> msgdbg = blocks.message_debug()
>>> msgdbg.to_basic_block()._post(pmt.intern('print'), pmt.intern("test"))
>>> msgdbg.to_basic_block()._post(pmt.intern('store'), pmt.intern("test"))
>>> msgdbg.num_messages()
0

我无法理解为什么会发生这种情况以及我需要采取哪些步骤来为消息接受块编写单元测试。

_post连接到不属于 运行 流程图的块不起作用。

这是因为 GNU Radio 有一个基于线程的调度器,其中每个块都在自己的线程中,基本上会经历一个无限循环,为 space 检查输入和输出流,调用 general_work 可行,然后检查该块是否注册了消息处理程序以及队列中是否有消息。

如果您还没有启动流程图,则没有线程也没有循环运行检查队列。

现在,即使在流程图中 运行 时你也不能使用 _post 这一事实起初让我有点惊讶,但后来我意识到只有实际上 以某种方式 连接的块实际上有自己的线程。