GNU Radio没有来自与我自己的OOT块并行的其他块的输出

GNU Radio no output from other blocks parallel with my own OOT block

本文关键字:OOT 输出 并行 自己的 其他 我自己 Radio GNU      更新时间:2023-10-16

我想用C++为GNU Radio编写我自己的通用块,其中有1个输入和1个输出。我使用gr_motool遵循了gnradio.org中的步骤。它可以很好地工作。但当我连接其他块(作用域sink2(和相同的源时,它没有输出

我将流程图连接为:

                            /-> Scope Sink2
Signal Source -> Throttle -|
                            -> my own block -> Scope Sink1

我使用的是GNU Radio Companion v3.7.6.1-65-g500517ac

我创建了块"energy_de"。这将在其他四个文件中创建:energy_de.h

#ifndef INCLUDED_CPP_ENERGY_DE_H
#define INCLUDED_CPP_ENERGY_DE_H
#include <cpp/api.h>
#include <gnuradio/block.h>
namespace gr {
  namespace cpp {
    /*!
     * brief <+description of block+>
     * ingroup cpp
     *
     */
    class CPP_API energy_de : virtual public gr::block
    {
     public:
      typedef boost::shared_ptr<energy_de> sptr;
      /*!
       * brief Return a shared_ptr to a new instance of cpp::energy_de.
       *
       * To avoid accidental use of raw pointers, cpp::energy_de's
       * constructor is in a private implementation
       * class. cpp::energy_de::make is the public interface for
       * creating new instances.
       */
      static sptr make(float makenoise);
      virtual float noise () const = 0;
      virtual void set_noise (float noise) = 0;
    };
  } // namespace cpp
} // namespace gr

energy_de_impl.h

#ifndef INCLUDED_CPP_ENERGY_DE_IMPL_H
#define INCLUDED_CPP_ENERGY_DE_IMPL_H
#include <cpp/energy_de.h>
namespace gr {
  namespace cpp {
    class energy_de_impl : public energy_de
    {
     private:
      float d_noise;
     public:
      energy_de_impl(float noise);
      ~energy_de_impl();
      // Where all the action really happens
      void forecast (int noutput_items, gr_vector_int &ninput_items_required);
      float noise() const { return d_noise; }
      void set_noise(float noise) { d_noise = noise; }
      int general_work(int noutput_items,
               gr_vector_int &ninput_items,
               gr_vector_const_void_star &input_items,
               gr_vector_void_star &output_items);
    };
  } // namespace cpp
} // namespace gr

energy_de_impl.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "energy_de_impl.h"
namespace gr {
  namespace cpp {
    energy_de::sptr
    energy_de::make(float noise)
    {
      return gnuradio::get_initial_sptr
        (new energy_de_impl(noise));
    }
    /*
     * The private constructor
     */
    energy_de_impl::energy_de_impl(float noise)
      : gr::block("energy_de",
              gr::io_signature::make(1, 1, sizeof(float)),
              gr::io_signature::make(1, 1, sizeof(float))),
        d_noise(noise)
    {
    }
    /*
     * Our virtual destructor.
     */
    energy_de_impl::~energy_de_impl()
    {
    }
    void
    energy_de_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
    {
         ninput_items_required[0] = noutput_items;
    }
    int
    energy_de_impl::general_work (int noutput_items,
                       gr_vector_int &ninput_items,
                       gr_vector_const_void_star &input_items,
                       gr_vector_void_star &output_items)
    {
        const float *in = (const float *) input_items[0];
        float *out = (float *) output_items[0];
        for(int i = 0; i < noutput_items; i++){
            if (in[i]*in[i] > d_noise){
              out[i] = 1.0;
            }
            else{
              out[i] = 0.0;
            }
        }
        return noutput_items;
    }
  } /* namespace cpp */
} /* namespace gr */

cpp_energy_de.xml

<?xml version="1.0"?>
<block>
  <name>energy_de</name>
  <key>cpp_energy_de</key>
  <category>cpp</category>
  <import>import cpp</import>
  <make>cpp.energy_de($noise)</make>
  <callback>set_niose($noise)</callback>
  <param>
    <name>noise</name>
    <key>noise</key>
    <type>float</type>
  </param>

  <sink>
    <name>in</name>
    <type>float</type>
  </sink>
  <source>
    <name>out</name>
    <type>float</type>
  </source>
</block>

为什么我不能从Scope Sink2获得输出?我忘了在四个文件里写些什么了?这是我的块的input_items缓冲区的问题吗?

当使用通用block而不是sync_block时,您的general_work必须调用consume,指示您已经读取了多少项,否则您自己块的输入缓冲区(=throttle的输出缓冲区(会很快填满,throttle无法向其中放入新样本,流图也会停止。此时,您的作用域接收器可能根本没有足够的输入来显示任何内容。

我认为对于您的用例,只使用sync_block会容易得多,因此,这是正确的方法。

我想给你指出我今天写的一封邮件,讨论GNU无线电邮件列表。它解释了这背后的缓冲空间概念。

              /->A->Null Sink
File Source -|
              ->B->File Sink

[…]

因此,下面的机制是:File Source的输出缓冲区是A的输入缓冲器和B的输入缓冲器。没有存储器复制在这里

文件源有一个带写指针的缓冲区写入程序,a和B有它们自己指向该缓冲区的读取指针。

当文件源产生N个项目时,写入指针前进N。

类似地,当A消耗M个项目时,A的读取指针前进M。

当调用(general_(work时,input_items缓冲区实际上是只是一个指针(start_of_buffer+读取指针(。等效地output_items缓冲区实际上只是指向写指针。

文件源只允许产生太多的项目,以至于写指针不会超过最小读指针,因为在这种情况下,它会覆盖下游块尚未消耗的样本。