summaryrefslogtreecommitdiff
path: root/gr-uhd/swig
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/swig')
-rw-r--r--gr-uhd/swig/__init__.py41
-rw-r--r--gr-uhd/swig/uhd_swig.i21
2 files changed, 54 insertions, 8 deletions
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py
index 157733880..0991f5b6b 100644
--- a/gr-uhd/swig/__init__.py
+++ b/gr-uhd/swig/__init__.py
@@ -27,13 +27,15 @@
from uhd_swig import *
########################################################################
-# Add other content from pure-Python modules here
+# Make types with to_string functions printable
########################################################################
-
-#make the ranges printable in python
range_t.__str__ = lambda s: s.to_pp_string().strip()
meta_range_t.__str__ = lambda s: s.to_pp_string().strip()
+device_addr_t.__str__ = lambda s: s.to_pp_string().strip()
+########################################################################
+# Add other content from pure-Python modules here
+########################################################################
class freq_range_t(meta_range_t): pass #a typedef for the user
class gain_range_t(meta_range_t): pass #a typedef for the user
@@ -46,8 +48,41 @@ class tune_request_t(tune_request_t, float):
def __new__(self, *args): return float.__new__(self)
def __float__(self): return self.target_freq
+class device_addr_t(device_addr_t, str):
+ """
+ Make the python tune request object inherit from string
+ so that it can be passed in GRC as a string parameter.
+ The type checking in GRC will accept the device address.
+ Define the set/get item special methods for dict access.
+ """
+ def __new__(self, *args): return str.__new__(self)
+ def __getitem__(self, key): return self.get(key)
+ def __setitem__(self, key, val): self.set(key, val)
+
########################################################################
# Create aliases for global attributes to avoid the "_t"
########################################################################
for attr in globals().keys():
if attr.endswith('_t'): globals()[attr[:-2]] = globals()[attr]
+
+########################################################################
+# Cast constructor args (FIXME swig handle overloads?)
+########################################################################
+for attr in (
+ 'single_usrp_source', 'single_usrp_sink',
+ 'multi_usrp_source', 'multi_usrp_sink'
+):
+ def constructor_factory(old_constructor):
+ def constructor_interceptor(*args, **kwargs):
+ args = list(args)
+ kwargs = dict(kwargs)
+ for index, key, cast in (
+ (0, 'device_addr', device_addr),
+ (1, 'io_type', io_type),
+ ):
+ if len(args) > index: args[index] = cast(args[index])
+ if kwargs.has_key(key): kwargs[key] = cast(kwargs[key])
+ return old_constructor(*args, **kwargs)
+ return constructor_interceptor
+ import uhd_swig
+ globals()[attr] = constructor_factory(getattr(uhd_swig, attr))
diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i
index 89f82e9f4..e25dbce90 100644
--- a/gr-uhd/swig/uhd_swig.i
+++ b/gr-uhd/swig/uhd_swig.i
@@ -60,21 +60,32 @@
%}
////////////////////////////////////////////////////////////////////////
-// templated types
+// used types
////////////////////////////////////////////////////////////////////////
%template(string_vector_t) std::vector<std::string>;
-%template(range_vector_t) std::vector<uhd::range_t>;
-////////////////////////////////////////////////////////////////////////
-// used types
-////////////////////////////////////////////////////////////////////////
%include <uhd/config.hpp>
+
%include <uhd/utils/pimpl.hpp>
+
+%include <uhd/types/dict.hpp>
+%template(string_string_dict_t) uhd::dict<std::string, std::string>; //define after dict
+
+%include <uhd/types/device_addr.hpp>
+
+%include <uhd/types/io_type.hpp>
+
+%template(range_vector_t) std::vector<uhd::range_t>; //define before range
%include <uhd/types/ranges.hpp>
+
%include <uhd/types/tune_request.hpp>
+
%include <uhd/types/tune_result.hpp>
+
%include <uhd/types/io_type.hpp>
+
%include <uhd/types/time_spec.hpp>
+
%include <uhd/types/clock_config.hpp>
////////////////////////////////////////////////////////////////////////