From 7c23fd43214e8a729b3022db281dc85040f0e749 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 26 Feb 2010 15:17:38 -0800 Subject: Created simple source (with nothing in it) and some swig build stuff. Seems to work and compile --- gr-uhd/swig/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 gr-uhd/swig/__init__.py (limited to 'gr-uhd/swig/__init__.py') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py new file mode 100644 index 000000000..2fed17e57 --- /dev/null +++ b/gr-uhd/swig/__init__.py @@ -0,0 +1,28 @@ +# +# Copyright 2010 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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 + +# Add SWIG generated code to this namespace +from uhd_swig import * + +# Add other content from pure-Python modules here + -- cgit From 3dab5d93a45928baa4fb23878d644751e06943a0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 28 Oct 2010 13:24:23 -0700 Subject: uhd: make a tune_request_t that inherits from float for GRC, added docs --- gr-uhd/swig/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gr-uhd/swig/__init__.py') diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py index 2fed17e57..0fdacb796 100644 --- a/gr-uhd/swig/__init__.py +++ b/gr-uhd/swig/__init__.py @@ -21,8 +21,20 @@ # The presence of this file turns this directory into a Python package +######################################################################## # Add SWIG generated code to this namespace +######################################################################## from uhd_swig import * +######################################################################## # Add other content from pure-Python modules here +######################################################################## +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 -- cgit 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 ++++++ 1 file changed, 6 insertions(+) (limited to 'gr-uhd/swig/__init__.py') 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 -- 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 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gr-uhd/swig/__init__.py') 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] -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-uhd/swig/__init__.py') 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 # -- 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 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'gr-uhd/swig/__init__.py') 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)) -- 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/__init__.py') 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 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'gr-uhd/swig/__init__.py') 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?) ######################################################################## -- 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/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'gr-uhd/swig/__init__.py') 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 -- 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/__init__.py') 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 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'gr-uhd/swig/__init__.py') 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?) -- cgit