我想爲我自己的通用塊編寫一個輸入和一個輸出,用於C++中的GNU無線電。我使用gr_modtool按照gnuradio.org中的步驟操作。它可以很好地工作。但是當我用相同的源連接其他塊(範圍sink2)時,其中沒有輸出。GNU無線電從其他塊與我自己的OOT塊並行輸出
我連接流圖作爲:
/-> Scope Sink2
Signal Source -> Throttle -|
\-> my own block -> Scope Sink1
我使用GNU無線電播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>
爲什麼我C注意從Scope Sink2獲取輸出?我忘了在四個文件中寫什麼?這是關於我的塊的input_items緩衝區的問題嗎?
非常感謝!使用'消耗'後,我收到範圍sink2的信號。 – Betty