From 0ace86e5209957bbd614d34ac4e48fc32614075f Mon Sep 17 00:00:00 2001 From: "Michal Krenek (Mikos)" Date: Mon, 20 Mar 2017 18:03:30 +0100 Subject: [PATCH] Add --info option (shows informations about selected SoapySDR device) --- README.rst | 5 +++-- soapypower/__main__.py | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 9ae1ea7..9d4ffdc 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ Usage :: usage: soapy_power [-h] [-f Hz|Hz:Hz] [-O FILE | --output-fd NUM] [-F {rtl_power,rtl_power_fftw,soapy_power_bin}] [-q] - [--debug] [--detect] [--version] [-b BINS | -B Hz] [-n REPEATS | -t SECONDS | -T SECONDS] + [--debug] [--detect] [--info] [--version] [-b BINS | -B Hz] [-n REPEATS | -t SECONDS | -T SECONDS] [-c | -u RUNS | -e SECONDS] [-d DEVICE] [-C CHANNEL] [-A ANTENNA] [-r Hz] [-w Hz] [-p PPM] [-g 1/10th of dB | -a] [--lnb-lo Hz] [--force-rate] [--force-bandwidth] [--tune-delay SECONDS] [--reset-stream] [-o PERCENT | -k PERCENT] [-s BUFFER_SIZE] [-S MAX_BUFFER_SIZE] [--even | --pow2] @@ -44,6 +44,7 @@ Usage -q, --quiet limit verbosity --debug detailed debugging messages --detect detect connected SoapySDR devices and exit + --info show info about selected SoapySDR device and exit --version show program's version number and exit FFT bins: @@ -112,7 +113,7 @@ Usage shape parameter of window function (required for kaiser and tukey windows) --fft-overlap PERCENT Welch's method overlap between segments (default: 50) - + Example ------- :: diff --git a/soapypower/__main__.py b/soapypower/__main__.py index 242721b..06830e1 100755 --- a/soapypower/__main__.py +++ b/soapypower/__main__.py @@ -33,18 +33,43 @@ def freq_or_freq_range(string): return [float_with_multiplier(f) for f in string.split(':')] -def detect_devices(): - devices = simplesoapy.detect_devices(as_string=True) +def detect_devices(soapy_args=''): + """Returns detected SoapySDR devices""" + devices = simplesoapy.detect_devices(soapy_args, as_string=True) text = [] text.append('Detected SoapySDR devices:') if devices: for i, d in enumerate(devices): text.append(' {}'.format(d)) else: - text.append(' No devices found') + text.append(' No devices found!') return (devices, '\n'.join(text)) +def device_info(soapy_args=''): + """Returns info about selected SoapySDR device""" + text = [] + try: + device = simplesoapy.SoapyDevice(soapy_args) + text.append('Selected device: {}'.format(device.hardware)) + text.append(' Available RX channels:') + text.append(' {}'.format(', '.join(str(x) for x in device.list_channels()))) + text.append(' Available antennas:') + text.append(' {}'.format(', '.join(device.list_antennas()))) + text.append(' Available tunable elements:') + text.append(' {}'.format(', '.join(device.list_frequencies()))) + text.append(' Available amplification elements:') + text.append(' {}'.format(', '.join(device.list_gains()))) + text.append(' Allowed sample rates:') + text.append(' [{}] MHz'.format(', '.join('{:.2f}'.format(x / 1e6) for x in device.list_sample_rates()))) + text.append(' Allowed bandwidths:') + text.append(' [{}] MHz'.format(', '.join('{:.2f}'.format(x / 1e6) for x in device.list_bandwidths()))) + except RuntimeError: + device = None + text.append('No devices found!') + return (device, '\n'.join(text)) + + def setup_argument_parser(): """Setup command line parser""" # Fix help formatter width @@ -83,6 +108,8 @@ def setup_argument_parser(): help='detailed debugging messages') main_title.add_argument('--detect', action='store_true', help='detect connected SoapySDR devices and exit') + main_title.add_argument('--info', action='store_true', + help='show info about selected SoapySDR device and exit') main_title.add_argument('--version', action='version', version='%(prog)s {}'.format(__version__)) @@ -209,10 +236,16 @@ def main(): # Detect SoapySDR devices if args.detect: - devices, devices_text = detect_devices() + devices, devices_text = detect_devices(args.device) print(devices_text) sys.exit(0 if devices else 1) + # Show info about selected SoapySDR device + if args.info: + device, device_text = device_info(args.device) + print(device_text) + sys.exit(0 if device else 1) + # Prepare arguments for SoapyPower if args.no_pyfftw: power.psd.simplespectral.use_pyfftw = False