discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Derive OOT header format from header_format_defau


From: Justin Hamilton
Subject: Re: [Discuss-gnuradio] Derive OOT header format from header_format_default
Date: Thu, 6 Apr 2017 16:44:40 +1000

Hi everyone,

I was able to solve this issue by running nm -C -u libgnuradio-cognitiveSDR.so | grep header_format_cognitive in my custom module's folder "gr-cognitiveSDR/build/lib", which identified a function accidentally declared in my class' header file, which wasn't implemented in the source code and was trying to override the base class' corresponding function. I simply removed this declaration and rebuilt/installed.

To make my new header format work with the protocol_formatter_async block I also had to remove "typedef boost::shared_ptr<header_format_cognitive> sptr" from my header file so that my class would instead inherit the required sptr from header_format_base to satisfy the requirements of the protocol_formatter_async block's make method.

The issue I am facing now is attempting to make my format's custom setter and getter functions accessible by python GUI elements and variables inside GRC. Currently it appears that after creating the formatter object (hdr_format) and using it in the protocol formatter, I can't, for example, call hdr_format.setter_function() to update some property in the header. I get the following error:

Value "hdr_format.set_bps(2)" cannot be evaluated:
    'header_format_base_sptr' object has no attribute 'set_bps'


Currently all my functions are declared as virtual both in "gr-cognitiveSDR/include/cognitiveSDR/header_format_cognitive.h" and "gr-cognitiveSDR/lib/header_format_cognitive.h" (not pure virtual ie. "bool setter_function() = 0" as this prevents me from even instantiating the object ), and defined in the source "gr-cognitiveSDR/lib/header_format_cognitive.cc".

Any ideas? Do I need to add something to the SWIG config to make these callback functions accessible?

Cheers.

On Fri, Mar 31, 2017 at 3:56 PM, Justin Hamilton <address@hidden> wrote:
Hi everyone,

I'm creating a custom header format 'header_format_cognitive' derived from 'header_format_default'. I'm adding extra info to the default header, very similar to the way the child class 'header_format_counter' adds bits/symbol to the default. I'm creating my class as an OOT module named 'cognitiveSDR'.

I'm running into what appears to be a common issue, with people previously creating spin-offs of packet_header_default, including gr-ieee-802.11.
https://www.mail-archive.com/address@hidden/msg50789.html
http://gnuradio.4.n7.nabble.com/Trouble-with-SWIG-for-packet-formatter-default-child-class-td52446.html

I was able to compile, install and import my module in GRC, but once I try to create the class using a variable with "cognitiveSDR.header_format_cognitive(..........)", I get the message:

"Value "cognitiveSDR.header_format_cognitive(..........)" cannot be evaluated: 'module' object has no attribute 'header_format_cognitive'"

To give some context, normally when creating a standard header format object using a GRC variable I call "digital.header_format_counter(preamble_b, 3, Const_PLD.bits_per_symbol())"

Steps taken so far:
1. Created my new module cognitiveSDR with gr_modtool
2. Added header_format_cognitive (c++) using gr_modtool as type 'noblock'
3. Fleshed out the .cc and .h files using a combination of header_format_counter, header_format_crc and my own functions
4. Made sure to #include <gnuradio/digital/header_format_default.h> in the header file
5. Used digital::header_format_default as the parent class in the class declaration since it's now in separate namespace to 'digital'
6. Modified set(GR_REQUIRED_COMPONENTS RUNTIME DIGITAL) in CMakeLists.txt
6. Modified the SWIG file as shown below

Are there any modifications that I should make to the default CMakeLists.txt file generated for the module or additional changes to the SWIG file in order to make my class accessible inside GRC? I assume the parent and child classes are linking up properly since cmake, make and install succeed.

Thanks for you help! Cheers.
Justin

cognitiveSDR_swig.i
-------------------------------------------------------------------------------------------------------------------
/* -*- c++ -*- */

#define COGNITIVESDR_API
#define DIGITAL_API

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

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

%{
#include "cognitiveSDR/header_format_cognitive.h"
%}

%include "gnuradio/digital/header_format_base.h"
%include "gnuradio/digital/header_format_default.h"

%include "cognitiveSDR/header_format_cognitive.h"

%template(header_format_cognitive_sptr) boost::shared_ptr<gr::cognitiveSDR::header_format_cognitive>;
%pythoncode %{
header_format_cognitive_sptr.__repr__ = lambda self: "<header_format_cognitive>"
header_format_cognitive = header_format_cognitive .make;
%}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]