aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2018-10-11 16:37:44 -0700
committerBrent Stapleton <bstapleton@g.hmc.edu>2018-11-14 18:01:51 -0800
commit388bc5229f01a042505dc30aacece88739fdeffc (patch)
treef16448a4ea8051c00e024a3713b0ef228e2cdbf1 /host
parentd901b1e70801bae4974b2403b9762be368774e9b (diff)
downloaduhd-388bc5229f01a042505dc30aacece88739fdeffc.tar.gz
uhd-388bc5229f01a042505dc30aacece88739fdeffc.tar.bz2
uhd-388bc5229f01a042505dc30aacece88739fdeffc.zip
python: adding device_addr_t to Python API
Add support for device_addr_t to the Python API. Most functions are exposed normally. The main exception is the constructor from a map of strings, which is replaced by a factory function called `make_device_addr`.
Diffstat (limited to 'host')
-rw-r--r--host/lib/types/types_python.hpp32
-rw-r--r--host/python/types.py1
2 files changed, 33 insertions, 0 deletions
diff --git a/host/lib/types/types_python.hpp b/host/lib/types/types_python.hpp
index 4cda00d0d..434ae9171 100644
--- a/host/lib/types/types_python.hpp
+++ b/host/lib/types/types_python.hpp
@@ -7,12 +7,30 @@
#ifndef INCLUDED_UHD_TYPES_PYTHON_HPP
#define INCLUDED_UHD_TYPES_PYTHON_HPP
+#include <uhd/types/device_addr.hpp>
#include <uhd/types/stream_cmd.hpp>
+#include <boost/python.hpp>
+#include <string>
+#include <map>
+
+
+//! Make a device_addr_t from a Python dict of strings
+static uhd::device_addr_t make_device_addr(bp::dict& info) {
+ // Manually extract each key and each value, copy them to a map of strings, and return that.
+ std::map<std::string,std::string> info_map;
+ auto keys = info.keys();
+ for (int ii = 0; ii < bp::len(keys); ++ii) {
+ std::string key = bp::extract<std::string>(keys[ii]);
+ info_map[key] = bp::extract<std::string>(info[key]);
+ }
+ return uhd::device_addr_t(info_map);
+}
void export_types()
{
using stream_cmd_t = uhd::stream_cmd_t;
using stream_mode_t = stream_cmd_t::stream_mode_t;
+ using str_map = std::map<std::string, std::string>;
bp::enum_<stream_mode_t>("stream_mode")
.value("start_cont", stream_cmd_t::STREAM_MODE_START_CONTINUOUS )
@@ -28,6 +46,20 @@ void export_types()
.def_readwrite("time_spec" , &stream_cmd_t::time_spec )
.def_readwrite("stream_now", &stream_cmd_t::stream_now)
;
+
+ bp::class_<uhd::device_addr_t>("device_addr", bp::init<bp::optional<std::string> >())
+ // Constructors
+ /* TODO: This calls the correct C++ constructor, but Python
+ dictionaries != str_maps, so we get a signature error */
+ .def(bp::init<str_map>())
+
+ // Methods
+ .def("__str__", &uhd::device_addr_t::to_pp_string)
+ .def("to_string", &uhd::device_addr_t::to_string)
+ .def("to_pp_string", &uhd::device_addr_t::to_pp_string)
+ ;
+
+ bp::def("make_device_addr", make_device_addr);
}
#endif /* INCLUDED_UHD_TYPES_PYTHON_HPP */
diff --git a/host/python/types.py b/host/python/types.py
index bcf6e1df2..6b4ceefce 100644
--- a/host/python/types.py
+++ b/host/python/types.py
@@ -12,6 +12,7 @@ from . import libpyuhd as lib
StreamMode = lib.types.stream_mode
StreamCMD = lib.types.stream_cmd
+DeviceAddr = lib.types.device_addr
TimeSpec = lib.types.time_spec
SPIEdge = lib.types.spi_edge
SPIConfig = lib.types.spi_config