commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4450 - in gnuradio/branches/developers/trondeau/digit


From: trondeau
Subject: [Commit-gnuradio] r4450 - in gnuradio/branches/developers/trondeau/digital-wip2: config gnuradio-examples/python/hier gnuradio-examples/python/hier/usrp
Date: Sun, 11 Feb 2007 18:13:56 -0700 (MST)

Author: trondeau
Date: 2007-02-11 18:13:56 -0700 (Sun, 11 Feb 2007)
New Revision: 4450

Added:
   
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/
   
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/Makefile.am
   
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/usrp_siggen.py
Modified:
   
gnuradio/branches/developers/trondeau/digital-wip2/config/grc_gnuradio_examples.m4
Log:
adding simple usrp_siggen script using hier_block2's

Modified: 
gnuradio/branches/developers/trondeau/digital-wip2/config/grc_gnuradio_examples.m4
===================================================================
--- 
gnuradio/branches/developers/trondeau/digital-wip2/config/grc_gnuradio_examples.m4
  2007-02-12 00:32:50 UTC (rev 4449)
+++ 
gnuradio/branches/developers/trondeau/digital-wip2/config/grc_gnuradio_examples.m4
  2007-02-12 01:13:56 UTC (rev 4450)
@@ -35,6 +35,7 @@
        gnuradio-examples/python/hier/audio/Makefile \
        gnuradio-examples/python/hier/digital/Makefile \
        gnuradio-examples/python/hier/ofdm/Makefile \
+       gnuradio-examples/python/hier/usrp/Makefile \
         gnuradio-examples/python/multi-antenna/Makefile \
         gnuradio-examples/python/multi_usrp/Makefile \
         gnuradio-examples/python/networking/Makefile \

Added: 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/Makefile.am
                           (rev 0)
+++ 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/Makefile.am
   2007-02-12 01:13:56 UTC (rev 4450)
@@ -0,0 +1,23 @@
+#
+# Copyright 2004,2005 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 2, 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.
+# 
+
+EXTRA_DIST = \
+       usrp_siggen.py

Added: 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/usrp_siggen.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/usrp_siggen.py
                                (rev 0)
