uhd/host/tests/devtest/usrp_probe.py
Martin Braun 21ed72b5a2 devtese: Change default Python interpreter to 3
Usually, devtest is run via make (or ninja), and will use the correct
Python interpreter. When running directly on the command line, it is
important to pick the right Python interpreter so it will work with the
Python API.

Here, we change the default interpreter from Python 2 to 3, because
that's the more common version, and will be the only option for upcoming
UHD 4.0 anyway.
2019-11-08 08:56:20 -08:00

43 lines
1.4 KiB
Python

#!/usr/bin/env python3
#
# Copyright 2015-2016 Ettus Research LLC
# Copyright 2018 Ettus Research, a National Instruments Company
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
""" Run uhd_find_devices and parse the output. """
from __future__ import print_function
import re
import subprocess
def get_usrp_list(device_filter=None, env=None):
""" Returns a list of dicts that contain USRP info """
try:
cmd = ['uhd_find_devices']
if device_filter is not None:
cmd += ['--args', device_filter]
output = subprocess.check_output(cmd, env=env, universal_newlines=True)
except subprocess.CalledProcessError:
return []
split_re = "\n*-+\n-- .*\n-+\n"
uhd_strings = re.split(split_re, output)
result = []
for uhd_string in uhd_strings:
if not re.match("Device Address", uhd_string):
continue
this_result = {k: v for k, v in re.findall(" ([a-z]+): (.*)", uhd_string)}
if this_result.get('reachable') == "No":
continue
args_string = ""
try:
args_string = "type={},serial={}".format(this_result['type'], this_result['serial'])
except KeyError:
continue
this_result['args'] = args_string
result.append(this_result)
return result
if __name__ == "__main__":
print(get_usrp_list())
print(get_usrp_list('type=x300'))