Continuos data transmission using messages

I am having a little problem working with messages. I want to transmit
an entire binary file using messages over and over again. Eg., msg1
transmits file x, msg2 again transmits file x
and so forth. My problem is that I’m unable to find a way to loop over
the file again and again. I tried using tx_voice.py as a reference but
was unable to find something suitable.
Setting repeat to true in gr.file_source won’t help either. My goal is
to send this file using packets(which is why I started out with a
shorter script using messages) , so repeating or throttling ends up
making them strings longer than 4096.
Any help would be much appreciated. Thanks in advance.

Regards,
Kshitij

from gnuradio import gr
from struct import unpack

queue = gr.msg_queue(10)
source = gr.file_source(gr.sizeof_char,’/home/kshitij/work/tp.dat’,
False)
c2f = gr.char_to_float()
sink = gr.message_sink(gr.sizeof_float,queue,False)
tb = gr.top_block()
tb.connect(source,c2f,sink)
try:
tb.start()
msg = queue.delete_head()
payload = msg.to_string()
data = unpack(‘512f’, payload)
print data, len(payload)
print msg.type(), msg.arg1(), msg.arg2(), msg.length()

except KeyboardInterrupt:
pass

On Tue, Feb 26, 2008 at 10:12:44AM -0500, Kshitij Kumar S. wrote:

Any help would be much appreciated. Thanks in advance.

Regards,
Kshitij

I think you are misunderstanding how gr.message_sink works. Since
it’s possible to set the item size small (e.g., gr.sizeof_float), it
returns as many samples as it can in a message. It does however
provide you information about what it did in the arg1 and arg2 field.

// build a message to hold whatever we’ve got
gr_message_sptr msg = gr_make_message(0, // msg type
d_itemsize, // arg1 for other end
noutput_items, // arg2 for other end (redundant)
noutput_items * d_itemsize); // len of msg

tb.connect(source,c2f,sink)

Eric

Eric
Eric, thanks for the reply and for clearing up the confusion. I now
understand how this works. Sorry if I did not phrase my question
correctly earlier: I want to transmit a file using packets repeatedly,
i.e. the first packet transmits the entire contents of file(as a string,
size <= 4096), the second packet again transmits the entire file and so
on. I thought that the best place to start was tx_voice.py since all I
needed to do was replace the audio_rx class with my own which got the
data from a file. The program ran perfectly without glitches but after
the sending the first packet, I was unable to loop around for a second
time (Still can’t figure it out). So I decided to start from scratch and
got confused with the message stuff.

Thanks for your patience.

Regards,
Kshitij

On Tue, Feb 26, 2008 at 12:02:31PM -0500, Kshitij Kumar S. wrote:

      noutput_items,   // arg2 for other end (redundant)

data from a file. The program ran perfectly without glitches but after
the sending the first packet, I was unable to loop around for a second
time (Still can’t figure it out). So I decided to start from scratch and
got confused with the message stuff.

Thanks for your patience.

Regards,
Kshitij

Take a look at the code in gnuradio-examples/python/digital. See
especially benchmark_tx.py, benchmark_rx.py and tunnel.py

Eric