【发布时间】:2016-02-27 02:43:20
【问题描述】:
我想用 1 个输入端口和 0 个输出端口为 C++ 中的 GNU Radio 编写自己的接收器块。我阅读并遵循了此处描述的步骤:
- http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide
- http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules
- http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModulesConfig
- http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorial_GNU_Radio_in_C++
我正在使用
- Ubuntu 14.04.3 LTS
- Eclipse 4.5.1
- CDT 8.8.0.201509131935
- GNU Radio 3.7.8
我使用 gr_modtool 创建了新模块“jammertrap”。在其中,我创建了“bandpower”块。这其中创建了三个文件
- /home/sdr/gnuradio/gr-jammertrap/include/jammertrap/ 内的bandpower.h
- bandpower_impl.h 在 /home/sdr/gnuradio/gr-jammertrap/lib/ 内
- /home/sdr/gnuradio/gr-jammertrap/lib/ 内的bandpower_impl.cc
bandpower.h:
#ifndef INCLUDED_JAMMERTRAP_BANDPOWER_H
#define INCLUDED_JAMMERTRAP_BANDPOWER_H
#include <jammertrap/api.h>
#include <gnuradio/block.h>
namespace gr
{
namespace jammertrap
{
class JAMMERTRAP_API bandpower : virtual public gr::block
{
public:
typedef boost::shared_ptr<bandpower> sptr;
// Return a shared_ptr to a new instance of jammertrap::bandpower.
// To avoid accidental use of raw pointers, jammertrap::bandpower's constructor is in a private implementation class.
// jammertrap::bandpower::make is the public interface for creating new instances.
static sptr make();
};
} // namespace jammertrap
} // namespace gr
#endif /* INCLUDED_JAMMERTRAP_BANDPOWER_H */
bandpower_impl.h:
#ifndef INCLUDED_JAMMERTRAP_BANDPOWER_IMPL_H
#define INCLUDED_JAMMERTRAP_BANDPOWER_IMPL_H
#include <jammertrap/bandpower.h>
namespace gr
{
namespace jammertrap
{
class bandpower_impl : public bandpower
{
private:
double d_bandpower_;
public:
bandpower_impl();
~bandpower_impl();
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
// Where all the action really happens
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items);
// Returns the calculated RMS Bandpower
double get_bandpower();
};
} // namespace jammertrap
} // namespace gr
#endif /* INCLUDED_JAMMERTRAP_BANDPOWER_IMPL_H */
bandpower_impl.cc:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "bandpower_impl.h"
namespace gr
{
namespace jammertrap
{
bandpower::sptr
bandpower::make()
{
return gnuradio::get_initial_sptr (new bandpower_impl());
}
// The private constructor
bandpower_impl::bandpower_impl() : gr::block("bandpower", gr::io_signature::make(1, 1, sizeof(gr_complex)), gr::io_signature::make(0, 0, 0))
{
d_bandpower_ = 0;
}
// Our virtual destructor
bandpower_impl::~bandpower_impl()
{}
void bandpower_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required)
{
// ninput_items_required[0] = noutput_items;
}
int bandpower_impl::general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items)
{
const gr_complex *in = (const gr_complex *) input_items[0];
d_bandpower_ = 0;
for(int i = 0; i < noutput_items; i++)
{
d_bandpower_ += (in[i].real() * in[i].real()) + (in[i].imag() * in[i].imag());
}
d_bandpower_ = sqrt(d_bandpower_ / noutput_items);
// Tell runtime system how many input items we consumed on each input stream.
consume_each (noutput_items);
// Tell runtime system how many output items we produced
return noutput_items;
}
double bandpower_impl::get_bandpower()
{
return d_bandpower_;
}
} /* namespace jammertrap */
} /* namespace gr */
为了制作和安装这个新块,我在 /home/sdr/gnuradio/gr-jammertrap/build 中输入了以下命令:
- cmake ../
- 制作
- make test // 结果:“test_jammertrap”和“qa_bandpower”成功通过
- sudo make install
这个 sink 块“bandpower”应该接收 gr_complex 类型的项目,计算平均接收功率并将这个值存储在私有成员“d_bandpower_”中。 另外我定义了方法“get_bandpower()”来获取存储的值。
在另一个程序中,我用两个块创建了一个流程图类
osmosdr::source:sptr osmosdr_source_;
gr::jammertrap::bandpower::sptr bandpower_measurement_;
并用实例化它们
osmosdr_source_ = osmosdr::source::make(std::string());
bandpower_measurement_ = gr::jammertrap::bandpower::make();
启动流程图后,我想通过调用 get_bandpower() 来读取计算的带宽,但 Eclipse 没有显示方法“bandpower_measurement_->get_bandpower()”
我忘记在 bandpower.h、bandpower_impl.h 或 bandpower_impl.cc 中写什么?
【问题讨论】:
标签: c++ eclipse ubuntu block gnuradio