How to use gr.message_sink and gr.message_source


#1

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!