AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb' given by Gnuradio Companion
AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb' given by Gnuradio Companion
我还有一个问题。我一直在关注创建 QPSK 解调器的教程。这是 link:https://wiki.gnuradio.org/index.php/Guided_Tutorial_GNU_Radio_in_C%2B%2B
我能够解决一个不同的问题并修复了我收到的警告,但是出现了一个新问题,我似乎无法解决它。这是错误:
Traceback (most recent call last):
File "/home/mariom/gr-tutorial/build/top_block.py", line 191, in <module>
main()
File "/home/mariom/gr-tutorial/build/top_block.py", line 167, in main
tb = top_block_cls()
File "/home/mariom/gr-tutorial/build/top_block.py", line 82, in __init__
self.tutorial_my_qpsk_demod_cb_0 = tutorial.my_qpsk_demod_cb(True)
AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb'
Noramlly 当我看到这个错误时,我想我知道如何解决这个问题并找到模块教程并添加 my_qpsk_demod_cb。这一次,我似乎 运行 陷入了我似乎无法找到正确区域或者我在正确区域中的问题。我知道问题出在我从教程中创建的块中,所以有什么想法吗?这是块代码。
My_qpsk_demod_cb_impl.cc
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "my_qpsk_demod_cb_impl.h"
namespace gr {
namespace tutorial {
my_qpsk_demod_cb::sptr
my_qpsk_demod_cb::make(bool gray_code)
{
return gnuradio::get_initial_sptr
(new my_qpsk_demod_cb_impl(gray_code));
}
/*
* The private constructor
*/
my_qpsk_demod_cb_impl::my_qpsk_demod_cb_impl(bool gray_code)
: gr::block("my_qpsk_demod_cb",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(char))),
d_gray_code(gray_code)
{
}
/*
* Our virtual destructor.
*/
my_qpsk_demod_cb_impl::~my_qpsk_demod_cb_impl()
{
}
void
my_qpsk_demod_cb_impl::forecast(int noutput_items,
gr_vector_int &ninput_items_required)
{
unsigned ninputs = ninput_items_required.size ();
for(unsigned i = 0; i < ninputs; i++)
ninput_items_required[i] = noutput_items;
}
unsigned char
my_qpsk_demod_cb_impl::get_minimum_distances(const gr_complex &sample)
{
if (d_gray_code) {
unsigned char bit0 = 0;
unsigned char bit1 = 0;
// The two left quadrants (quadrature component < 0) have this bit set to 1
if (sample.real() < 0) {
bit0 = 0x01;
}
// The two lower quadrants (in-phase component < 0) have this bit set to 1
if (sample.imag() < 0) {
bit1 = 0x01 << 1;
}
return bit0 | bit1;
} else {
// For non-gray code, we can't simply decide on signs, so we check every single
quadrant.
if (sample.imag() >= 0 and sample.real() >= 0) {
return 0x00;
}
else if (sample.imag() >= 0 and sample.real() < 0) {
return 0x01;
}
else if (sample.imag() < 0 and sample.real() < 0) {
return 0x02;
}
else if (sample.imag() < 0 and sample.real() >= 0) {
return 0x03;
}
}
return 0;
}
int
my_qpsk_demod_cb_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 gr_complex *in = (const gr_complex *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];
gr_complex origin = gr_complex(0,0);
// Perform ML decoding over the input iq data to generate alphabets
for(int i = 0; i < noutput_items; i++)
{
// ML decoder, determine the minimum distance from all constellation points
out[i] = get_minimum_distances(in[i]);
}
// 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;
}
} /* namespace tutorial */
} /* namespace gr */
my_qpsk_demod_cb_impl.h
#ifndef INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H
#define INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H
#include <tutorial/my_qpsk_demod_cb.h>
namespace gr {
namespace tutorial {
class my_qpsk_demod_cb_impl : public my_qpsk_demod_cb
{
private:
bool d_gray_code;
public:
my_qpsk_demod_cb_impl(bool gray_code);
~my_qpsk_demod_cb_impl();
unsigned char get_minimum_distances(const gr_complex &sample);
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
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 tutorial
} // namespace gr
#endif /* INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H */
我认为您缺少 swig/dependencies 或 PYTHONPATH。我有同样的问题,并且能够通过以下修复解决它:
- 安装特定于您的环境的依赖项(包括
swig
):https://wiki.gnuradio.org/index.php/UbuntuInstall#Bionic_Beaver_.2818.04.29_through_Eoan_Ermine_.2819.10.29
- 根据以下步骤配置 PYTHONPATH and/or LD_LIBRARY_PATH:https://wiki.gnuradio.org/index.php/ModuleNotFoundError
(请注意,根据这种情况,顺序可能很重要:https://lists.gnu.org/archive/html/discuss-gnuradio/2016-03/msg00065.html)
我还有一个问题。我一直在关注创建 QPSK 解调器的教程。这是 link:https://wiki.gnuradio.org/index.php/Guided_Tutorial_GNU_Radio_in_C%2B%2B 我能够解决一个不同的问题并修复了我收到的警告,但是出现了一个新问题,我似乎无法解决它。这是错误:
Traceback (most recent call last):
File "/home/mariom/gr-tutorial/build/top_block.py", line 191, in <module>
main()
File "/home/mariom/gr-tutorial/build/top_block.py", line 167, in main
tb = top_block_cls()
File "/home/mariom/gr-tutorial/build/top_block.py", line 82, in __init__
self.tutorial_my_qpsk_demod_cb_0 = tutorial.my_qpsk_demod_cb(True)
AttributeError: module 'tutorial' has no attribute 'my_qpsk_demod_cb'
Noramlly 当我看到这个错误时,我想我知道如何解决这个问题并找到模块教程并添加 my_qpsk_demod_cb。这一次,我似乎 运行 陷入了我似乎无法找到正确区域或者我在正确区域中的问题。我知道问题出在我从教程中创建的块中,所以有什么想法吗?这是块代码。
My_qpsk_demod_cb_impl.cc
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "my_qpsk_demod_cb_impl.h"
namespace gr {
namespace tutorial {
my_qpsk_demod_cb::sptr
my_qpsk_demod_cb::make(bool gray_code)
{
return gnuradio::get_initial_sptr
(new my_qpsk_demod_cb_impl(gray_code));
}
/*
* The private constructor
*/
my_qpsk_demod_cb_impl::my_qpsk_demod_cb_impl(bool gray_code)
: gr::block("my_qpsk_demod_cb",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(char))),
d_gray_code(gray_code)
{
}
/*
* Our virtual destructor.
*/
my_qpsk_demod_cb_impl::~my_qpsk_demod_cb_impl()
{
}
void
my_qpsk_demod_cb_impl::forecast(int noutput_items,
gr_vector_int &ninput_items_required)
{
unsigned ninputs = ninput_items_required.size ();
for(unsigned i = 0; i < ninputs; i++)
ninput_items_required[i] = noutput_items;
}
unsigned char
my_qpsk_demod_cb_impl::get_minimum_distances(const gr_complex &sample)
{
if (d_gray_code) {
unsigned char bit0 = 0;
unsigned char bit1 = 0;
// The two left quadrants (quadrature component < 0) have this bit set to 1
if (sample.real() < 0) {
bit0 = 0x01;
}
// The two lower quadrants (in-phase component < 0) have this bit set to 1
if (sample.imag() < 0) {
bit1 = 0x01 << 1;
}
return bit0 | bit1;
} else {
// For non-gray code, we can't simply decide on signs, so we check every single
quadrant.
if (sample.imag() >= 0 and sample.real() >= 0) {
return 0x00;
}
else if (sample.imag() >= 0 and sample.real() < 0) {
return 0x01;
}
else if (sample.imag() < 0 and sample.real() < 0) {
return 0x02;
}
else if (sample.imag() < 0 and sample.real() >= 0) {
return 0x03;
}
}
return 0;
}
int
my_qpsk_demod_cb_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 gr_complex *in = (const gr_complex *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];
gr_complex origin = gr_complex(0,0);
// Perform ML decoding over the input iq data to generate alphabets
for(int i = 0; i < noutput_items; i++)
{
// ML decoder, determine the minimum distance from all constellation points
out[i] = get_minimum_distances(in[i]);
}
// 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;
}
} /* namespace tutorial */
} /* namespace gr */
my_qpsk_demod_cb_impl.h
#ifndef INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H
#define INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H
#include <tutorial/my_qpsk_demod_cb.h>
namespace gr {
namespace tutorial {
class my_qpsk_demod_cb_impl : public my_qpsk_demod_cb
{
private:
bool d_gray_code;
public:
my_qpsk_demod_cb_impl(bool gray_code);
~my_qpsk_demod_cb_impl();
unsigned char get_minimum_distances(const gr_complex &sample);
// Where all the action really happens
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
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 tutorial
} // namespace gr
#endif /* INCLUDED_TUTORIAL_MY_QPSK_DEMOD_CB_IMPL_H */
我认为您缺少 swig/dependencies 或 PYTHONPATH。我有同样的问题,并且能够通过以下修复解决它:
- 安装特定于您的环境的依赖项(包括
swig
):https://wiki.gnuradio.org/index.php/UbuntuInstall#Bionic_Beaver_.2818.04.29_through_Eoan_Ermine_.2819.10.29 - 根据以下步骤配置 PYTHONPATH and/or LD_LIBRARY_PATH:https://wiki.gnuradio.org/index.php/ModuleNotFoundError
(请注意,根据这种情况,顺序可能很重要:https://lists.gnu.org/archive/html/discuss-gnuradio/2016-03/msg00065.html)