noutput_items 在 GNU Radio 中是如何确定的?

How is noutput_items determined in GNU Radio?

我正在查看 GrOsmoSdr rtl_tcp_source_f.cc 的源代码,这是一个 GNU Radio 源,它从 TCP 读取交错 I/Q 数据。

功函数如下所示:

int rtl_tcp_source_f::work (int noutput_items,
                            gr_vector_const_void_star &input_items,
                            gr_vector_void_star &output_items)
{
  float *out = (float *) output_items[0];
  ssize_t r = 0;

  int bytesleft = noutput_items;
  int index = 0;
  int receivedbytes = 0;
  while(bytesleft > 0) {
    receivedbytes = recv(d_socket, (char*)&d_temp_buff[index], bytesleft, 0);

    if(receivedbytes == -1 && !is_error(EAGAIN)){
      fprintf(stderr, "socket error\n");
      return -1;
    }
    bytesleft -= receivedbytes;
    index += receivedbytes;
  }
  r = noutput_items;

  for(int i=0; i<r; ++i)
    out[i]=d_LUT[*(d_temp_buff+d_temp_offset+i)];

  return r;
}

缓冲区d_temp_buff在构造函数中设置:

d_temp_buff = new unsigned char[d_payload_size]; 

其中d_payload_size是配置传入的构造函数参数。

功函数恰好将 noutput_items 读入 d_temp_buffnoutput_items一般是怎么被Gnuradio选中的,这个工作函数怎么确定noutput_items <= d_payload_size

默认情况下,流程图的最大输出项数上限是一个很大的数字,具体取决于 gnuradio 版本,目前在主存储库中设置的值为 100000000

这是通过在没有指定参数的情况下调用流程图的顶部块来设置的,并使用默认参数。可以通过将不同的参数传递给 top_block 的开始调用或通过调用 set_max_noutput_items.[=13 在顶部块或特定块上调用 set_max_noutput_items 来覆盖此全局值=]

在如此高的值初始化后,调度程序根据最小可用输出 space 将其设置为较低的值,它使用 [=27] 中设置的 noutput_items 的值=] 构造函数,以及块的 output_multiple 和 min_noutput_items。参见 single_threaded_scheduler.cc and block_executor.cc

在你的模块中发生的工作函数的子分类似乎没有任何基于负载大小的 max_noutput_items 约束,默认设置为 16384,或者作为参数传入的 MTU / 数据包长度。

需要修改代码以添加这样的检查,或者 set_max_noutput_items 需要根据数据包长度为给定的块设置,无论是在使用前还是在构造函数中,目前默认为继承自 sync_block 的 rtl_tcp_source_f 块的继承值 0 和 value 的标志设置为 false,而 sync_block 继承自块。