#!/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
class my_top_block(gr.top_block):
- def __init__ (self):
+ def __init__ (self, nsamples):
gr.top_block.__init__(self)
# controllable values
self.waveform_ampl = 16000
self.waveform_freq = 100.12345e3
self.waveform_offset = 0
+ self.nsamples = nsamples
self._instantiate_blocks ()
self.set_waveform_type (self.waveform_type)
self.noisegen = gr.noise_source_c (gr.GR_UNIFORM,
self.waveform_ampl)
+ self.head = None
+ if self.nsamples > 0:
+ self.head = gr.head(gr.sizeof_gr_complex, int(self.nsamples))
+
# self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
def _configure_graph (self, type):
- was_running = self.is_running ()
- if was_running:
- self.stop ()
- self.disconnect_all ()
- if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
- self.connect (self.siggen, self.u)
- # self.connect (self.siggen, self.file_sink)
- self.siggen.set_waveform (type)
- self.src = self.siggen
- elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
- self.connect (self.noisegen, self.u)
- self.noisegen.set_type (type)
- self.src = self.noisegen
- else:
- raise ValueError, type
- if was_running:
- self.start ()
+ try:
+ self.lock()
+ self.disconnect_all ()
+
+ if self.head:
+ self.connect(self.head, self.u)
+ tail = self.head
+ else:
+ tail = self.u
+
+ if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
+ self.connect (self.siggen, tail)
+ # self.connect (self.siggen, self.file_sink)
+ self.siggen.set_waveform (type)
+ self.src = self.siggen
+ elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+ self.connect (self.noisegen, tail)
+ self.noisegen.set_type (type)
+ self.src = self.noisegen
+ else:
+ raise ValueError, type
+ finally:
+ self.unlock()
def set_freq(self, target_freq):
"""
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)
+ 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)
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,
+ parser.add_option ("-w", "--waveform-freq", type="eng_float", default=0,
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")
help="set output gain to GAIN [default=%default]")
parser.add_option ("-o", "--offset", type="eng_float", default=0,
help="set waveform offset to OFFSET [default=%default]")
+ parser.add_option ("-N", "--nsamples", type="eng_float", default=0,
+ help="set number of samples to transmit [default=+inf]")
(options, args) = parser.parse_args ()
if len(args) != 0:
parser.print_help()
raise SystemExit
- tb = my_top_block()
+ tb = my_top_block(options.nsamples)
tb.set_interpolator (options.interp)
tb.set_waveform_type (options.type)
tb.set_waveform_freq (options.waveform_freq)
print "Using TX d'board %s" % (tb.subdev.side_and_name(),)
if options.gain is None:
- tb.subdev.set_gain(fg.subdev.gain_range()[1]) # set max Tx gain
+ tb.subdev.set_gain(tb.subdev.gain_range()[1]) # set max Tx gain
else:
tb.subdev.set_gain(options.gain) # set max Tx gain
except KeyboardInterrupt:
pass
+
if __name__ == '__main__':
main ()