Forum: GNU Radio test with message_source

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C369ebbe1655201988e376af57460f23?d=identicon&s=25 Anastasopoulos Achilleas (Guest)
on 2007-02-22 20:34
(Received via mailing list)
Hi,

I am trying to understand how the message source works
and how I can use it from within my python code.
So I wrote a simple script with a message source and a null sink.
I wanted the following behavior:
every time I press a button on my keybord to send a constant message in
the queue and verify that the queue size has increased.

Here is the piece of code that I have so far...

What I don't know how to do is to enqueue a message every time
I press a button.
Can someone point to the right direction as to how this event driven
behavior is implemented.

Thanks
Achilleas



==========================================================
from gnuradio import gr
from gnuradio import audio
from gnuradio.eng_option import eng_option
from optparse import OptionParser

class my_graph(gr.flow_graph):

     def __init__(self):
         gr.flow_graph.__init__(self)

         packet = 'abcdefghijklmnopqrstuwxy' #multiple of
gr.sizeof_float
         msg=gr.message_from_string(packet)

         src0 = gr.message_source(gr.sizeof_float,10)
         dst = gr.null_sink (gr.sizeof_float)
         self.connect (src0, dst)

         # Now I want every time I press a button to run the following
code,
         # so that I add the same msg in the message queue
         src0.msgq().insert_tail(msg)
         print src0.msgq().count()


if __name__ == '__main__':
     try:
         my_graph().run()
     except KeyboardInterrupt:
         pass
==========================================================
3dfb724cefc1eddbade1e8bd1ee6131f?d=identicon&s=25 Dan Halperin (Guest)
on 2007-02-22 21:10
(Received via mailing list)
Anastasopoulos Achilleas wrote:
> What I don't know how to do is to enqueue a message every time
> I press a button.
> Can someone point to the right direction as to how this event driven
> behavior is implemented.

Look in the gnuradio-examples/python/digital/tunnel.py and subfiles.

transmit_path.py has a send_pkt function which calls the send_pkt
function in pkt.py (in the gnuradio python libraries directory), which
converts a string into the proper format and enqueues it into a message
queue.

When you're done with the queue, and you want to close up, call the
send_pkt function with eof = True (enqueues gr.message(1)), which tells
the queue that no more input is coming and enables the fg to stop.

-Dan
This topic is locked and can not be replied to.