discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] Passing the payload to the application level (to


From: Eric Blossom
Subject: Re: [Discuss-gnuradio] Passing the payload to the application level (to GUI display)
Date: Mon, 15 Jun 2009 07:41:00 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

On Mon, Jun 15, 2009 at 04:06:15PM +0800, Yu-Hua Yang wrote:
> Hi,
> 
> I found a similar thread here
> http://lists.gnu.org/archive/html/discuss-gnuradio/2006-09/msg00205.html
> 
> but the suggested solution doesnt seem to work well with what I am trying to
> do.
> 
> All i am trying to do is take the received packet information
> 
> print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
>                     ok, pktno, n_rcvd, n_right)
> 
> and display this on my GUI. But the rx_callback function cannot take 'self'
> as a parameter so there is no way for me display the pktno, n_rcvd, n_right
> on my GUI.
> 
> I tried the following without success, because the same problem persists: i
> simply cannot pass the callback information back up to the GUI level.
> 
> def rx_callback(ok, payload):
> 
>                 global n_rcvd, n_right, message
>                 (pktno,) = struct.unpack('!H', payload[0:2])
>                 n_rcvd += 1
>                 if ok:
>                     n_right += 1
> 
>                 message = "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right =
> %4d" % (
>                     ok, pktno, n_rcvd, n_right)
> 
> def wrapped_callback(self, callback):
>           def test_wrap(ok, payload):
>                     callback(ok, payload)
>           return test_wrap
>           self.output.AppendText(message)
> 
> tb = my_top_block(demods[options.modulation],
> wrapped_callback(self,rx_callback), options)
> 
> I am very lost as to what to do. Do I have to modify pkt.py and rebuild?? Is
> there anyway to pass the payload stuff up to the GUI??

You do not need to modify pkt.py, since you can pass in whatever you
like for rx_callback.  Consider modifying it such that it closes over
whatever variables or functions you need.

Please read up on closures and/or see 
http://artificialcode.blogspot.com/2009/04/python-functional-programming.html

Eric




reply via email to

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