From 5e00de56713729b7c366884d3a1e31ffa3423b13 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 12:46:39 -0800 Subject: uhd: removed ranges template stuff, added some python polish in __init__.py --- gr-uhd/swig/__init__.py | 6 ++++++ gr-uhd/swig/uhd_swig.i | 11 ----------- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 0fdacb796..6d09f19f0 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -30,6 +30,12 @@ from uhd_swig import * # Add other content from pure-Python modules here ######################################################################## +#make the meta-range printable in python +meta_range_t.__str__ = lambda s: s.to_pp_string().strip() + +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): """ Make the python tune request object inherit from float diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 76f44a491..cf4ecf920 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -73,17 +73,6 @@ namespace std { %include %include -//Re-create range typedefs here with %template as they are not imported. -//Replicate all the levels of templated inheritance so swig understands. - -%template(float_range_t) uhd::range_t; -%template(_float_range_vector_t) std::vector >; -%template(gain_range_t) uhd::meta_range_t; - -%template(double_range_t) uhd::range_t; -%template(_double_range_vector_t) std::vector >; -%template(freq_range_t) uhd::meta_range_t; - //////////////////////////////////////////////////////////////////////// // block magic //////////////////////////////////////////////////////////////////////// -- cgit From c63edcbe834c0929a7e0c7907f7c79ffc3fc5667 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 16:19:19 -0800 Subject: uhd: swig + python tweaks to uhd types --- gr-uhd/swig/__init__.py | 9 ++++++++- gr-uhd/swig/uhd_swig.i | 12 ++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 6d09f19f0..a8082bc34 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -30,7 +30,8 @@ from uhd_swig import * # Add other content from pure-Python modules here ######################################################################## -#make the meta-range printable in python +#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() class freq_range_t(meta_range_t): pass #a typedef for the user @@ -44,3 +45,9 @@ class tune_request_t(tune_request_t, float): """ def __new__(self, *args): return float.__new__(self) def __float__(self): return self.target_freq + +######################################################################## +# Create aliases for global attributes to avoid the "_t" +######################################################################## +for attr in globals().keys(): + if attr.endswith('_t'): globals()[attr[:-2]] = globals()[attr] diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index cf4ecf920..5628a1203 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -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; -} - //////////////////////////////////////////////////////////////////////// // block headers //////////////////////////////////////////////////////////////////////// @@ -61,6 +59,12 @@ namespace std { #include %} +//////////////////////////////////////////////////////////////////////// +// templated types +//////////////////////////////////////////////////////////////////////// +%template(string_vector_t) std::vector; +%template(range_vector_t) std::vector; + //////////////////////////////////////////////////////////////////////// // used types //////////////////////////////////////////////////////////////////////// -- cgit From cf33e1e5f75c627907811e07e4c3c7a6b6175e8a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 16:22:47 -0800 Subject: uhd: added export macros (not used now) and updated copyright dates --- gr-uhd/swig/__init__.py | 2 +- gr-uhd/swig/uhd_swig.i | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index a8082bc34..157733880 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 # diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index 5628a1203..89f82e9f4 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 * -- cgit From dfcc8cc28d8e5d0ca1de62b1622438be2439ebd1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 19:08:26 -0800 Subject: uhd: use the actual device and io types, do hacks in the init.py, also use clock config convenience --- gr-uhd/swig/__init__.py | 41 ++++++++++++++++++++++++++++++++++++++--- gr-uhd/swig/uhd_swig.i | 21 ++++++++++++++++----- 2 files changed, 54 insertions(+), 8 deletions(-) (limited to 'gr-uhd/swig') 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; -%template(range_vector_t) std::vector; -//////////////////////////////////////////////////////////////////////// -// used types -//////////////////////////////////////////////////////////////////////// %include + %include + +%include +%template(string_string_dict_t) uhd::dict; //define after dict + +%include + +%include + +%template(range_vector_t) std::vector; //define before range %include + %include + %include + %include + %include + %include //////////////////////////////////////////////////////////////////////// -- cgit From 69ae2c9b1eca4c69d9007b146aa54fd1b75fcd28 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 20:15:10 -0800 Subject: uhd: make the repr and str installation more generic --- gr-uhd/swig/__init__.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 0991f5b6b..18b5dfefc 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -26,13 +26,6 @@ ######################################################################## from uhd_swig import * -######################################################################## -# Make types with to_string functions printable -######################################################################## -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 ######################################################################## @@ -61,9 +54,13 @@ class device_addr_t(device_addr_t, str): ######################################################################## # Create aliases for global attributes to avoid the "_t" +# Install the __str__ and __repr__ handlers if applicable ######################################################################## for attr in globals().keys(): - if attr.endswith('_t'): globals()[attr[:-2]] = globals()[attr] + myobj = globals()[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'): globals()[attr[:-2]] = myobj ######################################################################## # Cast constructor args (FIXME swig handle overloads?) -- cgit From 81d3460c5c6a950c8b734f192aa62cd1f8718d7c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 12 Jan 2011 15:20:13 -0800 Subject: uhd: swig up the device discovery --- gr-uhd/swig/__init__.py | 21 +++++++++++---------- gr-uhd/swig/uhd_swig.i | 5 +++++ 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'gr-uhd/swig') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 18b5dfefc..1a9f8358d 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -21,6 +21,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 ######################################################################## @@ -52,16 +63,6 @@ class device_addr_t(device_addr_t, str): 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" -# Install the __str__ and __repr__ handlers if applicable -######################################################################## -for attr in globals().keys(): - myobj = globals()[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'): globals()[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 e25dbce90..3c317beb4 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -88,6 +88,11 @@ %include +%include + +%include +%template(device_addr_vector_t) std::vector; + //////////////////////////////////////////////////////////////////////// // block magic //////////////////////////////////////////////////////////////////////// -- cgit