diff options
author | Martin Braun <martin.braun@ettus.com> | 2020-12-15 14:08:04 +0100 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-05-20 14:56:23 -0500 |
commit | 7a0b87a43e2009e6a96ba4b19a935ce3bc4a6292 (patch) | |
tree | c12ff9cac873268a987e81abd1c519ebb2bef6a3 | |
parent | e1515c755c551fac1d218be112df745b4a15db16 (diff) | |
download | uhd-7a0b87a43e2009e6a96ba4b19a935ce3bc4a6292.tar.gz uhd-7a0b87a43e2009e6a96ba4b19a935ce3bc4a6292.tar.bz2 uhd-7a0b87a43e2009e6a96ba4b19a935ce3bc4a6292.zip |
tools: Add bool-property-set ability to rx_settling_time.py
Adds a new command line argument:
rx_settling_time.py --property-bool /path/to/prop=True [...]
will set a Boolean property to true at the given time.
-rwxr-xr-x | tools/gr-usrptest/apps/rx_settling_time.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/tools/gr-usrptest/apps/rx_settling_time.py b/tools/gr-usrptest/apps/rx_settling_time.py index d58eeb9dc..04927e4b6 100755 --- a/tools/gr-usrptest/apps/rx_settling_time.py +++ b/tools/gr-usrptest/apps/rx_settling_time.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -# Copyright 2018 Ettus Research, a National Instruments Company +# Copyright 2018-2020 Ettus Research, a National Instruments Company # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -17,13 +17,11 @@ time: $ rx_settling_time.py -a type=x300 -f 1e9 -g 0 --new-gain 30 --plot """ -from __future__ import print_function +import sys import argparse import numpy as np -from six import iteritems import uhd - def parse_args(): """Parse the command line arguments""" parser = argparse.ArgumentParser( @@ -63,6 +61,9 @@ def parse_args(): "--new-gain", help="Gain after set time") parser.add_argument( + "--property-bool", + help="Set a Boolean property tree node. Use the format path=True or path=False.") + parser.add_argument( "-r", "--rate", default=1e6, type=float, help="Sampling rate (Hz)") parser.add_argument( @@ -76,7 +77,6 @@ def parse_args(): return parser.parse_args() - def get_rx_streamer(usrp, chan): """ Return a streamer @@ -109,6 +109,18 @@ def start_rx_stream(streamer, start_time): streamer.issue_stream_cmd(stream_cmd) +def _cmd_set_property_bool(usrp, key_value): + """ + Execute setting a Boolean property tree node. key_value is a string of the + form "/path/to/node=True" (or "False"). + """ + path, value = key_value.split("=") + value = value.lower() + # Convert to bool from string, allowing all sorts of "true" values: + value = value in ("1", "yes", "y", "true") + usrp.get_tree().access_bool(path).set(value) + + def load_commands(usrp, chan, cmd_time, **kwargs): """ Load the switching commands. @@ -117,8 +129,9 @@ def load_commands(usrp, chan, cmd_time, **kwargs): kw_cb_map = { 'freq': lambda freq: usrp.set_rx_freq(uhd.types.TuneRequest(float(freq)), chan), 'gain': lambda gain: usrp.set_rx_gain(float(gain), chan), + 'prop_tree_bool': lambda key_value: _cmd_set_property_bool(usrp, key_value), } - for key, callback in iteritems(kw_cb_map): + for key, callback in kw_cb_map.items(): if kwargs.get(key) is not None: callback(kwargs[key]) usrp.clear_command_time() @@ -222,6 +235,7 @@ def main(): cmd_time=time_zero+args.setup_delay+args.set_delay, freq=args.new_freq, gain=args.new_gain, + prop_tree_bool=args.property_bool, ) print("Starting receive...") samps = recv_samples(rx_streamer, total_num_samps, skip_samps) @@ -245,5 +259,4 @@ def main(): return True if __name__ == "__main__": - exit(not main()) - + sys.exit(not main()) |