summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/limbo
diff options
context:
space:
mode:
authorjcorgan2007-09-18 18:59:00 +0000
committerjcorgan2007-09-18 18:59:00 +0000
commite692e71305ecd71d3681fe37f3d76f350d67e276 (patch)
treedc320c9261303aa9a92f4d12bdba85f82720d1bf /gnuradio-examples/python/limbo
parent6ad04a094ced626e46c210b9847eae46a1ae8e67 (diff)
downloadgnuradio-e692e71305ecd71d3681fe37f3d76f350d67e276.tar.gz
gnuradio-e692e71305ecd71d3681fe37f3d76f350d67e276.tar.bz2
gnuradio-e692e71305ecd71d3681fe37f3d76f350d67e276.zip
Merge r6461:6464 from jcorgan/t162-staging into trunk.
* Final gr.top_block and gr.hier_block2 implementation inside gnuradio-core/src/lib/runtime * Implementation of gr.hier_block2 versions of all the old-style blocks in blks. These live in blks2. * Addition of gr.hier_block2 based versions of gr-wxgui blocks * Conversion of all the example code in gnuradio-examples to use this new code * Conversion of all the gr-utils scripts to use the new code The OFDM examples and related hierarchical blocks have not yet been converted. Code in the rest of the tree that is outside the core and example components has also not yet been converted. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6466 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-examples/python/limbo')
-rw-r--r--gnuradio-examples/python/limbo/networking/Makefile.am23
-rwxr-xr-xgnuradio-examples/python/limbo/networking/measurement_slave.py241
-rw-r--r--gnuradio-examples/python/limbo/sounder/Makefile.am30
-rw-r--r--gnuradio-examples/python/limbo/sounder/sounder_rx.py53
-rw-r--r--gnuradio-examples/python/limbo/sounder/sounder_tx.py45
-rw-r--r--gnuradio-examples/python/limbo/sounder/usrp_sink.py117
-rwxr-xr-xgnuradio-examples/python/limbo/sounder/usrp_sounder_rx.py95
-rwxr-xr-xgnuradio-examples/python/limbo/sounder/usrp_sounder_tx.py110
-rw-r--r--gnuradio-examples/python/limbo/sounder/usrp_source.py126
9 files changed, 840 insertions, 0 deletions
diff --git a/gnuradio-examples/python/limbo/networking/Makefile.am b/gnuradio-examples/python/limbo/networking/Makefile.am
new file mode 100644
index 000000000..d30294537
--- /dev/null
+++ b/gnuradio-examples/python/limbo/networking/Makefile.am
@@ -0,0 +1,23 @@
+#
+# Copyright 2006 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.
+#
+
+EXTRA_DIST = \
+ measurement_slave.py \ No newline at end of file
diff --git a/gnuradio-examples/python/limbo/networking/measurement_slave.py b/gnuradio-examples/python/limbo/networking/measurement_slave.py
new file mode 100755
index 000000000..a2b04151f
--- /dev/null
+++ b/gnuradio-examples/python/limbo/networking/measurement_slave.py
@@ -0,0 +1,241 @@
+#!/usr/bin/env python
+#
+# Copyright 2006 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.
+#
+
+import struct
+import socket
+import asyncore
+import sys
+import optparse
+import random
+from gnuradio.eng_option import eng_option
+import gnuradio.gr.gr_threading as _threading
+
+LOOP_TIMEOUT = 0.001
+BROADCAST_ADDR = '255.255.255.255'
+
+BROADCAST_PORT = 27010 # UDP
+CONTROL_PORT = 27011 # TCP
+
+PKT_HEADER_SIZE = 4 # 32-bit int
+
+logfile = None
+
+def unpack_header(s):
+ (len,) = struct.unpack('!i', s)
+ return (len,)
+
+def pack_header(len):
+ return struct.pack('!i', len)
+
+
+class control_port_listener(asyncore.dispatcher):
+ def __init__(self, port=CONTROL_PORT, udp_socket=None, verbose=False):
+ """
+ @param port: TCP port to listen on.
+ @type port: int
+ """
+ asyncore.dispatcher.__init__(self)
+
+ self._verbose = verbose
+ self._udp_socket = udp_socket
+
+ host = '' # symbolic name for localhost
+ self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.set_reuse_addr()
+
+ try:
+ self.bind((host, port))
+ except socket.error, err:
+ sys.stderr.write('Failed to bind to %s: %s\n' %
+ ((host, port), os.strerror (err.args[0]),))
+ sys.exit(1)
+
+ self.listen(3)
+
+ def handle_accept(self):
+ socket, addr = self.accept()
+ sys.stderr.write("handle_accept: %r\n" % (addr,))
+ if not(socket is None):
+ # instantiate a server
+ s = control_server(socket, addr, self._udp_socket, self._verbose)
+
+
+class gr_dispatcher(asyncore.dispatcher):
+ def __init__(self, sock=None, map=None):
+ asyncore.dispatcher.__init__(self, sock=sock, map=map)
+
+ def read_packet(self):
+ """
+ Returns None or packet
+ """
+ s = self.recvall(PKT_HEADER_SIZE)
+ if s == '':
+ return None
+
+ (payload_len,) = unpack_header(s)
+
+ payload_len = int(payload_len)
+
+ if payload_len == 0:
+ payload = ''
+ else:
+ payload = self.recvall(payload_len)
+ if len(payload) != payload_len:
+ sys.stderr.write ('short recv, expected %d bytes, got %d\n' % (
+ payload_len, len(payload)))
+ raise RuntimeError, "short recv"
+
+ return payload
+
+ def recvall(self, buffer_size):
+ result = ''
+ while len(result) < buffer_size:
+ data = self.recv(buffer_size - len(result))
+ if not data:
+ return ''
+ result += data
+ return result
+
+
+class pkt_receiver_thread(_threading.Thread):
+ def __init__(self, socket):
+ _threading.Thread.__init__(self)
+ self.setDaemon(1)
+ self.socket = socket
+ self.keep_running = True
+ self.start()
+
+ def run(self):
+ while self.keep_running:
+ pkt, sender = self.socket.recvfrom(10000)
+ if pkt:
+ if len(pkt) > 2:
+ t = struct.unpack('!H', pkt[0:2])
+ seqno = t[0]
+ else:
+ seqno = -1
+
+ logfile.write('RCVD seqno %4d len %4d from %s\n' % (seqno, len(pkt), sender))
+ logfile.flush()
+
+
+class control_server(gr_dispatcher):
+ def __init__(self, socket, addr, udp_socket, verbose=False):
+ gr_dispatcher.__init__(self, sock=socket)
+
+ self._udp_socket = udp_socket
+ self.verbose = verbose
+ self.setblocking(1)
+
+ def writable(self):
+ return False
+
+ def handle_read(self):
+ pkt = self.read_packet()
+ if pkt:
+ annotate = 'ANNOTATE'
+ if pkt.startswith(annotate):
+ logfile.write(pkt[len(annotate)+1:])
+ logfile.write('\n')
+ logfile.flush()
+ elif pkt.startswith('SEND'):
+ tokens = pkt.split()
+ if len(tokens) < 4:
+ invalid_packet(pkt)
+ else:
+ npkts = int(tokens[1])
+ size = int(tokens[2])
+ power = float(tokens[3])
+ send_test_packets(self._udp_socket, npkts, size, power)
+ else:
+ invalid_packet(pkt)
+
+ def handle_close(self):
+ self.close()
+
+
+def invalid_packet(pkt):
+ sys.stderr.write('received unrecognized packet: %s\n' % (pkt,))
+
+
+def make_random_payload(size):
+ p = [0] * size
+ if 1:
+ for i in range(size):
+ p[i] = chr(random.randint(0, 255))
+ else:
+ for i in range(size):
+ p[i] = chr(i % 256)
+ return ''.join(p)
+
+
+def send_test_packets(udp_socket, npkts, size, power):
+ # we ignore power for now...
+ size = max(2, size)
+ payload = make_random_payload(size - 2)
+ for n in range(npkts):
+ pkt = struct.pack('!H', n) + payload
+ udp_socket.sendto(pkt, (BROADCAST_ADDR, BROADCAST_PORT))
+ #udp_socket.sendall(pkt)
+
+
+def open_udp_broadcast_socket(gr0_host_ip, port):
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+# s.bind((gr0_host_ip, port))
+ s.bind(('', port))
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+# s.connect((BROADCAST_ADDR, port))
+ return s
+
+
+def main():
+ global logfile
+
+ usage = 'usage: %prog [options] gr0-ip-addr'
+ parser = optparse.OptionParser (option_class=eng_option, usage=usage)
+ parser.add_option('-l', '--logfile', type='string', default=None,
+ help="specify log file name [default=<stdout>]")
+ parser.add_option('-v', '--verbose', action="store_true", default=False,
+ help="enable verbose diagnostics")
+
+ (options, args) = parser.parse_args ()
+ if len(args) != 1:
+ parser.print_help()
+ sys.exit(1)
+
+ gr0_ip_addr = args[0]
+ if options.logfile is None:
+ logfile = sys.stdout
+ else:
+ logfile = file(options.logfile, 'w')
+
+ udp_socket = open_udp_broadcast_socket(gr0_ip_addr, BROADCAST_PORT)
+ R = pkt_receiver_thread(udp_socket)
+ L = control_port_listener(CONTROL_PORT, udp_socket=udp_socket, verbose=options.verbose)
+ asyncore.loop(LOOP_TIMEOUT)
+
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass
diff --git a/gnuradio-examples/python/limbo/sounder/Makefile.am b/gnuradio-examples/python/limbo/sounder/Makefile.am
new file mode 100644
index 000000000..9814d80ef
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Copyright 2007 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.
+#
+
+EXTRA_DIST = \
+ usrp_sounder_rx.py \
+ usrp_sounder_tx.py \
+ usrp_source.py \
+ usrp_sink.py \
+ sounder_rx.py \
+ sounder_tx.py
+
+MOSTLYCLEANFILES = *.pyc *~ *.dat
diff --git a/gnuradio-examples/python/limbo/sounder/sounder_rx.py b/gnuradio-examples/python/limbo/sounder/sounder_rx.py
new file mode 100644
index 000000000..d24eb8efa
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/sounder_rx.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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, usrp, eng_notation
+from usrp_source import usrp_source_c
+import math
+
+n2s = eng_notation.num_to_str
+
+class sounder_rx(gr.hier_block2):
+ """
+ Creates a channel sounder receiver block with the given parameters.
+ """
+
+ def __init__(self, chip_rate, degree, verbose):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.hier_block2.__init__(self,
+ "sounder_rx", # Block typename
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+
+ self._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
+ self._length = 2**self._degree-1
+ self._rep_rate = self._chip_rate/float(self._length)
+
+ if self._verbose:
+ print "Using PN sequence of degree", self._degree, "length", self._length
+ print "Sequence repetition rate is", n2s(self._rep_rate), "per sec"
+
+ self.connect(self, gr.pn_correlator_cc(self._degree), self)
diff --git a/gnuradio-examples/python/limbo/sounder/sounder_tx.py b/gnuradio-examples/python/limbo/sounder/sounder_tx.py
new file mode 100644
index 000000000..dcdd9fc5c
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/sounder_tx.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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, usrp, eng_notation
+import math
+
+n2s = eng_notation.num_to_str
+
+class sounder_tx(gr.hier_block2):
+ """
+ Creates a channel sounder generator with the given parameters.
+ """
+
+ def __init__(self, degree, chip_rate, verbose):
+ gr.hier_block2.__init__(self,
+ "sounder_tx", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
+
+ self._degree = degree
+ self._chip_rate = chip_rate
+ self._verbose = verbose
+ self._length = 2**degree-1
+
+ # Connect PN source to block output
+ self.connect(gr.glfsr_source_f(degree), self)
diff --git a/gnuradio-examples/python/limbo/sounder/usrp_sink.py b/gnuradio-examples/python/limbo/sounder/usrp_sink.py
new file mode 100644
index 000000000..34b610704
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/usrp_sink.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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, usrp, eng_notation
+n2s = eng_notation.num_to_str
+
+# Hierarchical block implementing a USRP sink for complex floats,
+# with convenience functions for tuning, interpolation, etc.
+#
+class usrp_sink_c(gr.hier_block2):
+ """
+ Create a USRP sink object accepting complex floats.
+ """
+ def __init__(self, which=0, subdev_spec=None, if_rate=None,
+ freq=0.0, calibration=0.0, verbose=False):
+ # Call hierarchical block constructor
+ gr.hier_block2.__init__(self,
+ "usrp_sink_c", # Block typename
+ gr.io_signature(1,1,gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(0,0,0)) # Output signature
+
+ self._verbose = verbose
+ self._u = usrp.sink_c(which)
+ if self._verbose:
+ print 'DAC sample rate is', n2s(self._u.dac_rate()), "sps"
+ self.set_subdev(subdev_spec)
+ self.set_if_rate(if_rate)
+ self.set_calibration(calibration)
+ self.tune(freq)
+ self.connect(self, self._u)
+
+ def set_subdev(self, subdev_spec):
+ if subdev_spec is None:
+ subdev_spec = self.pick_subdevice()
+ self._subdev = usrp.selected_subdev(self._u, subdev_spec)
+ self._u.set_mux(usrp.determine_tx_mux_value(self._u, subdev_spec))
+ if self._verbose:
+ print 'TX using', self._subdev.name(), 'daughterboard'
+
+ def pick_subdevice(self):
+ """
+ The user didn't specify a subdevice.
+ If there's a daughterboard on A, select A.
+ If there's a daughterboard on B, select B.
+ Otherwise, select A.
+ """
+ if self._u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
+ return (0, 0)
+ if self._u.db[1][0].dbid() >= 0:
+ return (1, 0)
+ return (0, 0)
+
+ def set_if_rate(self, if_rate):
+ # If no IF rate specified, set to maximum interpolation
+ if if_rate is None:
+ self._interp = 512
+ else:
+ self._interp = 4*int(self._u.dac_rate()/(4.0*if_rate)+0.5)
+
+
+ self._if_rate = self._u.dac_rate()/self._interp
+ self._u.set_interp_rate(self._interp)
+
+ if self._verbose:
+ print "USRP interpolation rate is", self._interp
+ print "USRP IF rate is", n2s(self._if_rate), "sps"
+
+ def set_calibration(self, calibration):
+ self._cal = calibration
+ if self._verbose:
+ print "Using frequency calibration offset of", n2s(calibration), "Hz"
+
+ def tune(self, freq):
+ """
+ Set the center frequency we're interested in.
+
+ @param target_freq: frequency in Hz
+ @type: 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.
+ """
+ self._tune_result = self._u.tune(self._subdev._which, self._subdev, freq+self._cal)
+ if self._tune_result:
+ if self._verbose:
+ print "Baseband frequency is", n2s(self._tune_result.baseband_freq), "Hz"
+ print "DXC frequency is", n2s(self._tune_result.dxc_freq), "Hz"
+ print "Center frequency is", n2s(freq), "Hz"
+ print "Residual frequency is", n2s(self._tune_result.residual_freq), "Hz"
+ return True
+
+ return False
+
+if __name__ == '__main__':
+ sink = usrp_sink_c(verbose=True)
+
diff --git a/gnuradio-examples/python/limbo/sounder/usrp_sounder_rx.py b/gnuradio-examples/python/limbo/sounder/usrp_sounder_rx.py
new file mode 100755
index 000000000..6b85281ad
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/usrp_sounder_rx.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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.eng_option import eng_option
+from optparse import OptionParser
+from usrp_source import usrp_source_c
+from sounder_rx import sounder_rx
+
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_rx(gr.top_block):
+ def __init__(self, options):
+ gr.top_block.__init__(self, "usrp_sounder_rx")
+ self._options = options
+ self._u = usrp_source_c(0,
+ self._options.rx_subdev_spec,
+ self._options.gain,
+ self._options.chip_rate,
+ self._options.freq,
+ self._options.cal,
+ self._options.verbose)
+ self._options.chip_rate = self._u._if_rate
+ self._length = 2**self._options.degree-1
+ self._receiver = sounder_rx(self._options.chip_rate,
+ self._options.degree,
+ self._options.verbose)
+
+ samples = 100 * self._length**2
+
+ head = gr.head(gr.sizeof_gr_complex, samples)
+ c2m = gr.complex_to_mag()
+ s2v = gr.stream_to_vector(gr.sizeof_float, self._length)
+ lpf = gr.single_pole_iir_filter_ff(self._options.alpha, self._length)
+ v2s = gr.vector_to_stream(gr.sizeof_float, self._length)
+ sink = gr.file_sink(gr.sizeof_float, "impulse.dat")
+
+ self.connect(self._u, head, self._receiver, c2m, s2v, lpf, v2s, sink)
+
+ if self._options.verbose:
+ print "Chip rate is", n2s(self._options.chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._options.chip_rate), "sec"
+ print "Using PN code of degree", self._options.degree
+
+def main():
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B (default=first found)")
+ parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+ help="set center frequency (default=%default)")
+ parser.add_option("-c", "--cal", type="eng_float", default=0.0,
+ help="set frequency calibration offset (default=%default)")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="print extra debugging info")
+ parser.add_option("-d", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, default=%default)")
+ parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
+ help="set sounder chip rate (default=%default)")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set receiver gain (default=%default)")
+ parser.add_option("", "--alpha", type="eng_float", default=1.0,
+ help="set smoothing constant (default=%default)")
+ (options, args) = parser.parse_args()
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ top_block = usrp_sounder_rx(options)
+
+ try:
+ top_block.run()
+ except KeyboardInterrupt:
+ pass
+
+if __name__ == '__main__':
+ main ()
diff --git a/gnuradio-examples/python/limbo/sounder/usrp_sounder_tx.py b/gnuradio-examples/python/limbo/sounder/usrp_sounder_tx.py
new file mode 100755
index 000000000..ae531d510
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/usrp_sounder_tx.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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.eng_option import eng_option
+from optparse import OptionParser
+from usrp_sink import usrp_sink_c
+from sounder_tx import sounder_tx
+
+n2s = eng_notation.num_to_str
+
+class usrp_sounder_tx(gr.top_block):
+ def __init__(self, subdev_spec, freq, cal, verbose, degree, chip_rate, amplitude):
+
+ # Call hierarchical block constructor
+ # Top-level blocks have no inputs or outputs
+ gr.top_block.__init__(self, "usrp_sounder_tx")
+ self._freq = freq
+ self._cal = cal
+ self._verbose = verbose
+ self._degree = degree
+ self._length = 2**degree-1
+ self._amplitude = amplitude
+
+ self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, self._verbose)
+ self._chip_rate = self._u._if_rate
+ self._max_time = float(self._length)/self._chip_rate
+ self._pn = sounder_tx(self._degree, self._chip_rate, self._verbose)
+ self._gain = gr.multiply_const_ff(amplitude)
+ self._f2c = gr.float_to_complex()
+ self.connect(self._pn, self._gain, self._f2c, self._u)
+
+ if self._verbose:
+ print "Chip rate is", n2s(self._chip_rate), "chips/sec"
+ print "Resolution is", n2s(1.0/self._chip_rate), "sec"
+ print "Using PN code of degree", self._degree, "length", 2**self._degree-1
+ print "Maximum measurable impulse response is", n2s(self._max_time), "sec"
+ print "Output amplitude is", amplitude
+
+
+def main():
+ parser = OptionParser(option_class=eng_option)
+
+ # Transmit path options
+ parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
+ help="select USRP Rx side A or B (default=first found)")
+ parser.add_option("-f", "--freq", type="eng_float", default=0.0,
+ help="set center frequency (default=%default)")
+ parser.add_option("-c", "--cal", type="eng_float", default=0.0,
+ help="set frequency calibration offset (default=%default)")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="print extra debugging info")
+ parser.add_option("-d", "--degree", type="int", default=10,
+ help="set PN code degree (length=2**degree-1, default=%default)")
+ parser.add_option("-r", "--chip-rate", type="eng_float", default=8e6,
+ help="set sounder chip rate (default=%default)")
+ parser.add_option("-g", "--amplitude", type="eng_float", default=8000.0,
+ help="set output amplitude (default=%default)")
+ parser.add_option("", "--real-time", action="store_true", default=False,
+ help="Attempt to enable real-time scheduling")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ if not options.real_time:
+ realtime = False
+ else:
+ # Attempt to enable realtime scheduling
+ r = gr.enable_realtime_scheduling()
+ if r == gr.RT_OK:
+ realtime = True
+ else:
+ realtime = False
+ print "Note: failed to enable realtime scheduling"
+
+ # Create an instance of a hierarchical block
+ top_block = usrp_sounder_tx(options.tx_subdev_spec, options.freq, options.cal,
+ options.verbose, options.degree, options.chip_rate,
+ options.amplitude)
+
+ try:
+ # Run forever
+ top_block.run()
+ except KeyboardInterrupt:
+ # Ctrl-C exits
+ pass
+
+if __name__ == '__main__':
+ main ()
diff --git a/gnuradio-examples/python/limbo/sounder/usrp_source.py b/gnuradio-examples/python/limbo/sounder/usrp_source.py
new file mode 100644
index 000000000..63eb3ce2b
--- /dev/null
+++ b/gnuradio-examples/python/limbo/sounder/usrp_source.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 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, usrp, eng_notation
+n2s = eng_notation.num_to_str
+
+# Hierarchical block implementing a USRP source for complex floats,
+# with convenience functions for gain, tune, decimation, etc.
+#
+class usrp_source_c(gr.hier_block2):
+ """
+ Create a USRP source object supplying complex floats.
+ """
+ def __init__(self, which=0, subdev_spec=None, gain=None, if_rate=None,
+ freq=0.0, calibration=0.0, verbose=False):
+ # Call hierarchical block constructor
+ gr.hier_block2.__init__(self,
+ "usrp_source_c", # Block typename
+ gr.io_signature(0,0,0), # Input signature
+ gr.io_signature(1,1,gr.sizeof_gr_complex)) # Output signature
+
+ self._verbose = verbose
+ self._u = usrp.source_c(which)
+ if self._verbose:
+ print 'ADC sample rate is', n2s(self._u.adc_rate()), "sps"
+ self.set_subdev(subdev_spec)
+ self.set_if_rate(if_rate)
+ self.set_gain(gain)
+ self.set_calibration(calibration)
+ self.tune(freq)
+ self.connect(self._u, self)
+
+ def set_subdev(self, subdev_spec):
+ if subdev_spec is None:
+ subdev_spec = self.pick_subdevice()
+ self._subdev = usrp.selected_subdev(self._u, subdev_spec)
+ self._u.set_mux(usrp.determine_rx_mux_value(self._u, subdev_spec))
+ if self._verbose:
+ print 'RX using', self._subdev.name(), 'daughterboard'
+
+ def pick_subdevice(self):
+ """
+ The user didn't specify a subdevice.
+ If there's a daughterboard on A, select A.
+ If there's a daughterboard on B, select B.
+ Otherwise, select A.
+ """
+ if self._u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem
+ return (0, 0)
+ if self._u.db[1][0].dbid() >= 0:
+ return (1, 0)
+ return (0, 0)
+
+ def set_if_rate(self, if_rate):
+ # If no IF rate specified, set to maximum decimation
+ if if_rate is None:
+ self._decim = 256
+ else:
+ self._decim = int(self._u.adc_rate()/if_rate)
+
+ self._u.set_decim_rate(self._decim)
+ self._if_rate = self._u.adc_rate()/self._decim
+
+ if self._verbose:
+ print "USRP decimation rate is", self._decim
+ print "USRP IF rate is", n2s(self._if_rate), "sps"
+
+ def set_gain(self, gain):
+ # If no gain specified, set to midrange
+ if gain is None:
+ g = self._subdev.gain_range()
+ gain = (g[0]+g[1])/2.0
+ self._gain = gain
+ self._subdev.set_gain(self._gain)
+ if self._verbose:
+ print "USRP gain set to", self._gain
+
+ def set_calibration(self, calibration):
+ self._cal = calibration
+ if self._verbose:
+ print "Using frequency calibration offset of", n2s(calibration), "Hz"
+
+ def tune(self, freq):
+ """
+ Set the center frequency we're interested in.
+
+ @param target_freq: frequency in Hz
+ @type: 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.
+ """
+ self._tune_result = usrp.tune(self._u, 0, self._subdev, freq+self._cal)
+ if self._tune_result:
+ if self._verbose:
+ print "Baseband frequency is", n2s(self._tune_result.baseband_freq), "Hz"
+ print "DXC frequency is", n2s(self._tune_result.dxc_freq), "Hz"
+ print "Center frequency is", n2s(freq), "Hz"
+ print "Residual frequency is", n2s(self._tune_result.residual_freq), "Hz"
+ return True
+
+ return False
+
+if __name__ == '__main__':
+ src = usrp_source_c(verbose=True)