summaryrefslogtreecommitdiff
path: root/gr-uhd/python/uhd/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/python/uhd/__init__.py')
-rw-r--r--gr-uhd/python/uhd/__init__.py63
1 files changed, 7 insertions, 56 deletions
diff --git a/gr-uhd/python/uhd/__init__.py b/gr-uhd/python/uhd/__init__.py
index 3f24d98826..85a8f2c142 100644
--- a/gr-uhd/python/uhd/__init__.py
+++ b/gr-uhd/python/uhd/__init__.py
@@ -31,39 +31,23 @@ def _prepare_uhd_python():
from . import uhd_python
#some useful typedefs for the user
- # setattr(uhd_python, 'freq_range_t', uhd_python.meta_range_t)
- # setattr(uhd_python, 'gain_range_t', uhd_python.meta_range_t)
- setattr(uhd_python, 'freq_range_t', uhd.types.MetaRange)
- setattr(uhd_python, 'gain_range_t', uhd.types.MetaRange)
+ setattr(uhd_python, 'freq_range_t', uhd_python.meta_range_t)
+ setattr(uhd_python, 'gain_range_t', uhd_python.meta_range_t)
#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.
#Also use kwargs to construct individual struct elements.
- class tune_request_t(uhd.types.TuneRequest): #, float):
- def __new__(self, *args, **kwargs): return float.__new__(self)
+ class tune_request_t(uhd_python.tune_request_t):
+ # def __new__(self, *args, **kwargs): return float.__new__(self)
def __float__(self): return self.target_freq
def __init__(self, *args, **kwargs):
- super(tune_request_t, self).__init__(*args)
+ super().__init__(*args)
for key, val in list(kwargs.items()): setattr(self, key, val)
setattr(uhd_python, 'tune_request_t', tune_request_t)
- #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.types.DeviceAddr): #, 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)
- def __init__(self, *args, **kwargs):
- super(device_addr_t, self).__init__(*args)
- if args and isinstance(args[0], device_addr_t):
- for key in list(args[0].keys()): self[key] = args[0][key]
- setattr(uhd_python, 'device_addr_t', device_addr_t)
-
#make the streamer args take **kwargs on init
- class stream_args_t(uhd.usrp.StreamArgs):
+ class stream_args_t(uhd_python.stream_args_t):
def __init__(self, *args, **kwargs):
# UHD Python API doesn't have default args for stream_args_t
# If empty args, then append empty str's
@@ -76,12 +60,11 @@ def _prepare_uhd_python():
if key == 'channels':
for v in val: self.channels.append(v)
elif key == 'args':
- self.args = device_addr_t(val)
+ self.args = uhd_python.device_addr_t(val)
else: setattr(self, key, val)
# FIXME: stream_args_t.channels.append does not work due to copy operation of STL vectors
setattr(uhd_python, 'stream_args_t', stream_args_t)
- # setattr(uhd_python, 'stream_args_t', uhd.usrp.StreamArgs)
#handle general things on all uhd_python attributes
#Install the __str__ and __repr__ handlers if applicable
@@ -104,38 +87,6 @@ def _prepare_uhd_python():
return __builtins__['map'](to_pythonized_dev_addr, uhd_python.find_devices_raw(*args, **kwargs))
setattr(uhd_python, 'find_devices', find_devices)
- #Cast constructor args (FIXME swig handle overloads?)
- for attr in ('usrp_source', 'usrp_sink', 'amsg_source'):
- 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),
- ):
- if len(args) > index:
- args[index] = cast(args[index])
- if key in kwargs:
- kwargs[key] = cast(kwargs[key])
- #don't pass kwargs, it confuses swig, map into args list:
- for key in ('device_addr', 'stream_args',
- 'issue_stream_cmd_on_start', 'tsb_tag_name', 'msgq'):
- if key in kwargs: args.append(kwargs[key])
- return old_constructor(*args)
- return constructor_interceptor
- setattr(uhd_python, attr, constructor_factory(getattr(uhd_python, attr)))
-
- #FIXME: Aliases for UHD Python API - can this go away?? Do we need more??
- setattr(uhd_python, 'time_spec_t', uhd.types.TimeSpec)
-
-
- #Aliases for deprecated constructors
- #FIXME: Remove for 3.9??
- setattr(uhd_python, 'single_usrp_source', uhd_python.usrp_source)
- setattr(uhd_python, 'single_usrp_sink', uhd_python.usrp_sink)
- setattr(uhd_python, 'multi_usrp_source', uhd_python.usrp_source)
- setattr(uhd_python, 'multi_usrp_sink', uhd_python.usrp_sink)
-
########################################################################
# Initialize this module with the contents of uhd pybind
########################################################################