commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10701 - gnuradio/trunk/gr-pager/src


From: jcorgan
Subject: [Commit-gnuradio] r10701 - gnuradio/trunk/gr-pager/src
Date: Sun, 29 Mar 2009 10:36:01 -0600 (MDT)

Author: jcorgan
Date: 2009-03-29 10:36:01 -0600 (Sun, 29 Mar 2009)
New Revision: 10701

Modified:
   gnuradio/trunk/gr-pager/src/pager_utils.py
   gnuradio/trunk/gr-pager/src/usrp_flex.py
   gnuradio/trunk/gr-pager/src/usrp_flex_all.py
   gnuradio/trunk/gr-pager/src/usrp_flex_band.py
Log:
Reorganize queue runner, some cleanup, fixes ticket:376

Modified: gnuradio/trunk/gr-pager/src/pager_utils.py
===================================================================
--- gnuradio/trunk/gr-pager/src/pager_utils.py  2009-03-27 05:36:17 UTC (rev 
10700)
+++ gnuradio/trunk/gr-pager/src/pager_utils.py  2009-03-29 16:36:01 UTC (rev 
10701)
@@ -1,5 +1,5 @@
 #
-# Copyright 2008 Free Software Foundation, Inc.
+# Copyright 2008,2009 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -18,7 +18,10 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
+from gnuradio import gr
 import gnuradio.gr.gr_threading as _threading
+from string import split, join, printable
+import time
 
 def make_trans_table():
     table = 256 * ['.']
@@ -34,14 +37,24 @@
 def make_printable(s):
     return s.translate(_trans_table)
 
-class top_block_runner(_threading.Thread):
-    def __init__(self, tb):
+
+class queue_runner(_threading.Thread):
+    def __init__(self, msgq):
         _threading.Thread.__init__(self)
-        self.setDaemon(1)
-        self.tb = tb
+        self.msgq = msgq
         self.done = False
         self.start()
 
     def run(self):
-        self.tb.run()
+        while 1:
+            msg = self.msgq.delete_head() # Blocking read
+            if msg.type() != 0:
+                break
+            
+            page = join(split(msg.to_string(), chr(128)), '|')
+            s = make_printable(page)
+            print msg.type(), s
+                
+    def end(self):
+        self.msgq.insert_tail(gr.message(1))
         self.done = True

Modified: gnuradio/trunk/gr-pager/src/usrp_flex.py
===================================================================
--- gnuradio/trunk/gr-pager/src/usrp_flex.py    2009-03-27 05:36:17 UTC (rev 
10700)
+++ gnuradio/trunk/gr-pager/src/usrp_flex.py    2009-03-29 16:36:01 UTC (rev 
10701)
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
-
 #
-# Copyright 2006,2007 Free Software Foundation, Inc.
+# Copyright 2006,2007,2009 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -25,7 +24,6 @@
 from gnuradio.eng_option import eng_option
 from optparse import OptionParser
 import time, os, sys
