summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjcorgan2008-09-23 19:39:09 +0000
committerjcorgan2008-09-23 19:39:09 +0000
commit16699b8ac2ab0c98ad3593b573e409ce39f9eb7c (patch)
treee55f4a3f4e724c8e1e87cc2ce50776ccc09385c6
parent7bd129934e980a8e9391f327e89ba56dd3ae95f4 (diff)
downloadgnuradio-16699b8ac2ab0c98ad3593b573e409ce39f9eb7c.tar.gz
gnuradio-16699b8ac2ab0c98ad3593b573e409ce39f9eb7c.tar.bz2
gnuradio-16699b8ac2ab0c98ad3593b573e409ce39f9eb7c.zip
Adds usrp2_siggen.py to gr-utils, missed copyright notices
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9642 221aa14e-8319-0410-a670-987f0aec2ac5
-rw-r--r--gr-utils/src/python/Makefile.am5
-rwxr-xr-xgr-utils/src/python/usrp2_rx_cfile.py20
-rwxr-xr-xgr-utils/src/python/usrp2_siggen.py143
-rwxr-xr-xgr-utils/src/python/usrp_siggen.py20
4 files changed, 186 insertions, 2 deletions
diff --git a/gr-utils/src/python/Makefile.am b/gr-utils/src/python/Makefile.am
index a48180b49..8b83dea73 100644
--- a/gr-utils/src/python/Makefile.am
+++ b/gr-utils/src/python/Makefile.am
@@ -49,6 +49,7 @@ bin_SCRIPTS = \
usrp_test_counting.py \
usrp_test_loopback.py \
usrp2_fft.py \
- usrp2_rx_cfile.py
-
+ usrp2_rx_cfile.py \
+ usrp2_siggen.py
+
MOSTLYCLEANFILES = *~ *.pyc
diff --git a/gr-utils/src/python/usrp2_rx_cfile.py b/gr-utils/src/python/usrp2_rx_cfile.py
index 9ab28607d..539b3e3d3 100755
--- a/gr-utils/src/python/usrp2_rx_cfile.py
+++ b/gr-utils/src/python/usrp2_rx_cfile.py
@@ -1,4 +1,24 @@
#!/usr/bin/env python
+#
+# Copyright 2004,2005,2007,2008 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.
+#
"""
Read samples from the USRP2 and write to file formatted as binary
diff --git a/gr-utils/src/python/usrp2_siggen.py b/gr-utils/src/python/usrp2_siggen.py
new file mode 100755
index 000000000..b4aee240a
--- /dev/null
+++ b/gr-utils/src/python/usrp2_siggen.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 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, eng_notation
+from gnuradio import usrp2
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+import sys
+
+n2s = eng_notation.num_to_str
+
+class siggen_top_block(gr.top_block):
+ def __init__(self, options):
+ gr.top_block.__init__(self)
+
+ # Create a USRP2 sink with the requested interpolation rate
+ self._u = usrp2.sink_32fc(options.interface, options.mac_addr)
+ self._u.set_interp(options.interp)
+
+ # Set the Tx daughterboard gain as requested
+ if options.gain is None:
+ #g = self._u.gain_range()
+ #options.gain = float(g[0]+g[1])/2
+ options.gain = 0 # Until gain range is implemented
+ self._u.set_gain(options.gain)
+
+ # Tune the USRP2 FPGA and daughterboard to the requested center frequency
+ tr = self._u.set_center_freq(options.tx_freq)
+ if tr == None:
+ sys.stderr.write('Failed to set center frequency\n')
+ raise SystemExit, 1
+
+ #eth_rate = self._u.dac_rate()/self._u.interp_rate()
+ eth_rate = 100e6/options.interp # FIXME
+
+ # Create a source for the requested waveform type
+ if options.type == gr.GR_SIN_WAVE or options.type == gr.GR_CONST_WAVE:
+ self._src = gr.sig_source_c(eth_rate, # Sample rate
+ options.type, # Waveform type
+ options.waveform_freq, # Waveform frequency
+ options.amplitude, # Waveform amplitude
+ options.offset) # Waveform offset
+
+ elif options.type == gr.GR_GAUSSIAN or options.type == gr.GR_UNIFORM:
+ self._src = gr.noise_source_c(options.type, options.amplitude)
+ else:
+ sys.stderr.write('Unknown waveform type\n')
+ raise SystemExit, 1
+
+ if options.verbose:
+ print "Network interface:", options.interface
+ print "USRP2 address:", self._u.mac_addr()
+ #print "Using TX d'board %s" % (self._u.tx_name(),)
+ print "Tx gain:", options.gain
+ print "Tx baseband frequency:", n2s(tr.baseband_freq), "Hz"
+ print "Tx DDC frequency:", n2s(tr.dxc_freq), "Hz"
+ print "Tx residual frequency:", n2s(tr.residual_freq), "Hz"
+ print "Tx interpolation rate:", options.interp
+ print "Tx GbE sample rate:", n2s(eth_rate), "samples/sec"
+ if options.type == gr.GR_SIN_WAVE:
+ print "Baseband waveform type: Sine wave"
+ print "Baseband waveform frequency:", n2s(options.waveform_freq), "Hz"
+ elif options.type == gr.GR_CONST_WAVE:
+ print "Baseband waveform type: Constant"
+ elif options.type == gr.GR_GAUSSIAN:
+ print "Baseband waveform type: Gaussian noise"
+ elif options.type == gr.GR_UNIFORM:
+ print "Baseband waveform type: Uniform noise"
+
+ # Wire the flowgraph
+ self.connect(self._src, self._u)
+
+def get_options():
+ usage="%prog: [options]"
+
+ parser = OptionParser(option_class=eng_option, usage=usage)
+ parser.add_option("-e", "--interface", type="string", default="eth0",
+ help="use specified Ethernet interface [default=%default]")
+ parser.add_option("-m", "--mac-addr", type="string", default="",
+ help="use USRP2 at specified MAC address [default=None]")
+ parser.add_option("-i", "--interp", type="int", default=16,
+ help="set fgpa decimation rate to DECIM [default=%default]")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set output gain to GAIN [default=%default]")
+ parser.add_option("-f", "--tx-freq", type="eng_float", default=None,
+ help="set frequency to FREQ", metavar="FREQ")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="verbose 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=0.5,
+ help="set waveform amplitude to AMPLITUDE (0-1.0) [default=%default]", metavar="AMPL")
+ parser.add_option("--offset", type="eng_float", default=0,
+ help="set waveform offset to OFFSET [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")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 0:
+ parser.print_help()
+ raise SystemExit, 1
+
+ if options.tx_freq is None:
+ parser.print_help()
+ sys.stderr.write('You must specify the frequency with -f FREQ\n');
+ raise SystemExit, 1
+
+ return options
+
+
+if __name__ == '__main__':
+ options = get_options()
+ tb = siggen_top_block(options)
+
+ try:
+ tb.run()
+ except KeyboardInterrupt:
+ pass
diff --git a/gr-utils/src/python/usrp_siggen.py b/gr-utils/src/python/usrp_siggen.py
index add3888ba..876b40056 100755
--- a/gr-utils/src/python/usrp_siggen.py
+++ b/gr-utils/src/python/usrp_siggen.py
@@ -1,4 +1,24 @@
#!/usr/bin/env python
+#
+# Copyright 2004,2005,2007,2008 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 usrp