Forum: GNU Radio Message Passing

739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 08:13
(Received via mailing list)
Dear gurus,

I am learning gnuradio Message Passing feature, but couldn't get
desirable
result.
The Message seems published successfully, but not subscribed by the
Message
receiver.
How to correct the error ..?

The message sender block:

    // constructor
        message_source1_impl::message_source1_impl()
          : gr::sync_block("message_source1",
                  gr::io_signature::make(0, 0, 0),
                  gr::io_signature::make( 1, 1, sizeof(int)) )
        {
            message_port_register_out( pmt::mp("print") );
        }

        // send_message1
        void
        message_source1_impl::send_message1()
        {
            std::cout << "message_source1_impl::send_message():
invoked"
<< std::endl;
            pmt::pmt_t str0 = pmt::string_to_symbol(
std::string("Welcome
2014"));
            message_port_pub( pmt::mp("print"), str0 );
        }

        // work
        int
        message_source1_impl::work(int noutput_items,
                  gr_vector_const_void_star &input_items,
                  gr_vector_void_star &output_items)
        {
            int *out = (int *) output_items[0];
            for (int i=0; i < noutput_items; i++)
                out[i] = (i+1) * (i+1);

            send_message1();
            return noutput_items;
        }



The message receiver block:

    // constructor
        message_sink1_impl::message_sink1_impl()
          : gr::sync_block("message_sink1",
                  gr::io_signature::make(0, 0, 0),
                  gr::io_signature::make( 1, 1, sizeof(int)) )
        {
            message_port_register_in( pmt::mp("print") );
            set_msg_handler( pmt::mp("print"), boost::bind(
&message_sink1_impl::handler1, this, _1 ) );
        }

        // message handler
        void
        message_sink1_impl::handler1( pmt::pmt_t myMessage )
        {
            std::cout << "message_sink1_impl::handler1():  invoked" <<
std::endl;
            pmt::print( myMessage );
        }

        // work
        int
        message_sink1_impl::work(int noutput_items,
                  gr_vector_const_void_star &input_items,
                  gr_vector_void_star &output_items)
        {
            int *out = (int *) output_items[0];
            for (int i=0; i < noutput_items; i++)
                out[i] = i+1;

            return noutput_items;
        }



Flow graph execution output:
    Executing: "/home/mmkk/gnuradio/gr-activecat/apps/top_block.py"
    message_source1_impl::send_message():  invoked
    message_source1_impl::send_message():  invoked
    message_source1_impl::send_message():  invoked
    message_source1_impl::send_message():  invoked
    message_source1_impl::send_message():  invoked
B4ffbc711addde4c649b1ed526df6157?d=identicon&s=25 Martin Braun (Guest)
on 2014-05-14 10:27
(Received via mailing list)
On 14.05.2014 08:11, Activecat wrote:
> Dear gurus,
>
> I am learning gnuradio Message Passing feature, but couldn't get
> desirable result.
> The Message seems published successfully, but not subscribed by the
> Message receiver.
> How to correct the error ..?

Just to make sure: You did connect the ports in your flow graph?

That said, I've seen something like this recently. Maybe there's a
bug... needs investigating.

M
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 11:16
(Received via mailing list)
On Wed, May 14, 2014 at 4:26 PM, Martin Braun
<martin.braun@ettus.com>wrote:

>
> Just to make sure: You did connect the ports in your flow graph?
> That said, I've seen something like this recently. Maybe there's a bug...
> needs investigating.
> M
>

Both blocks (message sender block, message receiver block) are source
blocks, both are directly connected to the inputs of a divider blocks,
i.e. the message receiver block is not at the downstream of the message
sender block.  I guess this is ok because Message Passing is for
downstream
blocks to communicate to upstream blocks. Is this correct?

This is part of the top_block.py generated by GRC, to illustrate the
flowgraph.

        ##################################################
        # Blocks
        ##################################################
        self.blocks_head_0 = blocks.head(gr.sizeof_int*1, 10)
        self.blocks_divide_xx_0 = blocks.divide_ii(1)
        self.activecat_message_source1_0 = activecat.message_source1()
        self.activecat_message_sink1_0 = activecat.message_sink1()
        self.activecat_integer_sink3_0 = activecat.integer_sink3(False,
True, "Integer1")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_divide_xx_0, 0), (self.blocks_head_0,
0))
        self.connect((self.blocks_head_0, 0),
(self.activecat_integer_sink3_0, 0))
        self.connect((self.activecat_message_source1_0, 0),
(self.blocks_divide_xx_0, 0))
        self.connect((self.activecat_message_sink1_0, 0),
(self.blocks_divide_xx_0, 1))