-from string import split, join
 
 """
 This example application demonstrates receiving and demodulating the
@@ -108,9 +106,9 @@
            print "Channel filter has", len(taps), "taps."
 
         self.chan = gr.freq_xlating_fir_filter_ccf(10,    # Decimation rate
-                                              taps,  # Filter taps
-                                              0.0,   # Offset frequency
-                                              250e3) # Sample rate
+                                                   taps,  # Filter taps
+                                                   0.0,   # Offset frequency
+                                                   250e3) # Sample rate
 
        if options.log:
            chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
@@ -160,24 +158,15 @@
     # Flow graph emits pages into message queue
     queue = gr.msg_queue()
     tb = app_top_block(options, queue)
-    runner = pager.top_block_runner(tb)
+    runner = pager.queue_runner(queue)
     
     try:
-       while 1:
-           if not queue.empty_p():
-               msg = queue.delete_head() # Blocking read
-               page = join(split(msg.to_string(), chr(128)), '|')
-                s = pager.make_printable(page)
-                print s
-               tb.adjust_freq()
-            elif runner.done:
-                break
-           else:
-               time.sleep(1)
-
+        tb.run()
     except KeyboardInterrupt:
-        tb.stop()
-        runner = None
+        pass
 
+    runner.end()
+
+
 if __name__ == "__main__":
     main()

Modified: gnuradio/trunk/gr-pager/src/usrp_flex_all.py
===================================================================
--- gnuradio/trunk/gr-pager/src/usrp_flex_all.py        2009-03-27 05:36:17 UTC 
(rev 10700)
+++ gnuradio/trunk/gr-pager/src/usrp_flex_all.py        2009-03-29 16:36:01 UTC 
(rev 10701)
@@ -1,4 +1,24 @@
 #!/usr/bin/env python
+#
+# Copyright 2006,2007,2009 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
 
 from gnuradio import gr, gru, usrp, optfir, eng_notation, blks2, pager
 from gnuradio.eng_option import eng_option
@@ -21,10 +41,10 @@
             subdev = usrp.selected_subdev(src, options.rx_subdev_spec)
             src.set_mux(usrp.determine_rx_mux_value(src, 
options.rx_subdev_spec))
             src.set_decim_rate(20)
-            result = usrp.tune(src, 0, subdev, 930.5e6+options.calibration)
+            result = usrp.tune(src, 0, subdev, 930.5125e6+options.calibration)
             if options.verbose:
                 print "Using", subdev.name(), " for receiving."
-                print "Tuned USRP to", 930.5e6+options.calibration
+                print "Tuned USRP to", 930.5125e6+options.calibration
                 
         taps = gr.firdes.low_pass(1.0,
                                   1.0,
@@ -76,23 +96,14 @@
 
     queue = gr.msg_queue()
     tb = app_top_block(options, queue)
+    runner = pager.queue_runner(queue)
 
-    runner = pager.top_block_runner(tb)
     try:
-       while 1:
-           if not queue.empty_p():
-               msg = queue.delete_head() # Blocking read
-               page = join(split(msg.to_string(), chr(128)), '|')
-                s = pager.make_printable(page)
-                print s
-            elif runner.done:
-                break
-           else:
-               time.sleep(0.05)
+        tb.run()
+    except KeyboardInterrupt:
+        pass
 
-    except KeyboardInterrupt:
-        tb.stop()
-        runner = None
+    runner.end()
     
 if __name__ == "__main__":
     main()

Modified: gnuradio/trunk/gr-pager/src/usrp_flex_band.py
===================================================================
--- gnuradio/trunk/gr-pager/src/usrp_flex_band.py       2009-03-27 05:36:17 UTC 
(rev 10700)
+++ gnuradio/trunk/gr-pager/src/usrp_flex_band.py       2009-03-29 16:36:01 UTC 
(rev 10701)
@@ -1,10 +1,28 @@
 #!/usr/bin/env python
+#
+# Copyright 2006,2007,2009 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
 
 from gnuradio import gr, gru, usrp, optfir, eng_notation, blks2, pager
 from gnuradio.eng_option import eng_option
 from optparse import OptionParser
-from string import split, join, printable
-import time
 
 class app_top_block(gr.top_block):
     def __init__(self, options, queue):
@@ -54,10 +72,6 @@
            if options.log:
                self.connect((bank, i), gr.file_sink(gr.sizeof_gr_complex, 
'chan_'+'%3.3f'%(freq/1e6)+'.dat'))
 
-    def __del__(self):
-       # Avoid weak-ref error
-       del self.subdev
-       
 
 def main():
     parser = OptionParser(option_class=eng_option)
@@ -82,23 +96,15 @@
 
     queue = gr.msg_queue()
     tb = app_top_block(options, queue)
+    runner = pager.queue_runner(queue)
 
-    runner = pager.top_block_runner(tb)
     try:
-       while 1:
-           if not queue.empty_p():
-               msg = queue.delete_head() # Blocking read
-               page = join(split(msg.to_string(), chr(128)), '|')
-                s = pager.make_printable(page)
-                print s
-            elif runner.done:
-                break
-           else:
-               time.sleep(0.05)
+        tb.run()
+    except KeyboardInterrupt:
+        pass
 
-    except KeyboardInterrupt:
-        tb.stop()
-        runner = None
+    runner.end()
+
     
 if __name__ == "__main__":
     main()





reply via email to

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