summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rondeau2011-10-06 17:04:47 -0400
committerTom Rondeau2011-10-06 17:04:47 -0400
commit21beeed3c257e43b557edf01114fc752d4123125 (patch)
treef7d57aa3bd35964d299125992bd38a6033589aef
parent887b369981ebf3e6f69d8e761d83dd556d2ae2d4 (diff)
downloadgnuradio-21beeed3c257e43b557edf01114fc752d4123125.tar.gz
gnuradio-21beeed3c257e43b557edf01114fc752d4123125.tar.bz2
gnuradio-21beeed3c257e43b557edf01114fc752d4123125.zip
uhd: moved fm_tx_2_daughterboards and usrp_spectrum_sense to gr-uhd/examples. Neither are working properly quite yet.
Removed all usrp examples from gnuradio-examples/python/usrp and removed directory.
-rw-r--r--gnuradio-examples/python/Makefile.am3
-rw-r--r--gnuradio-examples/python/usrp/Makefile.am2
-rwxr-xr-xgnuradio-examples/python/usrp/test_dft_analysis.py72
-rwxr-xr-xgnuradio-examples/python/usrp/test_dft_synth.py78
-rw-r--r--gr-uhd/examples/Makefile.am2
-rwxr-xr-xgr-uhd/examples/fm_tx_2_daughterboards.py (renamed from gnuradio-examples/python/usrp/fm_tx_2_daughterboards.py)114
-rwxr-xr-xgr-uhd/examples/usrp_spectrum_sense.py (renamed from gnuradio-examples/python/usrp/usrp_spectrum_sense.py)110
7 files changed, 116 insertions, 265 deletions
diff --git a/gnuradio-examples/python/Makefile.am b/gnuradio-examples/python/Makefile.am
index 8165081f8..d3d20e15a 100644
--- a/gnuradio-examples/python/Makefile.am
+++ b/gnuradio-examples/python/Makefile.am
@@ -29,5 +29,4 @@ SUBDIRS = \
network \
ofdm \
pfb \
- tags \
- usrp \ No newline at end of file
+ tags
diff --git a/gnuradio-examples/python/usrp/Makefile.am b/gnuradio-examples/python/usrp/Makefile.am
index 8033b2a7a..addee0d40 100644
--- a/gnuradio-examples/python/usrp/Makefile.am
+++ b/gnuradio-examples/python/usrp/Makefile.am
@@ -25,6 +25,4 @@ ourdatadir = $(exampledir)/usrp
dist_ourdata_SCRIPTS = \
fm_tx_2_daughterboards.py \
- test_dft_analysis.py \
- test_dft_synth.py \
usrp_spectrum_sense.py
diff --git a/gnuradio-examples/python/usrp/test_dft_analysis.py b/gnuradio-examples/python/usrp/test_dft_analysis.py
deleted file mode 100755
index 49db6bf2a..000000000
--- a/gnuradio-examples/python/usrp/test_dft_analysis.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/env python
-
-from gnuradio import gr, gru, blks2
-from gnuradio.wxgui import stdgui2, fftsink2, slider
-from gnuradio.eng_option import eng_option
-from optparse import OptionParser
-import wx
-
-class test_graph (stdgui2.std_top_block):
- def __init__(self, frame, panel, vbox, argv):
- stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
-
- parser = OptionParser (option_class=eng_option)
- (options, args) = parser.parse_args ()
-
- sample_rate = 16e3
- mpoints = 4
- ampl = 1000
- freq = 0
-
- lo_freq = 1e6
- lo_ampl = 1
-
- vbox.Add(slider.slider(panel,
- -sample_rate/2, sample_rate/2,
- self.set_lo_freq), 0, wx.ALIGN_CENTER)
-
-
- src = gr.sig_source_c(sample_rate, gr.GR_CONST_WAVE,
- freq, ampl, 0)
-
- self.lo = gr.sig_source_c(sample_rate, gr.GR_SIN_WAVE,
- lo_freq, lo_ampl, 0)
-
- mixer = gr.multiply_cc()
- self.connect(src, (mixer, 0))
- self.connect(self.lo, (mixer, 1))
-
- # We add these throttle blocks so that this demo doesn't
- # suck down all the CPU available. Normally you wouldn't use these.
- thr = gr.throttle(gr.sizeof_gr_complex, sample_rate)
-
- taps = gr.firdes.low_pass(1, # gain
- 1, # rate
- 1.0/mpoints * 0.4, # cutoff
- 1.0/mpoints * 0.1, # trans width
- gr.firdes.WIN_HANN)
- print len(taps)
- analysis = blks2.analysis_filterbank(mpoints, taps)
-
- self.connect(mixer, thr)
- self.connect(thr, analysis)
-
- for i in range(mpoints):
- fft = fftsink2.fft_sink_c(frame, fft_size=128,
- sample_rate=sample_rate/mpoints,
- fft_rate=5,
- title="Ch %d" % (i,))
- self.connect((analysis, i), fft)
- vbox.Add(fft.win, 1, wx.EXPAND)
-
- def set_lo_freq(self, freq):
- self.lo.set_frequency(freq)
-
-
-
-def main ():
- app = stdgui2.stdapp (test_graph, "Test DFT filterbank")
- app.MainLoop ()
-
-if __name__ == '__main__':
- main ()
diff --git a/gnuradio-examples/python/usrp/test_dft_synth.py b/gnuradio-examples/python/usrp/test_dft_synth.py
deleted file mode 100755
index 99b1c4923..000000000
--- a/gnuradio-examples/python/usrp/test_dft_synth.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env python
-
-from gnuradio import gr, gru, blks2
-from gnuradio.wxgui import stdgui2, fftsink2
-from gnuradio.eng_option import eng_option
-from optparse import OptionParser
-import wx
-import random
-
-
-def make_random_complex_tuple(L, gain=1):
- result = []
- for x in range(L):
- result.append(gain * complex(random.gauss(0, 1),random.gauss(0, 1)))
-
- return tuple(result)
-
-def random_noise_c(gain=1):
- src = gr.vector_source_c(make_random_complex_tuple(32*1024, gain), True)
- return src
-
-
-class test_graph (stdgui2.std_top_block):
- def __init__(self, frame, panel, vbox, argv):
- stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
-
- parser = OptionParser (option_class=eng_option)
- (options, args) = parser.parse_args ()
-
- sample_rate = 16e6
- mpoints = 16
- ampl = 1000
-
- enable = mpoints/2 * [1, 0]
- enable[0] = 1
-
- taps = gr.firdes.low_pass(1, # gain
- 1, # rate
- 1.0/mpoints * 0.4, # cutoff
- 1.0/mpoints * 0.1, # trans width
- gr.firdes.WIN_HANN)
-
- synth = blks2.synthesis_filterbank(mpoints, taps)
-
- null_source = gr.null_source(gr.sizeof_gr_complex)
-
- if 1:
- for i in range(mpoints):
- s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE,
- 300e3, ampl * enable[i], 0)
- self.connect(s, (synth, i))
-
- else:
- for i in range(mpoints):
- if i == 1:
- #s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE,
- # 300e3, ampl * enable[i], 0)
- s = random_noise_c(ampl)
- self.connect(s, (synth, i))
- else:
- self.connect(null_source, (synth, i))
-
-
- # We add these throttle blocks so that this demo doesn't
- # suck down all the CPU available. Normally you wouldn't use these.
- thr = gr.throttle(gr.sizeof_gr_complex, sample_rate)
- fft = fftsink2.fft_sink_c(frame, fft_size=1024,sample_rate=sample_rate)
- vbox.Add(fft.win, 1, wx.EXPAND)
-
- self.connect(synth, thr, fft)
-
-
-def main ():
- app = stdgui2.stdapp (test_graph, "Test DFT filterbank")
- app.MainLoop ()
-
-if __name__ == '__main__':
- main ()
diff --git a/gr-uhd/examples/Makefile.am b/gr-uhd/examples/Makefile.am
index 8fe0c9221..b10b48928 100644
--- a/gr-uhd/examples/Makefile.am
+++ b/gr-uhd/examples/Makefile.am
@@ -27,10 +27,12 @@ ourdatadir = $(exampledir)/uhd
dist_ourdata_SCRIPTS = \
fm_tx4.py \
+ fm_tx_2_daughterboards.py \
max_power.py \
usrp_am_mw_rcv.py \
usrp_nbfm_ptt.py \
usrp_nbfm_rcv.py \
+ usrp_spectrum_sense.py \
usrp_tv_rcv_nogui.py \
usrp_tv_rcv.py \
usrp_wfm_rcv2_nogui.py \
diff --git a/gnuradio-examples/python/usrp/fm_tx_2_daughterboards.py b/gr-uhd/examples/fm_tx_2_daughterboards.py
index 15fdf2831..36d237616 100755
--- a/gnuradio-examples/python/usrp/fm_tx_2_daughterboards.py
+++ b/gr-uhd/examples/fm_tx_2_daughterboards.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005,2006,2007 Free Software Foundation, Inc.
+# Copyright 2005-2007,2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -30,14 +30,10 @@ Side A is 600 Hz tone.
Side B is 350 + 440 Hz tones.
"""
-from gnuradio import gr
+from gnuradio import gr, uhd, blks2
from gnuradio.eng_notation import num_to_str, str_to_num
-from gnuradio import usrp
-from gnuradio import audio
-from gnuradio import blks2
from gnuradio.eng_option import eng_option
from optparse import OptionParser
-from usrpm import usrp_dbid
import math
import sys
@@ -90,8 +86,17 @@ class my_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
- usage="%prog: [options] side-A-tx-freq side-B-tx-freq"
+ usage="%prog: [options] tx-freq0 tx-freq1"
parser = OptionParser (option_class=eng_option, usage=usage)
+ parser.add_option("-a", "--address", type="string",
+ default="addr=192.168.10.2",
+ help="Address of UHD device, [default=%default]")
+ parser.add_option("-A", "--antenna", type="string", default=None,
+ help="select Rx Antenna where appropriate")
+ parser.add_option("-s", "--samp-rate", type="eng_float", default=320e3,
+ help="set sample rate [default=%default]")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set gain in dB (default is midpoint)")
(options, args) = parser.parse_args ()
if len(args) != 2:
@@ -104,32 +109,45 @@ class my_top_block(gr.top_block):
# ----------------------------------------------------------------
# Set up USRP to transmit on both daughterboards
- self.u = usrp.sink_c(nchan=2) # say we want two channels
+ d = uhd.device_find(uhd.device_addr(options.address))
+ uhd_type = d[0].get('type')
- self.dac_rate = self.u.dac_rate() # 128 MS/s
- self.usrp_interp = 400
- self.u.set_interp_rate(self.usrp_interp)
- self.usrp_rate = self.dac_rate / self.usrp_interp # 320 kS/s
+ self.u = uhd.usrp_sink(device_addr=options.address,
+ io_type=uhd.io_type.COMPLEX_FLOAT32,
+ num_channels=2)
- # we're using both daughterboard slots, thus subdev is a 2-tuple
- self.subdev = (self.u.db(0, 0), self.u.db(1, 0))
- print "Using TX d'board %s" % (self.subdev[0].side_and_name(),)
- print "Using TX d'board %s" % (self.subdev[1].side_and_name(),)
-
- # set up the Tx mux so that
- # channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
- self.u.set_mux(0xba98)
+ # Set up USRP system based on type
+ if(uhd_type == "usrp"):
+ self.u.set_subdev_spec("A:0 B:0")
+ tr0 = uhd.tune_request(freq0)
+ tr1 = uhd.tune_request(freq1)
- self.subdev[0].set_gain(self.subdev[0].gain_range()[1]) # set max Tx gain
- self.subdev[1].set_gain(self.subdev[1].gain_range()[1]) # set max Tx gain
+ else:
+ if abs(freq0 - freq1) > 5.5e6:
+ sys.stderr.write("\nError: When not using two separate d'boards, frequencies must bewithin 5.5MHz of each other.\n")
+ raise SystemExit
+
+ self.u.set_subdev_spec("A:0 A:0")
+
+ mid_freq = (freq0 + freq1)/2.0
+ tr0 = uhd.tune_request(freq0, rf_freq=mid_freq,
+ rf_freq_policy=uhd.tune_request.POLICY_MANUAL)
+
+ tr1 = uhd.tune_request(freq1, rf_freq=mid_freq,
+ rf_freq_policy=uhd.tune_request.POLICY_MANUAL)
+
+ # Use the tune requests to tune each channel
+ self.set_freq(tr0, 0)
+ self.set_freq(tr1, 1)
+
+ self.usrp_rate = options.samp_rate
- self.set_freq(0, freq0)
- self.set_freq(1, freq1)
- self.subdev[0].set_enable(True) # enable transmitter
- self.subdev[1].set_enable(True) # enable transmitter
+ self.u.set_samp_rate(self.usrp_rate)
+ dev_rate = self.u.get_samp_rate()
# ----------------------------------------------------------------
- # build two signal sources, interleave them, amplify and connect them to usrp
+ # build two signal sources, interleave them, amplify and
+ # connect them to usrp
sig0 = example_signal_0(self.usrp_rate)
sig1 = example_signal_1(self.usrp_rate)
@@ -138,43 +156,45 @@ class my_top_block(gr.top_block):
self.connect(sig0, (intl, 0))
self.connect(sig1, (intl, 1))
- # apply some gain
- if_gain = 10000
- ifamp = gr.multiply_const_cc(if_gain)
-
+ # Correct for any difference in requested and actual rates
+ rrate = self.usrp_rate / dev_rate
+ resamp = blks2.pfb_arb_resampler_ccf(rrate)
+
# and wire them up
- self.connect(intl, ifamp, self.u)
-
+ self.connect(intl, resamp, self.u)
+
+ if options.gain is None:
+ # if no gain was specified, use the mid-point in dB
+ g = self.u.get_gain_range()
+ options.gain = float(g.start()+g.stop())/2.0
+
+ self.set_gain(options.gain, 0)
+ self.set_gain(options.gain, 1)
- def set_freq(self, side, target_freq):
+ def set_freq(self, target_freq, chan):
"""
Set the center frequency we're interested in.
@param side: 0 = side A, 1 = side B
@param target_freq: frequency in Hz
@rtype: 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.
"""
- print "Tuning side %s to %sHz" % (("A", "B")[side], num_to_str(target_freq))
- r = self.u.tune(self.subdev[side].which(), self.subdev[side], target_freq)
+ print "Tuning channel %s to %sHz" % \
+ (chan, num_to_str(target_freq))
+
+ r = self.u.set_center_freq(target_freq, chan)
+
if r:
- print " r.baseband_freq =", num_to_str(r.baseband_freq)
- print " r.dxc_freq =", num_to_str(r.dxc_freq)
- print " r.residual_freq =", num_to_str(r.residual_freq)
- print " r.inverted =", r.inverted
- print " OK"
return True
else:
- print " Failed!"
+ print " Set Frequency Failed!"
return False
+ def set_gain(self, gain, chan):
+ self.u.set_gain(gain, chan)
if __name__ == '__main__':
try:
diff --git a/gnuradio-examples/python/usrp/usrp_spectrum_sense.py b/gr-uhd/examples/usrp_spectrum_sense.py
index 90adf1671..e89745b3b 100755
--- a/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
+++ b/gr-uhd/examples/usrp_spectrum_sense.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2005,2007 Free Software Foundation, Inc.
+# Copyright 2005,2007,2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -20,16 +20,16 @@
# Boston, MA 02110-1301, USA.
#
-from gnuradio import gr, gru, eng_notation, optfir, window
+from gnuradio import gr, eng_notation, window
from gnuradio import audio
-from gnuradio import usrp
+from gnuradio import uhd
from gnuradio.eng_option import eng_option
from optparse import OptionParser
-from usrpm import usrp_dbid
import sys
import math
import struct
+sys.stderr.write("Warning: this is known to have issues on some machines+Python version combinations to seg fault due to the callback in bin_statitics. If you figure out why, we'd love to hear about it!\n")
class tune(gr.feval_dd):
"""
@@ -41,17 +41,20 @@ class tune(gr.feval_dd):
def eval(self, ignore):
"""
- This method is called from gr.bin_statistics_f when it wants to change
- the center frequency. This method tunes the front end to the new center
- frequency, and returns the new frequency as its result.
+ This method is called from gr.bin_statistics_f when it wants
+ to change the center frequency. This method tunes the front
+ end to the new center frequency, and returns the new frequency
+ as its result.
"""
+
try:
- # We use this try block so that if something goes wrong from here
- # down, at least we'll have a prayer of knowing what went wrong.
- # Without this, you get a very mysterious:
+ # We use this try block so that if something goes wrong
+ # from here down, at least we'll have a prayer of knowing
+ # what went wrong. Without this, you get a very
+ # mysterious:
#
- # terminate called after throwing an instance of 'Swig::DirectorMethodException'
- # Aborted
+ # terminate called after throwing an instance of
+ # 'Swig::DirectorMethodException' Aborted
#
# message on stderr. Not exactly helpful ;)
@@ -68,7 +71,7 @@ class parse_msg(object):
self.vlen = int(msg.arg2())
assert(msg.length() == self.vlen * gr.sizeof_float)
- # FIXME consider using Numarray or NumPy vector
+ # FIXME consider using NumPy array
t = msg.to_string()
self.raw_data = t
self.data = struct.unpack('%df' % (self.vlen,), t)
@@ -81,24 +84,25 @@ class my_top_block(gr.top_block):
usage = "usage: %prog [options] min_freq max_freq"
parser = OptionParser(option_class=eng_option, usage=usage)
- parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0,0),
- help="select USRP Rx side A or B (default=A)")
+ parser.add_option("-a", "--address", type="string",
+ default="addr=192.168.10.2",
+ help="Address of UHD device, [default=%default]")
+ parser.add_option("-A", "--antenna", type="string", default=None,
+ help="select Rx Antenna where appropriate")
+ parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6,
+ help="set sample rate [default=%default]")
parser.add_option("-g", "--gain", type="eng_float", default=None,
help="set gain in dB (default is midpoint)")
- parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS",
+ parser.add_option("", "--tune-delay", type="eng_float",
+ default=1e-3, metavar="SECS",
help="time to delay (in seconds) after changing frequency [default=%default]")
- parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS",
+ parser.add_option("", "--dwell-delay", type="eng_float",
+ default=10e-3, metavar="SECS",
help="time to dwell (in seconds) at a given frequncy [default=%default]")
parser.add_option("-F", "--fft-size", type="int", default=256,
help="specify number of FFT bins [default=%default]")
- parser.add_option("-d", "--decim", type="intx", default=16,
- help="set decimation to DECIM [default=%default]")
parser.add_option("", "--real-time", action="store_true", default=False,
help="Attempt to enable real-time scheduling")
- parser.add_option("-B", "--fusb-block-size", type="int", default=0,
- help="specify fast usb block size [default=%default]")
- parser.add_option("-N", "--fusb-nblocks", type="int", default=0,
- help="specify number of fast usb blocks [default=%default]")
(options, args) = parser.parse_args()
if len(args) != 2:
@@ -109,11 +113,11 @@ class my_top_block(gr.top_block):
self.max_freq = eng_notation.str_to_num(args[1])
if self.min_freq > self.max_freq:
- self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them
+ # swap them
+ self.min_freq, self.max_freq = self.max_freq, self.min_freq
self.fft_size = options.fft_size
-
if not options.real_time:
realtime = False
else:
@@ -125,36 +129,14 @@ class my_top_block(gr.top_block):
realtime = False
print "Note: failed to enable realtime scheduling"
- # If the user hasn't set the fusb_* parameters on the command line,
- # pick some values that will reduce latency.
-
- if 1:
- if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
- if realtime: # be more aggressive
- options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
- options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
- else:
- options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
- options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16)
-
- #print "fusb_block_size =", options.fusb_block_size
- #print "fusb_nblocks =", options.fusb_nblocks
-
# build graph
-
- self.u = usrp.source_c(fusb_block_size=options.fusb_block_size,
- fusb_nblocks=options.fusb_nblocks)
-
-
- adc_rate = self.u.adc_rate() # 64 MS/s
- usrp_decim = options.decim
- self.u.set_decim_rate(usrp_decim)
- usrp_rate = adc_rate / usrp_decim
-
- self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
- self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
- print "Using RX d'board %s" % (self.subdev.side_and_name(),)
+ self.u = uhd.usrp_source(device_addr=options.address,
+ io_type=uhd.io_type.COMPLEX_FLOAT32,
+ num_channels=1)
+ usrp_rate = options.samp_rate
+ self.u.set_samp_rate(usrp_rate)
+ dev_rate = self.u.get_samp_rate()
s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
@@ -186,7 +168,8 @@ class my_top_block(gr.top_block):
self.msgq = gr.msg_queue(16)
self._tune_callback = tune(self) # hang on to this to keep it from being GC'd
stats = gr.bin_statistics_f(self.fft_size, self.msgq,
- self._tune_callback, tune_delay, dwell_delay)
+ self._tune_callback, tune_delay,
+ dwell_delay)
# FIXME leave out the log10 until we speed it up
#self.connect(self.u, s2v, fft, c2mag, log, stats)
@@ -194,8 +177,8 @@ class my_top_block(gr.top_block):
if options.gain is None:
# if no gain was specified, use the mid-point in dB
- g = self.subdev.gain_range()
- options.gain = float(g[0]+g[1])/2
+ g = self.u.get_gain_range()
+ options.gain = float(g.start()+g.stop())/2.0
self.set_gain(options.gain)
print "gain =", options.gain
@@ -209,6 +192,7 @@ class my_top_block(gr.top_block):
if not self.set_freq(target_freq):
print "Failed to set frequency to", target_freq
+ sys.exit(1)
return target_freq
@@ -219,17 +203,15 @@ class my_top_block(gr.top_block):
@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.
"""
- return self.u.tune(0, self.subdev, target_freq)
+ r = self.u.set_center_freq(target_freq)
+ if r:
+ return True
+ return False
def set_gain(self, gain):
- self.subdev.set_gain(gain)
+ self.u.set_gain(gain)
def main_loop(tb):
@@ -254,7 +236,7 @@ def main_loop(tb):
if __name__ == '__main__':
tb = my_top_block()
try:
- tb.start() # start executing flow graph in another thread...
+ tb.start()
main_loop(tb)
except KeyboardInterrupt: