discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] test with message_source


From: Anastasopoulos Achilleas
Subject: Re: [Discuss-gnuradio] test with message_source
Date: Thu, 22 Feb 2007 23:30:21 -0500 (EST)

Dan,

thanks for the info you provided; it was ver helpful!
I think I got the basic understanding of the message_source/sink.

I wrote my first toy code based on this:
The Tx queues 100 packets and the Rx waits until
it receives everything (broken into different number of packets)....

The Rx does not know when transmission ended
but I can check the total # of bytes received and it
coincides with that transmitted.
I hope I have not missed something big here.

I wanted to ask if there is a natural way for the code to exit
this kind of loop; so far I am doing it manually with contr-C

Thanks
Achilleas

===========================================================
#!/usr/bin/env python

from gnuradio import gr

class my_graph(gr.flow_graph):
    def __init__(self,rx_queue):
        gr.flow_graph.__init__(self)

        Qtx=20
        src = gr.message_source(gr.sizeof_char,Qtx)
        self.tx_queue = src.msgq()
        dst = gr.message_sink(gr.sizeof_char,rx_queue,False)
        self.connect (src, dst)



if __name__ == '__main__':
    payload = 'abcdefghijklmnopqrst'
    Qrx=5
    rx_queue = gr.msg_queue(Qrx)
    fg=my_graph(rx_queue)

    print 'Starting the graph'
    fg.start()

    i=1
    j=1
    imax=100    # max number of packets to Tx
    tot=0       # counts number of received bytes
    tx_done = False
    while True:
        # process Tx side
        if not tx_done:
                msg=gr.message_from_string(payload)
                fg.tx_queue.insert_tail(msg)
                print 'Just queued the  ',i,' th packet'
                i+=1
                if i>imax:
                        tx_done = True
                        print 'Nothing to do at the Tx'
                        print 'Sending the EOF message'
                        eof_msg=gr.message(1)
                        fg.tx_queue.insert_tail(eof_msg)

        #process Rx side
        while not rx_queue.empty_p():
                rmsg = rx_queue.delete_head()
                tot+=rmsg.length()
print 'I got mail: ',j,rmsg.type(), rmsg.length(), rmsg.arg1(), rmsg.arg2(), tot
                j+=1
==============================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]