GNU Radio没有来自与我自己的OOT块并行的其他块的输出
GNU Radio no output from other blocks parallel with my own OOT block
我想用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缓冲区实际上只是指向写指针。
文件源只允许产生太多的项目,以至于写指针不会超过最小读指针,因为在这种情况下,它会覆盖下游块尚未消耗的样本。
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 如何在 c++ 中正确读取 GRC 块"Random Source"的字节输出数据到自己的 OOT 块中?
- GNU Radio没有来自与我自己的OOT块并行的其他块的输出