From 8afa393725c2bfda7c341b7202acfa40cc3245d2 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Fri, 21 Jan 2011 19:24:33 -0800 Subject: Added first pass at swigging dboard iface --- gr-uhd/swig/uhd_swig.i | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 3c317beb4..e90f850bd 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -93,6 +93,15 @@ %include %template(device_addr_vector_t) std::vector; +//////////////////////////////////////////////////////////////////////// +// swig dboard_iface for python access +//////////////////////////////////////////////////////////////////////// +%include stdint.i +%include +%include + +%template(dboard_iface_sptr) boost::shared_ptr; + //////////////////////////////////////////////////////////////////////// // block magic //////////////////////////////////////////////////////////////////////// -- cgit From 7787d1fc1aecc7b59e476c31865b4f32348cb729 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 00:56:55 -0800 Subject: uhd: replaced multi/single usrp stuff with just one usrp wrapper --- gr-uhd/swig/Makefile.am | 6 ++---- gr-uhd/swig/__init__.py | 13 +++++++++---- gr-uhd/swig/uhd_swig.i | 20 ++++++-------------- 3 files changed, 17 insertions(+), 22 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/Makefile.am b/gr-uhd/swig/Makefile.am index e93571a66..035fb2112 100644 --- a/gr-uhd/swig/Makefile.am +++ b/gr-uhd/swig/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2010 Free Software Foundation, Inc. +# Copyright 2010-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -66,9 +66,7 @@ uhd_swig_python = \ # additional SWIG files to be installed uhd_swig_swiginclude_headers = -uhd_swig_swig_args = \ - $(UHD_CFLAGS) \ - -I$(top_srcdir)/gr-uhd/lib +uhd_swig_swig_args = $(UHD_CPPFLAGS) ## If UHD was installed, defined GR_HAVE_UHD for swigging headers if GR_DEFINE_HAVE_UHD diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 1a9f8358d..b464f903d 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -66,10 +66,7 @@ class device_addr_t(device_addr_t, str): ######################################################################## # Cast constructor args (FIXME swig handle overloads?) ######################################################################## -for attr in ( - 'single_usrp_source', 'single_usrp_sink', - 'multi_usrp_source', 'multi_usrp_sink' -): +for attr in ('usrp_source', 'usrp_sink'): def constructor_factory(old_constructor): def constructor_interceptor(*args, **kwargs): args = list(args) @@ -84,3 +81,11 @@ for attr in ( return constructor_interceptor import uhd_swig globals()[attr] = constructor_factory(getattr(uhd_swig, attr)) + +######################################################################## +# Aliases for deprecated constructors +######################################################################## +single_usrp_source = usrp_source +single_usrp_sink = usrp_sink +multi_usrp_source = usrp_source +multi_usrp_sink = usrp_sink diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index e90f850bd..a42344fab 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -53,10 +53,8 @@ // block headers //////////////////////////////////////////////////////////////////////// %{ -#include -#include -#include -#include +#include +#include %} //////////////////////////////////////////////////////////////////////// @@ -105,17 +103,11 @@ //////////////////////////////////////////////////////////////////////// // block magic //////////////////////////////////////////////////////////////////////// -GR_SWIG_BLOCK_MAGIC(uhd,multi_usrp_source) -%include +GR_SWIG_BLOCK_MAGIC(uhd,usrp_source) +%include -GR_SWIG_BLOCK_MAGIC(uhd,multi_usrp_sink) -%include - -GR_SWIG_BLOCK_MAGIC(uhd,single_usrp_source) -%include - -GR_SWIG_BLOCK_MAGIC(uhd,single_usrp_sink) -%include +GR_SWIG_BLOCK_MAGIC(uhd,usrp_sink) +%include //////////////////////////////////////////////////////////////////////// // helpful constants -- cgit From cf4c96c754fee998b14df771d78f086b08ecbd80 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 15 Feb 2011 14:42:35 -0800 Subject: uhd: tweaks for swig/python init file --- gr-uhd/swig/__init__.py | 116 +++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 61 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index b464f903d..276f381d0 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -17,75 +17,69 @@ # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -# - -# 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 +# Prepare uhd swig module to make it more pythonic ######################################################################## -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) +def _prepare_uhd_swig(): + import uhd_swig -######################################################################## -# Add SWIG generated code to this namespace -######################################################################## -from uhd_swig import * + #some useful typedefs for the user + setattr(uhd_swig, 'freq_range_t', uhd_swig.meta_range_t) + setattr(uhd_swig, 'gain_range_t', uhd_swig.meta_range_t) -######################################################################## -# 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 + #Make the python tune request object inherit from float + #so that it can be passed in GRC as a frequency parameter. + #The type checking in GRC will accept the tune request. + class tune_request_t(uhd_swig.tune_request_t, float): + def __new__(self, *args): return float.__new__(self) + def __float__(self): return self.target_freq + setattr(uhd_swig, 'tune_request_t', tune_request_t) -class tune_request_t(tune_request_t, float): - """ - Make the python tune request object inherit from float - so that it can be passed in GRC as a frequency parameter. - The type checking in GRC will accept the tune request. - """ - def __new__(self, *args): return float.__new__(self) - def __float__(self): return self.target_freq + #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. + class device_addr_t(uhd_swig.device_addr_t, str): + 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) + setattr(uhd_swig, 'device_addr_t', device_addr_t) -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) + #handle general things on all uhd_swig attributes + #Install the __str__ and __repr__ handlers if applicable + #Create aliases for uhd swig attributes to avoid the "_t" + 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) -######################################################################## -# Cast constructor args (FIXME swig handle overloads?) -######################################################################## -for attr in ('usrp_source', '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)) + #Cast constructor args (FIXME swig handle overloads?) + for attr in ('usrp_source', '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 + setattr(uhd_swig, attr, constructor_factory(getattr(uhd_swig, attr))) + + #Aliases for deprecated constructors + setattr(uhd_swig, 'single_usrp_source', uhd_swig.usrp_source) + setattr(uhd_swig, 'single_usrp_sink', uhd_swig.usrp_sink) + setattr(uhd_swig, 'multi_usrp_source', uhd_swig.usrp_source) + setattr(uhd_swig, 'multi_usrp_sink', uhd_swig.usrp_sink) ######################################################################## -# Aliases for deprecated constructors +# Initialize this module with the contents of uhd swig ######################################################################## -single_usrp_source = usrp_source -single_usrp_sink = usrp_sink -multi_usrp_source = usrp_source -multi_usrp_sink = usrp_sink +_prepare_uhd_swig() +from uhd_swig import * -- cgit From 5bb8acf24e4913d2a969db70476af65c498b032f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 25 Feb 2011 15:34:04 -0800 Subject: uhd: added sensors api to gr-uhd blocks and swig support --- gr-uhd/swig/__init__.py | 7 +++++-- gr-uhd/swig/uhd_swig.i | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 276f381d0..7ed689ec0 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -52,8 +52,11 @@ def _prepare_uhd_swig(): #Create aliases for uhd swig attributes to avoid the "_t" 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 hasattr(myobj, 'to_string'): myobj.__repr__ = lambda o: o.to_string().strip() + if hasattr(myobj, 'to_pp_string'): myobj.__str__ = lambda o: o.to_pp_string().strip() + if hasattr(myobj, 'to_bool'): myobj.__nonzero__ = lambda o: o.to_bool() + if hasattr(myobj, 'to_int'): myobj.__int__ = lambda o: o.to_int() + if hasattr(myobj, 'to_real'): myobj.__float__ = lambda o: o.to_real() if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj) #Cast constructor args (FIXME swig handle overloads?) diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index a42344fab..b814471b2 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -91,6 +91,8 @@ %include %template(device_addr_vector_t) std::vector; +%include + //////////////////////////////////////////////////////////////////////// // swig dboard_iface for python access //////////////////////////////////////////////////////////////////////// -- cgit