Reorganize queue runner, some cleanup, fixes ticket:376
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 29 Mar 2009 16:36:01 +0000 (16:36 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 29 Mar 2009 16:36:01 +0000 (16:36 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10701 221aa14e-8319-0410-a670-987f0aec2ac5

gr-pager/src/pager_utils.py
gr-pager/src/usrp_flex.py
gr-pager/src/usrp_flex_all.py
gr-pager/src/usrp_flex_band.py

index bbcb633fdd60da6991a08f75748ce108c4d33293..72aac6826c7ce1917364aebacf2e9d8e737641cb 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright 2008 Free Software Foundation, Inc.
+# Copyright 2008,2009 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
 # 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 @@ _trans_table = make_trans_table()
 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
index 6e09b3df6ba922af8f997f6257bfee7471136dc4..f8d9d25b199af532084c0fbd29f1de4652facf7c 100755 (executable)
@@ -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 import gr, gru, usrp, optfir, eng_notation, pager
 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 @@ class app_top_block(gr.top_block):
            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 @@ def main():
     # 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()
index b37c6a5dae69060bd3b4d017205ef7837891105c..14f9151de1b33a1514e6b7e6fbee39385db05240 100755 (executable)
@@ -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 @@ class app_top_block(gr.top_block):
             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 @@ def main():
 
     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:
-        tb.stop()
-        runner = None
+        pass
+
+    runner.end()
     
 if __name__ == "__main__":
     main()
index 62307385b4b4c6316cbe34df630dd7aea2553607..06c2488c0563aa64105912c928d739531c0a3850 100755 (executable)
@@ -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 @@ class app_top_block(gr.top_block):
            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 @@ def main():
 
     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:
-        tb.stop()
-        runner = None
+        pass
+
+    runner.end()
+
     
 if __name__ == "__main__":
     main()