Commit a2f7b03c authored by Brent Stapleton's avatar Brent Stapleton Committed by michael-west

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
parent 8ff198d6
......@@ -7,12 +7,30 @@
#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>;
.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 */
// 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);
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment