commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10837 - gnuradio/branches/developers/trondeau/qtdevel


From: trondeau
Subject: [Commit-gnuradio] r10837 - gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python
Date: Tue, 14 Apr 2009 17:07:02 -0600 (MDT)

Author: trondeau
Date: 2009-04-14 17:07:02 -0600 (Tue, 14 Apr 2009)
New Revision: 10837

Added:
   
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/usrp2_display.py
Log:
changing name of USRP2 display program

Copied: 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/usrp2_display.py
 (from rev 10808, 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/usrp2_qtgui.py)
===================================================================
--- 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/usrp2_display.py
                         (rev 0)
+++ 
gnuradio/branches/developers/trondeau/qtdevel2/gr-qtgui/src/python/usrp2_display.py
 2009-04-14 23:07:02 UTC (rev 10837)
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+#
+# Copyright 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
+from gnuradio import usrp2
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from gnuradio.qtgui import qtgui
+from optparse import OptionParser
+import sys
+import numpy
+
+class app_top_block(gr.top_block):
+    def __init__(self):
+        gr.top_block.__init__(self)
+
+        parser = OptionParser(option_class=eng_option)
+        parser.add_option("-e", "--interface", type="string", default="eth0",
+                          help="select Ethernet interface, default is eth0")
+        parser.add_option("-m", "--mac-addr", type="string", default="",
+                          help="select USRP by MAC address, default is 
auto-select")
+        parser.add_option("-d", "--decim", type="int", default=16,
+                          help="set fgpa decimation rate to DECIM 
[default=%default]")
+        parser.add_option("-f", "--freq", type="eng_float", default=None,
+                          help="set frequency to FREQ", metavar="FREQ")
+        parser.add_option("-g", "--gain", type="eng_float", default=None,
+                          help="set gain in dB (default is midpoint)")
+        parser.add_option("--fft-size", type="int", default=1024,
+                          help="Set number of FFT bins [default=%default]")
+        (options, args) = parser.parse_args()
+
+        if len(args) != 0:
+            parser.print_help()
+            sys.exit(1)
+       self.options = options
+        self.show_debug_info = True
+        
+        self.u = usrp2.source_32fc(options.interface, options.mac_addr)
+        self.u.set_decim(options.decim)
+        
+        input_rate = self.u.adc_rate() / self.u.decim()
+        
+        self.snk = qtgui.sink_c(options.fft_size, 
gr.firdes.WIN_BLACKMAN_hARRIS,
+                                -input_rate/2.0, input_rate/2.0)
+
+        self.connect(self.u, self.snk)
+
+        self.snk.initialize()
+
+        if options.gain is None:
+            # if no gain was specified, use the mid-point in dB
+            g = self.u.gain_range()
+            options.gain = float(g[0]+g[1])/2
+
+        if options.freq is None:
+            # if no freq was specified, use the mid-point
+            r = self.u.freq_range()
+            options.freq = float(r[0]+r[1])/2
+            
+        self.set_gain(options.gain)
+
+        if self.show_debug_info:
+            print "Decimation rate: ", self.u.decim()
+            print "Bandwidth: ", input_rate
+            print "D'board: ", self.u.daughterboard_id()
+
+        self.set_freq(options.freq)
+            
+            
+    def set_freq(self, target_freq):
+        """
+        Set the center frequency we're interested in.
+
+        @param target_freq: frequency in Hz
+        @rypte: bool
+
+        Tuning is a two step process.  First we ask the front-end to
+        tune as close to the desired frequency as it can.  Then we use
+        the result of that operation and our target_frequency to
+        determine the value for the digital down converter.
+        """
+        r = self.u.set_center_freq(target_freq)
+
+        if r:
+           return True
+
+        return False
+
+    def set_gain(self, gain):
+        self.u.set_gain(gain)
+
+    def set_decim(self, decim):
+        ok = self.u.set_decim(decim)
+        if not ok:
+            print "set_decim failed"
+        input_rate = self.u.adc_rate() / self.u.decim()
+        return ok
+
+def main ():
+    tb = app_top_block()
+    tb.start()
+    tb.snk.start_app();
+
+if __name__ == '__main__':
+    try:
+        main ()
+    except KeyboardInterrupt:
+        pass
+    





reply via email to

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