+++ 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/usrp_siggen.py
        2007-02-12 01:13:56 UTC (rev 4450)
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, gru
+from gnuradio import usrp
+from gnuradio.eng_option import eng_option
+from gnuradio import eng_notation
+from optparse import OptionParser
+import sys
+
+
+class my_graph(gr.hier_block2):
+    def __init__ (self, type, ampl, wfreq, offset, subdev_spec, interp, 
rf_freq):
+        # Call hierarchical block constructor
+        # Top-level blocks have no inputs or outputs
+        gr.hier_block2.__init__(self, 
+                                "usrp_siggen",         # Block type 
+                                gr.io_signature(0,0,0), # Input signature
+                                gr.io_signature(0,0,0)) # Output signature
+        
+        # controllable values
+        self.interp = interp
+        self.waveform_type = type
+        self.waveform_ampl = ampl
+        self.waveform_freq = wfreq
+        self.waveform_offset = offset
+
+        self.u = usrp.sink_c (0, self.interp)
+
+        # determine the daughterboard subdevice we're using
+        if subdev_spec is None:
+            ubdev_spec = usrp.pick_tx_subdevice(self.u)
+        m = usrp.determine_tx_mux_value(self.u, subdev_spec)
+        self.u.set_mux(m)
+        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
+        self.subdev.set_gain(self.subdev.gain_range()[1])    # set max Tx gain
+        self.subdev.set_enable(True)                         # enable 
transmitter
+        print "Using TX d'board %s" % (self.subdev.side_and_name(),)
+
+        if not self.set_freq(rf_freq):
+            sys.stderr.write('Failed to set RF frequency\n')
+            raise SystemExit
+
+        self.define_component("usrp", self.u)
+
+        if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
+            self.src = gr.sig_source_c (self.usb_freq (),
+                                        gr.GR_SIN_WAVE,
+                                        self.waveform_freq,
+                                        self.waveform_ampl,
+                                        self.waveform_offset)
+            self.define_component("src", self.src)
+
+        elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+            self.src = gr.noise_source_c (gr.GR_UNIFORM,
+                                          self.waveform_ampl)
+            self.define_component("src", self.src)
+        
+        else:
+            raise ValueError, type
+
+        # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
+        # self.define_component("file_sink", self.file_sink)
+
+        self.connect ("src", 0, "usrp", 0)
+
+
+    def usb_freq (self):
+        return self.u.dac_freq() / self.interp
+
+    def usb_throughput (self):
+        return self.usb_freq () * 4
+        
+    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 up converter.
+        """
+        r = self.u.tune(self.subdev._which, self.subdev, target_freq)
+        if r:
+            #print "r.baseband_freq =", 
eng_notation.num_to_str(r.baseband_freq)
+            #print "r.dxc_freq      =", eng_notation.num_to_str(r.dxc_freq)
+            #print "r.residual_freq =", 
eng_notation.num_to_str(r.residual_freq)
+            #print "r.inverted      =", r.inverted
+            return True
+
+        return False
+
+
+
+def main ():
+    parser = OptionParser (option_class=eng_option)
+    parser.add_option ("-T", "--tx-subdev-spec", type="subdev", default=(0, 0),
+                       help="select USRP Tx side A or B")
+    parser.add_option ("-f", "--rf-freq", type="eng_float", default=None,
+                       help="set RF center frequency to FREQ")
+    parser.add_option ("-i", "--interp", type="int", default=64,
+                       help="set fgpa interpolation rate to INTERP 
[default=%default]")
+
+    parser.add_option ("--sine", dest="type", action="store_const", 
const=gr.GR_SIN_WAVE,
+                       help="generate a complex sinusoid [default]", 
default=gr.GR_SIN_WAVE)
+    parser.add_option ("--const", dest="type", action="store_const", 
const=gr.GR_CONST_WAVE, 
+                       help="generate a constant output")
+    parser.add_option ("--gaussian", dest="type", action="store_const", 
const=gr.GR_GAUSSIAN,
+                       help="generate Gaussian random output")
+    parser.add_option ("--uniform", dest="type", action="store_const", 
const=gr.GR_UNIFORM,
+                       help="generate Uniform random output")
+
+    parser.add_option ("-w", "--waveform-freq", type="eng_float", 
default=100e3,
+                       help="set waveform frequency to FREQ 
[default=%default]")
+    parser.add_option ("-a", "--amplitude", type="eng_float", default=16e3,
+                       help="set waveform amplitude to AMPLITUDE 
[default=%default]", metavar="AMPL")
+    parser.add_option ("-o", "--offset", type="eng_float", default=0,
+                       help="set waveform offset to OFFSET [default=%default]")
+    (options, args) = parser.parse_args ()
+
+    if len(args) != 0:
+        parser.print_help()
+        raise SystemExit
+
+    if options.rf_freq is None:
+        sys.stderr.write("usrp_siggen: must specify RF center frequency with 
-f RF_FREQ\n")
+        parser.print_help()
+        raise SystemExit
+
+    top_block = my_graph(options.type, options.amplitude, 
options.waveform_freq, options.offset,
+                         options.tx_subdev_spec, options.interp, 
options.rf_freq)
+
+    runtime = gr.runtime(top_block)
+    
+    try:    
+        # Run forever
+        runtime.run()
+    except KeyboardInterrupt:
+        # Ctrl-C exits
+        pass
+
+if __name__ == '__main__':
+    main ()


Property changes on: 
gnuradio/branches/developers/trondeau/digital-wip2/gnuradio-examples/python/hier/usrp/usrp_siggen.py
___________________________________________________________________
Name: svn:executable
   + *





reply via email to

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