System info:
Gnuradio version = 3.7.3
OS =  Debian jessie/sid, SMP Debian 3.13.10-1 x86_64 GNU/Linux
B4ffbc711addde4c649b1ed526df6157?d=identicon&s=25 Martin Braun (Guest)
on 2014-05-14 11:28
(Received via mailing list)
On 14.05.2014 11:14, Activecat wrote:
> Both blocks (message sender block, message receiver block) are source
> blocks, both are directly connected to the inputs of a divider blocks,
> i.e. the message receiver block is not at the downstream of the message
> sender block.  I guess this is ok because Message Passing is for
> downstream blocks to communicate to upstream blocks. Is this correct?

The message passing API doesn't really care about who's upstream for the
streaming API.

>          self.activecat_integer_sink3_0 = activecat.integer_sink3(False,
>          self.connect((self.activecat_message_sink1_0, 0),
> (self.blocks_divide_xx_0, 1))

There's no msg_connect() call here -- that would be your problem.

M
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 11:37
(Received via mailing list)
On Wed, May 14, 2014 at 5:26 PM, Martin Braun
<martin.braun@ettus.com>wrote:

> There's no msg_connect() call here -- that would be your problem.
> M
>

I build the flowgraph using GRC. How to make correction?
The complete top_block.py is as follows.

#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Top Block
# Generated: Wed May 14 17:30:37 2014
##################################################

from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import activecat
import wx

class top_block(grc_wxgui.top_block_gui):

    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path =
"/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.blocks_head_0 = blocks.head(gr.sizeof_int*1, 10)
        self.blocks_divide_xx_0 = blocks.divide_ii(1)
        self.activecat_message_source1_0 = activecat.message_source1()
        self.activecat_message_sink1_0 = activecat.message_sink1()
        self.activecat_integer_sink3_0 = activecat.integer_sink3(False,
True, "Integer1")

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_divide_xx_0, 0), (self.blocks_head_0,
0))
        self.connect((self.blocks_head_0, 0),
(self.activecat_integer_sink3_0, 0))
        self.connect((self.activecat_message_source1_0, 0),
(self.blocks_divide_xx_0, 0))
        self.connect((self.activecat_message_sink1_0, 0),
(self.blocks_divide_xx_0, 1))


# QT sink close method reimplementation

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate

