aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples/python/rx_to_file.py
diff options
context:
space:
mode:
authorPaul David <paul.david@ettus.com>2017-05-02 14:10:05 -0400
committerMartin Braun <martin.braun@ettus.com>2018-06-20 19:02:32 -0500
commite74cf7635ba3360b5b7002a2f7317941f65ffa16 (patch)
tree46b63039f31c5aedf26773b4b626b2a7932999db /host/examples/python/rx_to_file.py
parent22e24497a510c174e6de7718ad918a423d1973dd (diff)
downloaduhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.tar.gz
uhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.tar.bz2
uhd-e74cf7635ba3360b5b7002a2f7317941f65ffa16.zip
python: Separating exposed Python data structures
- Separating exposed Python data structures into logical sections - Exposes all of the multi_usrp API - Adds a layer of Python for documentation and adding helper methods - Adds improvements and fixes to the MultiUSRP object - Includes additional exposed data structures (like time_spec_t, etc.) - Add code to release the Python GIL during long C++ calls
Diffstat (limited to 'host/examples/python/rx_to_file.py')
-rwxr-xr-xhost/examples/python/rx_to_file.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/host/examples/python/rx_to_file.py b/host/examples/python/rx_to_file.py
new file mode 100755
index 000000000..7017a08c2
--- /dev/null
+++ b/host/examples/python/rx_to_file.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+#
+# Copyright 2017-2018 Ettus Research, a National Instruments Company
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+RX samples to file using Python API
+"""
+
+import argparse
+import numpy as np
+import uhd
+
+
+def parse_args():
+ """Parse the command line arguments"""
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-a", "--args", default="", type=str)
+ parser.add_argument("-o", "--output-file", type=str, required=True)
+ parser.add_argument("-f", "--freq", type=float, required=True)
+ parser.add_argument("-r", "--rate", default=1e6, type=float)
+ parser.add_argument("-d", "--duration", default=5.0, type=float)
+ parser.add_argument("-c", "--channels", default=0, nargs="+", type=int)
+ parser.add_argument("-g", "--gain", type=int, default=10)
+ parser.add_argument("-n", "--numpy", default=False, action="store_true",
+ help="Save output file in NumPy format (default: No)")
+ return parser.parse_args()
+
+
+def main():
+ """RX samples and write to file"""
+ args = parse_args()
+ usrp = uhd.usrp.MultiUSRP(args.args)
+ num_samps = int(np.ceil(args.duration*args.rate))
+ if not isinstance(args.channels, list):
+ args.channels = [args.channels]
+ samps = usrp.recv_num_samps(num_samps, args.freq, args.rate, args.channels, args.gain)
+ with open(args.output_file, 'wb') as out_file:
+ if args.numpy:
+ np.save(out_file, samps, allow_pickle=False, fix_imports=False)
+ else:
+ samps.tofile(out_file)
+
+if __name__ == "__main__":
+ main()