discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] callback from message sink is stopped


From: Timothy Lawrence Sitorus
Subject: [Discuss-gnuradio] callback from message sink is stopped
Date: Wed, 16 Dec 2009 15:00:22 +0900

Hi All,

I am a begginer in GNU Radio. I have sent my first question once,maybe 3 or 4 weeks ago, but nobody answer it. It is OK, since  I solved the problem. But this time ,  I am really stuck with the problem  for 2 weeks. could anyone answer my problem? please help me. I hope there is a nice person who can answer my problem.

I have a problem with the combination of message_source and message_sink. my code is written below.
The program is executed without any error. But what i am confused is sometimes it stopped even though the number of pktno isn't 1499 yet. I am hoping to get all the packet to printed in stdout.
please help me why it happen?

Best Regards,
Tim




from gnuradio import gr, usrp2, blks2, packet_utils
import gnuradio.gr.gr_threading as _threading
import threading
import struct


class my_top_block(gr.top_block):
    def __init__(self,callback=None,msq_limit = 2):
        gr.top_block.__init__(self)
    self.packet_sink = gr.msg_queue()
    self.src = "" msq_limit)
    self.sink = gr.message_sink(gr.sizeof_char,self.packet_sink,False)
    self.connect(self.src,self.sink)


def main():
    def send(payload='',eof=False) :

        if eof== True :
            tb.src.msgq().insert_tail(gr.message(1))
        else :
#            print 'send payload'
            tb.src.msgq().insert_tail(gr.message_from_string(payload))



    def receive(payload) :
        print payload



    tb = my_top_block()
    nbytes = 1e6
    tb.start()
    n=0
    pktno=0
    pkt_size=30
    tb.watcher = simple_thread(tb.packet_sink,receive)
#    while n < nbytes:
    while pktno <1500:
#                send(struct.pack('!H', pktno & 0xffff) + (pkt_size - 2) * chr(pktno & 0xff))
           payload = 'pktno = %d \n'%pktno
          
           send(payload)
                n += pkt_size
               pktno += 1
      
     send(eof=True)

    tb.wait()


class simple_thread(_threading.Thread):
    def __init__(self, msgq1,receive):
        _threading.Thread.__init__(self)
        self.setDaemon(1)
    self.msgq1 = msgq1
        self.receive = receive
        self.keep_running = True
        self.start()


    def run(self):
        while self.keep_running:
#        if self.msgq1.count >= 0 :
            print self.msgq1.empty_p()
            payload = self.msgq1.delete_head().to_string()

                if self.receive :
                self.receive(payload)


       
if __name__ == "__main__":
        main()





reply via email to

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