Monday, December 18, 2017

Re: [Discuss-gnuradio] Instantiating a C++ object derived from `boost::enable_shared_from_this' from Python

HI Michael,

I have inserted the following code in my common_modules_swig.i file:

/******/

%template(constellation_sptr)
boost::shared_ptr<gr::common_modules::covert_constellation>;

%template(constellation_cbpsk_sptr)
boost::shared_ptr<gr::common_modules::constellation_cbpsk>;
%pythoncode %{
constellation_cbpsk_sptr.__repr__ = lambda self: "<constellation CBPSK>"
constellation_cbpsk = constellation_cbpsk.make;
%}

%template(constellation_cqpsk_sptr)
boost::shared_ptr<gr::common_modules::constellation_cqpsk>;
%pythoncode %{
constellation_cqpsk_sptr.__repr__ = lambda self: "<constellation CQPSK>"
constellation_cqpsk = constellation_cqpsk.make;
%}

/*************/

However, I am still getting the following error:

Traceback (most recent call last):
  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 258, in <module>
    constellation_cbpsk = constellation_cbpsk.make;
NameError: name 'constellation_cbpsk' is not defined

Any ideas? This is my SWIG file now:

/*********/

/* -*- c++ -*- */

#define COMMON_MODULES_API

%include "gnuradio.i"            // the common stuff

//load generated python docstrings
%include "common_modules_swig_doc.i"

%{
#include "common_modules/fft.h"
#include "common_modules/packet_header_default.h"
#include "common_modules/packet_header_ofdm.h"
#include "common_modules/check_make_crc32.h"
#include "common_modules/repack_bits.h"
#include "common_modules/tag_debugger.h"
#include "common_modules/covert_constellation.h"
%}

%template(constellation_sptr)
boost::shared_ptr<gr::common_modules::covert_constellation>;

%template(constellation_cbpsk_sptr)
boost::shared_ptr<gr::common_modules::constellation_cbpsk>;
%pythoncode %{
constellation_cbpsk_sptr.__repr__ = lambda self: "<constellation CBPSK>"
constellation_cbpsk = constellation_cbpsk.make;
%}

%template(constellation_cqpsk_sptr)
boost::shared_ptr<gr::common_modules::constellation_cqpsk>;
%pythoncode %{
constellation_cqpsk_sptr.__repr__ = lambda self: "<constellation CQPSK>"
constellation_cqpsk = constellation_cqpsk.make;
%}

%include "common_modules/fft.h"
GR_SWIG_BLOCK_MAGIC2(common_modules, fft);
%include "common_modules/packet_header_default.h"
%include "common_modules/packet_header_ofdm.h"
%include "common_modules/check_make_crc32.h"
GR_SWIG_BLOCK_MAGIC2(common_modules, check_make_crc32);
%include "common_modules/repack_bits.h"
GR_SWIG_BLOCK_MAGIC2(common_modules, repack_bits);
%include "common_modules/tag_debugger.h"
GR_SWIG_BLOCK_MAGIC2(common_modules, tag_debugger);
%include "common_modules/covert_constellation.h"

/*********/


On 12/18/2017 08:54 AM, Michael Dickens wrote:
> Hi Frank - Yes this is a SWIG issue. You need the code as found here: <
> https://github.com/gnuradio/gnuradio/blob/master/gr-digital/swig/constellation.i
>> . There is a specific line for the base class, then a pattern used for
> any inheriting class. Should be self-obvious how to tweak them for your
> specific needs. Hope this is useful! - MLD
>
> On Mon, Dec 18, 2017, at 07:59 AM, Frank Restuccia wrote:
>> I am trying to instantiate a C++ object from Python as follows.
>> [snip]
>> /************************/
>>
>> 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?


_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

No comments:

Post a Comment