# Insert messages in queues?

**URL:** <https://www.ruby-forum.com/t/insert-messages-in-queues/241530>\
**Category:** GNU Radio\
**Created:** [April 12, 2015, 5:53am UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530 "2015-04-12T05:53:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [April 12, 2015, 5:53am UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530/1 "2015-04-12T05:53:54Z")

</div>

If I’m using a block that has a message port output, is there a way to  
put  
those messages into a message queue? For instance:

self.message\_queue = gr.msg\_queue()  
self.msg\_connect((self.gsm\_control\_channels\_decoder, ‘msgs’),  
(???message\_queue???, 0))

I have used gr.msg\_queue() with blocks.message\_sink() but that only  
accepts  
items such as complex, float, etc. I need to take the messages  
generated by  
any old block and parse them outside the flowgraph.

From what I have read, I thought all blocks that handle messages have  
queues, so shouldn’t I be able to pop them directly out of that block?  
I  
guess I’m confused. Are there two type of message passing; an old one  
that  
uses queues, and a new one that uses PMT?

Thanks,  
Lou

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272.html](http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![madengr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@madengr](https://www.ruby-forum.com/u/madengr)\
**Post date:** [April 12, 2015, 6:27pm UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530/2 "2015-04-12T18:27:36Z")

</div>

On 11.04.2015 20:38, madengr wrote:

> From what I have read, I thought all blocks that handle messages have  
> queues, so shouldn’t I be able to pop them directly out of that block? I  
> guess I’m confused. Are there two type of message passing; an old one that  
> uses queues, and a new one that uses PMT?

Hey Louis,

Yes, there are two ways, and they’re completely different. The old  
message queues will be deprecated soon, so anything with gr.msg\_queue()  
in there will, at one point in the future, stop working.

Look at the Python output of some of the message examples we provide,  
also check out this manual page:  
[http://gnuradio.org/doc/doxygen/page\_msg\_passing.html](http://gnuradio.org/doc/doxygen/page_msg_passing.html)

M

---

<div class="post-metadata">

**Author:** ![madengr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@madengr](https://www.ruby-forum.com/u/madengr)\
**Post date:** [April 13, 2015, 12:38am UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530/3 "2015-04-13T00:38:31Z")

</div>

Thanks Martin. Looking at the gr-blocks/examples/msg\_passing, the  
tutorial  
link, and qa\_msg, I only find examples of posting messages. Those make  
sense, but is there an equivalent to \_post method that pulls messages?

> **[GNU Radio Manual and C++ API Reference: gr::basic\_block Class Reference](https://www.gnuradio.org/doc/doxygen/classgr_1_1basic__block.html)**

From the above docs, I see the delete\_head\_blocking, which is maybe what  
I  
want. If I have a tagged stream to PDU like below, how do I pull the  
message?

sink=blocks.tagged\_stream\_to\_pdu(blocks.float\_t, “packet\_len”)  
sink.to\_basic\_block.???

Lou

Martin B.-2 wrote

> M
> 
> * * *
> 
> Discuss-gnuradio mailing list

> Discuss-gnuradio@

> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272p53277.html](http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272p53277.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![madengr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@madengr](https://www.ruby-forum.com/u/madengr)\
**Post date:** [April 13, 2015, 4:57pm UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530/4 "2015-04-13T16:57:14Z")

</div>

Martin,

Yes, pop them outside the block, but also outside of the flow graph.  
Exactly reverse of the last example “Posting from External Sources”  
here:

[http://gnuradio.org/doc/doxygen/page\_msg\_passing.html](http://gnuradio.org/doc/doxygen/page_msg_passing.html)

“The last feature of the message passing architecture to discuss here is  
how  
it can be used to take in messages from an external source. We can call  
a  
block’s gr::basic\_block::\_post method directly and pass it a message. So  
any  
block with an input message port can receive messages from the outside  
in  
this way.”

I want to take any block with an output message port and \_pull that  
message  
to the outside (of the flow so I can process it in Python).

Presently, with the old queued messaging system, I can use  
blocks.message\_sink() to take an item into a message queue I can access  
outside the flow. Since this will be deprecated, I’d want to use  
blocks.tagged\_stream\_to\_pdu() to generate a message, but don’t see a way  
to  
get those messages stored into a FIFO (queue) and access them outside  
the  
flow.

As you suggest, maybe the solution is to develop a block, with an input  
message port, that performs the callback and stores those messages in a  
FIFO. From browsing the documentation, it looks like the message\_debug  
block will store up messages (I haven’t attempted to read those  
messages),  
but I’d be worried about overflows. I guess the ideal was to do it  
without  
developing or modifying any blocks.

Though looking at line 278 of usrp\_spectrum\_sense.py, when the message  
queues are deprecated, what would you do to get the data out of the  
flow? I  
assume blocks.bin\_statistics\_f() would have to be re-written to have a  
message port output, but then how do you get that message out of the  
flow?

[https://github.com/gnuradio/gnuradio/blob/master/gr-uhd/examples/python/usrp\_spectrum\_sense.py#L278](https://github.com/gnuradio/gnuradio/blob/master/gr-uhd/examples/python/usrp_spectrum_sense.py#L278)

Thanks,  
Lou

Martin B.-2 wrote

> Cheers,  
> M

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272p53279.html](http://gnuradio.4.n7.nabble.com/Insert-messages-in-queues-tp53272p53279.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![madengr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@madengr](https://www.ruby-forum.com/u/madengr)\
**Post date:** [April 13, 2015, 8:34am UTC](https://www.ruby-forum.com/t/insert-messages-in-queues/241530/5 "2015-04-13T08:34:43Z")

</div>

On 12.04.2015 15:22, madengr wrote:

> sink=blocks.tagged\_stream\_to\_pdu(blocks.float\_t, “packet\_len”)  
> sink.to\_basic\_block.???

So you want pop messages from outside the block, right? Is the original  
block written in C++?

delete\_head\_block() should work, but this seems unusual. Typically, we  
have two mechanisms of handling messages: Dedicated message handler  
callbacks, or we pop the queue ourselves in work() using delete\_head().

If you’re popping messages outside of the block, the block itself would  
never see or use those messages – which is why I’m surprised. You might  
be better of writing a mini-Python-block that handles the messages.

Cheers,  
M
