discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] Implementing callbacks in custom blocks


From: Marcus Müller
Subject: Re: [Discuss-gnuradio] Implementing callbacks in custom blocks
Date: Sun, 20 Jul 2014 13:11:52 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

In addition to what Johannes said:

Make sure that you have

    virtual void set_gain(float gain) = 0;

in your var_gain.h and

    virtual void set_gain(float gain);

in your var_gain_impl.h, as well as

    void
    var_gain_impl::set_gain(float gain) {
        ...
    }

in your var_gain_impl.cc.

The idea is that the user of your block only sees var_gain and its public attributes, while you and your module work in var_gain_impl to make it easier for swig and readers to understand your "interface" for using that class and giving you the freedom to have whatever methods you'd need in the _impl without asking yourself if potential users might be confused by these methods.

And another side note for future readers: I assume you implement this as an exercise, which is a very good idea!
If someone just needs functionality of this kind, there's multiply_const_??.

Greetings,
Marcus

On 20.07.2014 12:24, Johannes Demel wrote:
hey,

I'm not entirely sure if it still holds true, but that might be an
error related to SWIG. For some reason virtual header files don't get
swig'ed again unless explicitly triggered. Just do a 'make clean' and
'make' again. That should rebuild your module from scratch and also
swig your headers.

happy hacking
Johannes

On 20.07.2014 07:58, jsam45 wrote:
> Using gr_modtool, I am trying to make a simple Gain block (called
> var_gain) which multiplies the input with a constant. I have a
> private variable called d_gain in the var_gain_impl class and a
> public function set_gain(float gain) which sets the value of d_gain
> to the argument. I modified the xml file by adding the line
> <callback>set_gain($gain)</callback> after the <make> line.

> During execution, gain value does not change even after changing it
> through a WX Slider. If I run it from terminal, I am getting the
> following error - Traceback (most recent call last): File
> "/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
> line 180, in _handle def _handle(self, event): self[INT_KEY] =
> self._slider.GetValue() File
> "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/pubsub.py",
> line 52, in __setitem__ sub(val) File
> "/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
> line 138, in _translate_internal_to_external if self._callback:
> self._callback(self[EXT_KEY]) File "top_block.py", line 102, in
> set_gg self.fsk_var_gain_0.set_gain(self.gg) AttributeError:
> 'var_gain_sptr' object has no attribute 'set_gain'

> I tried looking at some in-built blocks to see how callback is
> implemented. Then I saw that the in-built blocks have pure virtual
> functions in the include/module_name/var_gain.h header file. I
> tried implementing that but the result is still the same. What am I
> missing here?



> -- View this message in context:
> http://gnuradio.4.n7.nabble.com/Implementing-callbacks-in-custom-blocks-tp49462.html


Sent from the GnuRadio mailing list archive at Nabble.com.

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

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




reply via email to

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