Passing the payload to the application level (to GUI display)

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??

Please help!

On Mon, Jun 15, 2009 at 04:06:15PM +0800, Yu-Hua Y. wrote:

print “ok = %5s pktno = %4d n_rcvd = %4d n_right = %4d” % (

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