diff options
author | Josh Blum <josh@joshknows.com> | 2011-10-19 10:10:34 -0700 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2011-10-19 10:25:24 -0700 |
commit | cfba63c8dbe0d0b998f58f49d14fc43c290e7cfb (patch) | |
tree | 4a8eec0ca2384c1625b408ea3c8d253358961ef7 /gr-uhd/swig | |
parent | b35d84eb447f44b547d928e5741feab7660c39e6 (diff) |
uhd: added uhd.find_devices to python
Diffstat (limited to 'gr-uhd/swig')
-rw-r--r-- | gr-uhd/swig/__init__.py | 9 | ||||
-rw-r--r-- | gr-uhd/swig/uhd_swig.i | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index c63d3cc571..7745b4b797 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -69,6 +69,15 @@ def _prepare_uhd_swig(): if hasattr(myobj, 'to_real'): myobj.__float__ = lambda o: o.to_real() if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj) + #make a new find devices that casts everything with the pythonized device_addr_t which has __str__ + def find_devices(*args, **kwargs): + def to_pythonized_dev_addr(dev_addr): + new_dev_addr = uhd_swig.device_addr_t() + for key in dev_addr.keys(): new_dev_addr[key] = dev_addr.get(key) + return new_dev_addr + return map(to_pythonized_dev_addr, uhd_swig.find_devices_raw(*args, **kwargs)) + setattr(uhd_swig, 'find_devices', find_devices) + #Cast constructor args (FIXME swig handle overloads?) for attr in ('usrp_source', 'usrp_sink', 'amsg_source'): def constructor_factory(old_constructor): diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index f8381ae64b..37ff831bd6 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -102,6 +102,17 @@ GR_SWIG_BLOCK_MAGIC(uhd,amsg_source) %include <gr_uhd_amsg_source.h> //////////////////////////////////////////////////////////////////////// +// device discovery (no need to %include device.hpp) +//////////////////////////////////////////////////////////////////////// +%{ +static uhd::device_addrs_t find_devices_raw(const uhd::device_addr_t &dev_addr){ + return uhd::device::find(dev_addr); +} +%} + +static uhd::device_addrs_t find_devices_raw(const uhd::device_addr_t &dev_addr = uhd::device_addr_t()); + +//////////////////////////////////////////////////////////////////////// // helpful constants //////////////////////////////////////////////////////////////////////// %{ |