Skip to content

Commit

Permalink
Add --info option (shows informations about selected SoapySDR device)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmikos committed Mar 20, 2017
1 parent 9c9301a commit 0ace86e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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
-------
::
Expand Down
41 changes: 37 additions & 4 deletions soapypower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__))

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ace86e

Please sign in to comment.