我正试图使用gr_motool.py在gnuradio中创建一个新的DSP块。gnurradio版本为3.3.0。我在包含文件夹中的abc.h文件中有以下代码
ifndef INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H
#define INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H
#include <gr_block.h>
namespace gr {
namespace energydetector {
class ENERGYDETECTOR_API local_sensing_ff : virtual public gr_block
{
private:
public:
typedef boost::shared_ptr<local_sensing_ff> sptr;
float d_pfa; int d_L; int d_samples;
static sptr make(float pfa=0.01,int L=16,int samples=1000);
virtual void set_pfa(float input_a) { d_pfa = input_a; }
virtual int get_pfa() { return d_pfa; }
virtual void set_L(int input_b) { d_L = input_b; }
virtual int get_L() { return d_L; }
virtual void set_samples(int input_c) { d_samples = input_c; }
virtual int get_samples() { return d_samples; }
};
} // namespace energydetector
} // namespace gr
#endif /* INCLUDED_ENERGYDETECTOR_LOCAL_SENSING_FF_H */
上述头文件的实现类为:
#ifndef INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H
#define INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H
#include <energy-detector/local_sensing_ff.h>
namespace gr {
namespace energydetector {
class local_sensing_ff_impl : public local_sensing_ff
{
private:
float d_pfa; int d_L; int d_samples;
public:
local_sensing_ff_impl(float pfa,int L,int samples);
~local_sensing_ff_impl();
void set_pfa(float input_a) { d_pfa = input_a; }
int get_pfa() { return d_pfa; }
void set_L(int input_b) { d_L = input_b; }
int get_L() { return d_L; }
void set_samples(int input_c) { d_samples = input_c; }
int get_samples() { return d_samples; }
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 energy-detector
} // namespace gr
#endif /* INCLUDED_ENERGY-DETECTOR_LOCAL_SENSING_FF_IMPL_H */
SWIG文件是abc.i作为
#define ENERGY_DETECTOR_API
%include "gnuradio.i" // the common stuff
%include "energydetector_swig_doc.i"
%{
#include "energydetector/local_sensing_ff.h"
%}
%include "energydetector/local_sensing_ff.h"
GR_SWIG_BLOCK_MAGIC2(energydetector, local_sensing_ff);
它成功构建,但在执行时我收到以下错误:
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
AttributeError: No constructor defined
请帮我调试一下。
最后我知道这是由于版本不受支持。gr_motool.py仅由GNURadio 3.6或更高版本支持。
虽然我们可以构建块并在GRC中使用它,但不确定为什么它不能工作。它必须是由gr_motool.py生成的代码结构,不适用于3.3.0版本的
所以任何来问这个问题的人都要确保你有GNURadio 3.6及以上版本。但是,如果有人通过修改gr_motool.py或任何代码解决了这个问题,那么请在这个问题中告诉我们。
当我从代码中删除"from gnradio.gr import*"时,这个问题就会消失
SWIG不会为没有公共构造函数或抽象的类生成构造函数。
请参阅http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_nn9