summaryrefslogtreecommitdiff
path: root/gr-uhd/swig
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/swig')
-rw-r--r--gr-uhd/swig/__init__.py48
-rw-r--r--gr-uhd/swig/uhd_swig.i37
2 files changed, 70 insertions, 15 deletions
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py
index 0fdacb796..1a9f8358d 100644
--- a/gr-uhd/swig/__init__.py
+++ b/gr-uhd/swig/__init__.py
@@ -1,5 +1,5 @@
#
-# Copyright 2010 Free Software Foundation, Inc.
+# Copyright 2010-2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -22,6 +22,17 @@
# The presence of this file turns this directory into a Python package
########################################################################
+# Create aliases for uhd swig attributes to avoid the "_t"
+# Install the __str__ and __repr__ handlers if applicable
+########################################################################
+import uhd_swig
+for attr in dir(uhd_swig):
+ myobj = getattr(uhd_swig, attr)
+ if hasattr(myobj, 'to_string'): myobj.__repr__ = lambda s: s.to_string().strip()
+ if hasattr(myobj, 'to_pp_string'): myobj.__str__ = lambda s: s.to_pp_string().strip()
+ if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj)
+
+########################################################################
# Add SWIG generated code to this namespace
########################################################################
from uhd_swig import *
@@ -29,6 +40,8 @@ from uhd_swig import *
########################################################################
# 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
class tune_request_t(tune_request_t, float):
"""
@@ -38,3 +51,36 @@ 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)
+
+########################################################################
+# 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 76f44a491..3c317beb4 100644
--- a/gr-uhd/swig/uhd_swig.i
+++ b/gr-uhd/swig/uhd_swig.i
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2010 Free Software Foundation, Inc.
+ * Copyright 2010-2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -24,6 +24,8 @@
// header files if UHD was not installed.
#ifdef GR_HAVE_UHD
+#define GR_UHD_API
+
////////////////////////////////////////////////////////////////////////
// Language independent exception handler
////////////////////////////////////////////////////////////////////////
@@ -47,10 +49,6 @@
////////////////////////////////////////////////////////////////////////
%include "gnuradio.i"
-namespace std {
- %template(StringVector) vector<string>;
-}
-
////////////////////////////////////////////////////////////////////////
// block headers
////////////////////////////////////////////////////////////////////////
@@ -64,25 +62,36 @@ namespace std {
////////////////////////////////////////////////////////////////////////
// used types
////////////////////////////////////////////////////////////////////////
+%template(string_vector_t) std::vector<std::string>;
+
%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>
-//Re-create range typedefs here with %template as they are not imported.
-//Replicate all the levels of templated inheritance so swig understands.
+%include <uhd/types/clock_config.hpp>
-%template(float_range_t) uhd::range_t<float>;
-%template(_float_range_vector_t) std::vector<uhd::range_t<float> >;
-%template(gain_range_t) uhd::meta_range_t<float>;
+%include <uhd/types/metadata.hpp>
-%template(double_range_t) uhd::range_t<double>;
-%template(_double_range_vector_t) std::vector<uhd::range_t<double> >;
-%template(freq_range_t) uhd::meta_range_t<double>;
+%include <uhd/device.hpp>
+%template(device_addr_vector_t) std::vector<uhd::device_addr_t>;
////////////////////////////////////////////////////////////////////////
// block magic