[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss-gnuradio] Instantiating a C++ object derived from `boost::enabl
From: |
Frank Restuccia |
Subject: |
[Discuss-gnuradio] Instantiating a C++ object derived from `boost::enable_shared_from_this' from Python |
Date: |
Mon, 18 Dec 2017 07:59:23 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 |
Hi all,
I am trying to instantiate a C++ object from Python as follows.
This is my .H file:
/***********************/
#ifndef INCLUDED_COMMON_MODULES_COVERT_CONSTELLATION_H
#define INCLUDED_COMMON_MODULES_COVERT_CONSTELLATION_H
#include <common_modules/api.h>
#include <gnuradio/gr_complex.h>
#include <vector>
#include <boost/enable_shared_from_this.hpp>
#include <gnuradio/math.h>
namespace gr {
namespace common_modules {
/*!
* \brief Covert constellation
*
*/
class covert_constellation;
typedef boost::shared_ptr<covert_constellation> constellation_sptr;
class COMMON_MODULES_API covert_constellation : public
boost::enable_shared_from_this<covert_constellation> {
protected:
std::vector<gr_complex> d_points;
public:
covert_constellation(
std::vector<gr_complex> points
);
covert_constellation();
virtual ~covert_constellation();
gr_complex get_point_from_value(unsigned int value);
virtual unsigned int decision_maker(const gr_complex
*sample) = 0;
constellation_sptr base() { return shared_from_this(); }
};
class COMMON_MODULES_API constellation_cbpsk : public
covert_constellation {
public:
typedef boost::shared_ptr<constellation_cbpsk> sptr;
// public constructor
static sptr make();
~constellation_cbpsk();
unsigned int decision_maker(const gr_complex *sample);
protected:
constellation_cbpsk();
};
class COMMON_MODULES_API constellation_cqpsk : public
covert_constellation {
public:
typedef boost::shared_ptr<constellation_cqpsk> sptr;
// public constructor
static sptr make();
~constellation_cqpsk();
unsigned int decision_maker(const gr_complex *sample);
protected:
constellation_cqpsk();
};
} // namespace common_modules
} // namespace gr
#endif /* INCLUDED_COMMON_MODULES_COVERT_CONSTELLATION_H */
/*****************************/
And this is my .CC file:
/****************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include <common_modules/covert_constellation.h>
#define SQRT_TWO 0.707107
namespace gr {
namespace common_modules {
covert_constellation::
covert_constellation() { }
covert_constellation::
~covert_constellation() { }
gr_complex
covert_constellation::
get_point_from_value(
unsigned int value)
{
return d_points[value];
}
constellation_cbpsk::sptr
constellation_cbpsk::make()
{
return constellation_cbpsk::sptr(new constellation_cbpsk());
}
constellation_cbpsk::constellation_cbpsk()
{
d_points.resize(2);
d_points[0] = gr_complex(-1, 0);
d_points[1] = gr_complex(1, 0);
}
constellation_cbpsk::~constellation_cbpsk()
{
}
unsigned int
constellation_cbpsk::decision_maker(const gr_complex *sample)
{
return (real(*sample) > 0);
}
/********************************************************************/
constellation_cqpsk::sptr
constellation_cqpsk::make()
{
return constellation_cqpsk::sptr(new constellation_cqpsk());
}
constellation_cqpsk::constellation_cqpsk()
{
// Gray-coded
d_points.resize(4);
d_points[0] = gr_complex(-SQRT_TWO, -SQRT_TWO);
d_points[1] = gr_complex(SQRT_TWO, -SQRT_TWO);
d_points[2] = gr_complex(-SQRT_TWO, SQRT_TWO);
d_points[3] = gr_complex(SQRT_TWO, SQRT_TWO);
}
constellation_cqpsk::~constellation_cqpsk()
{
}
unsigned int
constellation_cqpsk::decision_maker(const gr_complex *sample)
{
// Real component determines small bit.
// Imag component determines big bit.
return 2*(imag(*sample)>0) + (real(*sample)>0);
}
} /* namespace common_modules */
} /* namespace gr */
/************************/
I am instantiating the module in the Python file as follows:
a = common_modules.constellation_cqpsk()
This is what I am getting:
File "./custom_ofdm_system_covert.py", line 12, in <module>
from custom_ofdm_txer_covert import custom_ofdm_txer_covert
File
"/home/frank/Documents/reconfigurable_ofdm/gr-custom_tx_ofdm/python/custom_ofdm_txer_covert.py",
line 14, in <module>
import common_modules_swig as common_modules
File
"/home/frank/Documents/reconfigurable_ofdm/gr-common_modules/build/swig/common_modules_swig.py",
line 238, in <module>
constellation_cbpsk = constellation_cbpsk.make;
NameError: name 'constellation_cbpsk' is not defined
However, I am able to use constellation_cbpsk perfectly from C++. So I
am guessing it's a SWIG problem.
Any ideas?
Thanks,
Frank
- [Discuss-gnuradio] Instantiating a C++ object derived from `boost::enable_shared_from_this' from Python,
Frank Restuccia <=