Forum: GNU Radio How to use gr.message_sink and gr.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.
Sajjad Sarwar (Guest)
on 2009-03-23 13:02
(Received via mailing list)
Hi,
I am new to gnuradio and trying to understand how gr.message_sink and
gr.message_source work. I want to convert a byte stream (read from a
file)
into a message of 50 bytes and store it in a queue. Then i want to
retrieve
that message, convert it back to byte stream and write it to another
file to
make the copy of original file.
Here is the code I have written for  this but its not working. Perhaps I
am
misunderstanding how to convert a byte stream into a "message":


#!/usr/bin/env python
from gnuradio import gr
from gnuradio import audio


class main_fg(gr.top_block):
    def __init__(self):
    gr.top_block.__init__(self)
    self.packet_src= gr.message_source(50)
        self.file_msgq = gr.msg_queue()
        self.packet_sink = gr.message_sink(50, self.file_msgq, False)
    file_src=gr.file_source(1,'/home/sajjad/Desktop/work/source_data')
    file_dst=gr.file_sink(1,'/home/sajjad/Desktop/work/dstdata')
    v2s=gr.vector_to_stream(1,50)
    s2v=gr.stream_to_vector(1,50)

    self.connect(file_src, s2v, self.packet_sink)
    self.connect(self.packet_src, v2s, file_dst)

fg=main_fg()
fg.start()

bytes=0;
while True:
    data=fg.file_msgq.delete_head()
    fg.packet_src.msgq().insert_tail(data)
    bytes+=5
    print bytes

fg.stop()

Please make me understand how these two blocks work  cz i severely and
urgently need them. Thanks a lot!
This topic is locked and can not be replied to.