【问题标题】:Why is my custom block going twice into general_work() function in GNU Radio?为什么我的自定义块两次进入 GNU Radio 中的 general_work() 函数?
【发布时间】:2022-01-06 03:29:00
【问题描述】:

我正在创建一个自定义块“组合”,它从第一个输入中获取 20 个字节的数据。第一个输入的值指定要从第二个输入读取的字节数,这些字节被读取并写入输出文件。

每当我执行流程图时,打印显示代码两次进入一般工作函数。它在第一次和第二次读取正确的数据,它只是读取虚假值并将这些不正确的数据写入输出接收器。

我使用以下签名进行输入:

Combine_impl::Combine_impl()
      : gr::block("Combine",
              gr::io_signature::make(2, 2, sizeof(unsigned char)),
              gr::io_signature::make(1, 1, sizeof(unsigned char)))
    {}

我认为我的问题在于预测功能和消耗每个功能的用法。我已经尝试在预测中这样做,但它仍然会两次进入 general_work 函数并将不正确的数据写入输出文件。

ninput_items_required[0] = 20;
ninput_items_required[1] = 7;   //because the first input has a value of 7 and will read 7 bytes of data from the second input

有人可以帮我确定这里到底出了什么问题吗?还有,这里的consume_each()函数应该怎么用?

【问题讨论】:

  • 我使用了consume(0, 20)和consume(1, 7)而不是consume_each(),但是问题仍然存在。

标签: gnuradio gnuradio-companion


【解决方案1】:

我修改了 forecast 函数以获取每个输入中使用的确切项目数:

void Combine_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
     ninput_items_required[0] = 20;
     ninput_items_required[1] = 7;
}

我没有使用 consume_each() 指定所有输入中消耗的字节数,而是使用 consume() 函数为每个单独指定此数字输入:

consume(0, 20); //20 bytes of input at index 0 were consumed
consume(1, 7);  //7 bytes of input at index 1 were consumed

我没有从 general_work 函数返回 noutput_items,而是返回以下内容。它准确地指定了要返回的字节数,其值不同于 noutput_items

return (20 + 7);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2016-03-02
    • 1970-01-01
    相关资源
    最近更新 更多