if __name__ == '__main__':
    import ctypes
    import sys
    if sys.platform.startswith('linux'):
        try:
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
            x11.XInitThreads()
        except:
            print "Warning: failed to XInitThreads()"
    parser = OptionParser(option_class=eng_option, usage="%prog:
[options]")
    (options, args) = parser.parse_args()
    tb = top_block()
    tb.Start(True)
    tb.Wait()
0817fa933c74eec9b3fcf3a04e16f418?d=identicon&s=25 Sylvain Munaut (Guest)
on 2014-05-14 12:05
(Received via mailing list)
Hi,

>> There's no msg_connect() call here -- that would be your problem.
>> M
>
>
> I build the flowgraph using GRC. How to make correction?
> The complete top_block.py is as follows.

Did you define the message port in the .grc XML file for your blocks ?

Something like :

  <sink>
    <name>portname</name>
    <type>message</type>
    <optional>1</optional>
  </sink>

Then they should show as message port in the GRC UI and you need to
connect them in the GUI.


Cheers,

   Sylvain
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 12:20
(Received via mailing list)
On Wed, May 14, 2014 at 5:50 PM, Sylvain Munaut <246tnt@gmail.com>
wrote:

> Then they should show as message port in the GRC UI and you need to
> connect them in the GUI.
>

This works: (this add additional port in gray color)
  <source>
    <name>print</name>
    <type>message</type>
    <optional>1</optional>
  </source>


Whereas this doesn't work: (the block becomes disappeared in the GRC)
  <sink>
    <name>print</name>
    <type>message</type>
    <optional>1</optional>
  </sink>

Then how to define the message sink port?
B4ffbc711addde4c649b1ed526df6157?d=identicon&s=25 Martin Braun (Guest)
on 2014-05-14 12:29
(Received via mailing list)
On 14.05.2014 11:35, Activecat wrote:
>
> On Wed, May 14, 2014 at 5:26 PM, Martin Braun <martin.braun@ettus.com
> <mailto:martin.braun@ettus.com>> wrote:
>
>     There's no msg_connect() call here -- that would be your problem.
>     M
>
>
> I build the flowgraph using GRC. How to make correction?

To correct this, connect the message ports.

M
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 12:31
(Received via mailing list)
On Wed, May 14, 2014 at 6:18 PM, Activecat <activecat@gmail.com> wrote:

>>   </sink>
>   </source>
>
> Whereas this doesn't work: (the block becomes disappeared in the GRC)
>   <sink>
>     <name>print</name>
>     <type>message</type>
>     <optional>1</optional>
>   </sink>
>
> Then how to define the message sink port?
>


I have then tested few combinations, it seems that a source block cannot
have a message sink port.
Is there such a restriction ..?
79b27563469f31314903878209a41971?d=identicon&s=25 Koslowski, Sebastian (CEL) (Guest)
on 2014-05-14 12:51
(Received via mailing list)
Attachment: signature.asc (884 Bytes)
On 05/14/2014 12:29 PM, Activecat wrote:
> I have then tested few combinations, it seems that a source block cannot
> have a message sink port.
> Is there such a restriction ..?

Not that I know of...

<?xml version='1.0' encoding='ASCII'?>
<block>
  <name>Test</name>
  <key>message_sink_complex_source_test</key>
  <category>Custom</category>
  <make>None</make>
  <sink>
    <name>in</name>
    <type>message</type>
    <optional>True</optional>
  </sink>
  <source>
    <name>out</name>
    <type>complex</type>
  </source>
</block>

Works here (GR version: recent master).

(This is a dummy block. The generated FG wont run)

Sebastian

--
Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Sebastian Koslowski
Research Associate

Kaiserstrae 12
Building 05.01
76131 Karlsruhe, Germany

Phone: +49 721 608-46275
Fax:   +49 721 608-46071
Email: sebastian.koslowski@kit.edu
Web:   http://www.cel.kit.edu/

KIT  University of the State of Baden-Wuerttemberg and National
Research Center of the Helmholtz Association
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-14 13:08
(Received via mailing list)
On Wed, May 14, 2014 at 6:49 PM, Koslowski, Sebastian (CEL) <
sebastian.koslowski@kit.edu> wrote:

>   <key>message_sink_complex_source_test</key>
>   </source>
> </block>
>
>
I retried by putting the definition of <sink></sink> on top of
<source></source> in the xml file, it works.
It seems that the "sink" definition must be placed on top of "source" ..

Problem solved, thank everyone !
C539637020fd56193dd6daec746c4a84?d=identicon&s=25 Tom Rondeau (Guest)
on 2014-05-14 16:26
(Received via mailing list)
On Wed, May 14, 2014 at 7:06 AM, Activecat <activecat@gmail.com> wrote:

>>
>>   </sink>
>
> Problem solved, thank everyone !
>


Yes, this is the strictness of the XML DTD. Glad you got it working.

Tom
739a038d5a03d5448114b3615e2caedc?d=identicon&s=25 Activecat K. (activecat_k)
on 2014-05-16 07:03
(Received via mailing list)
On Wed, May 14, 2014 at 10:25 PM, Tom Rondeau <tom@trondeau.com> wrote:

>>
>
> Yes, this is the strictness of the XML DTD. Glad you got it working.
>  Tom
>

Thank you very much.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.