summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/digital
diff options
context:
space:
mode:
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2007-02-06 00:10:32 +0000
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2007-02-06 00:10:32 +0000
commitc4e072e8a58800f2dfd6c1e5e95009dd783061be (patch)
tree575da3b788adacda6aeff19c730394ce1ddbdbc3 /gnuradio-examples/python/digital
parentb431e9f594607e61866aef2bab73240c21c4cc6f (diff)
Merged r4354:4390 from developer branch jcorgan/digital into trunk.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4391 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-examples/python/digital')
-rw-r--r--gnuradio-examples/python/digital/Makefile.am1
-rw-r--r--gnuradio-examples/python/digital/README7
-rwxr-xr-xgnuradio-examples/python/digital/benchmark_tx.py18
-rwxr-xr-xgnuradio-examples/python/digital/run_length.py83
-rw-r--r--gnuradio-examples/python/digital/transmit_path.py8
5 files changed, 112 insertions, 5 deletions
diff --git a/gnuradio-examples/python/digital/Makefile.am b/gnuradio-examples/python/digital/Makefile.am
index ad2fa4d688..93f1bafea8 100644
--- a/gnuradio-examples/python/digital/Makefile.am
+++ b/gnuradio-examples/python/digital/Makefile.am
@@ -28,6 +28,7 @@ EXTRA_DIST = \
pick_bitrate.py \
receive_path.py \
rx_voice.py \
+ run_length.py \
transmit_path.py \
tunnel.py \
tx_voice.py
diff --git a/gnuradio-examples/python/digital/README b/gnuradio-examples/python/digital/README
index 61801f73d1..5382498f55 100644
--- a/gnuradio-examples/python/digital/README
+++ b/gnuradio-examples/python/digital/README
@@ -75,3 +75,10 @@ Likewise, on machine B:
This now uses a carrier sense MAC, so you should be able to ssh
between the machines, web browse, etc.
+
+* run_length.py: This program takes a single argument '-f FILE' and
+outputs the number of runs of similar bits within the file. It is
+useful as a diagnostic tool when experimenting with line coding or
+whitening algorithms.
+
+
diff --git a/gnuradio-examples/python/digital/benchmark_tx.py b/gnuradio-examples/python/digital/benchmark_tx.py
index 55f309322e..27534a69ae 100755
--- a/gnuradio-examples/python/digital/benchmark_tx.py
+++ b/gnuradio-examples/python/digital/benchmark_tx.py
@@ -71,6 +71,8 @@ def main():
help="set megabytes to transmit [default=%default]")
parser.add_option("","--discontinuous", action="store_true", default=False,
help="enable discontinous transmission (bursts of 5 packets)")
+ parser.add_option("","--from-file", default=None,
+ help="use file for packet contents")
transmit_path.add_options(parser, expert_grp)
@@ -89,6 +91,9 @@ def main():
parser.print_help(sys.stderr)
sys.exit(1)
+ if options.from_file is not None:
+ source_file = open(options.from_file, 'r')
+
# build the graph
fg = my_graph(mods[options.modulation], options)
@@ -98,7 +103,6 @@ def main():
fg.start() # start flow graph
-
# generate and send packets
nbytes = int(1e6 * options.megabytes)
n = 0
@@ -106,8 +110,16 @@ def main():
pkt_size = int(options.size)
while n < nbytes:
- send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
- n += pkt_size
+ if options.from_file is None:
+ data = (pkt_size - 2) * chr(pktno & 0xff)
+ else:
+ data = source_file.read(pkt_size - 2)
+ if data == '':
+ break;
+
+ payload = struct.pack('!H', pktno) + data
+ send_pkt(payload)
+ n += len(payload)
sys.stderr.write('.')
if options.discontinuous and pktno % 5 == 4:
time.sleep(1)
diff --git a/gnuradio-examples/python/digital/run_length.py b/gnuradio-examples/python/digital/run_length.py
new file mode 100755
index 0000000000..dcf86e8c59
--- /dev/null
+++ b/gnuradio-examples/python/digital/run_length.py
@@ -0,0 +1,83 @@
+#!/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 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.
+#
+
+from optparse import OptionParser
+import sys
+
+def main():
+ parser = OptionParser()
+ parser.add_option("-f", "--file", default=None,
+ help="Choose file to read data from.")
+ (options, args) = parser.parse_args()
+
+ if options.file == None:
+ print "Must specify file to read from using '-f'."
+ sys.exit(1)
+ print "Using", options.file, "for data."
+
+ f = open(options.file, 'r')
+ runs = []
+ count = 0
+ current = 0
+ bytes = 0
+ bits = 0
+
+ for ch in f.read():
+ x = ord(ch)
+ bytes = bytes + 1
+ for i in range(7,-1,-1):
+ bits = bits + 1
+ t = (x >> i) & 0x1
+ if t == current:
+ count = count + 1
+ else:
+ if count > 0:
+ if len(runs) < count:
+ for j in range(count - len(runs)):
+ runs.append(0);
+ runs[count-1] = runs[count-1] + 1
+
+ current = 1-current;
+ count = 1
+
+ # Deal with last run at EOF
+ if len(runs) < count and count > 0:
+ for j in range(count - len(runs)):
+ runs.append(0);
+ runs[count-1] = runs[count-1] + 1
+
+ chk = 0
+ print "Bytes read: ", bytes
+ print "Bits read: ", bits
+ print
+ for i in range(len(runs)):
+ chk = chk + runs[i]*(i+1)
+ print "Runs of length", i+1, ":", runs[i]
+ print
+ print "Sum of runs:", chk, "bits"
+ print
+ print "Maximum run length is", len(runs), "bits"
+
+if __name__ == "__main__":
+ main()
+
+
diff --git a/gnuradio-examples/python/digital/transmit_path.py b/gnuradio-examples/python/digital/transmit_path.py
index 5c4017362b..753f59999a 100644
--- a/gnuradio-examples/python/digital/transmit_path.py
+++ b/gnuradio-examples/python/digital/transmit_path.py
@@ -50,7 +50,8 @@ class transmit_path(gr.hier_block):
self._samples_per_symbol = options.samples_per_symbol # desired samples/baud
self._fusb_block_size = options.fusb_block_size # usb info for USRP
self._fusb_nblocks = options.fusb_nblocks # usb info for USRP
-
+ self._use_whitener_offset = options.use_whitener_offset # increment start of whitener XOR data
+
self._modulator_class = modulator_class # the modulator_class we are using
if self._tx_freq is None:
@@ -80,7 +81,8 @@ class transmit_path(gr.hier_block):
self._modulator_class(fg, **mod_kwargs),
access_code=None,
msgq_limit=4,
- pad_for_usrp=True)
+ pad_for_usrp=True,
+ use_whitener_offset=options.use_whitener_offset)
# Set the USRP for maximum transmit gain
@@ -200,6 +202,8 @@ class transmit_path(gr.hier_block):
help="set fpga interpolation rate to INTERP [default=%default]")
expert.add_option("", "--log", action="store_true", default=False,
help="Log all parts of flow graph to file (CAUTION: lots of data)")
+ expert.add_option("","--use-whitener-offset", action="store_true", default=False,
+ help="make sequential packets use different whitening")
# Make a static method to call before instantiation
add_options = staticmethod(add_options)