diff options
author | Samuel O'Brien <sam.obrien@ni.com> | 2020-08-06 14:05:36 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-10-28 15:25:48 -0500 |
commit | a5091cd52614e01e1a8acf0e77cf4185baa5dd3d (patch) | |
tree | 438027eedd6123950dc2ec43123807eef85a0165 /mpm/python/usrp_mpm/simulator/sample_source.py | |
parent | a56f4f63e235c7511cccfc291d395481828703f5 (diff) | |
download | uhd-a5091cd52614e01e1a8acf0e77cf4185baa5dd3d.tar.gz uhd-a5091cd52614e01e1a8acf0e77cf4185baa5dd3d.tar.bz2 uhd-a5091cd52614e01e1a8acf0e77cf4185baa5dd3d.zip |
sim: Support Out of Tree Sources and Sinks
This commit adds the ability to specify a path to an arbitrary python
file in a simulator config file, which will be imported and used to
construct a SampleSink or SampleSource for use with data streaming.
Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
Diffstat (limited to 'mpm/python/usrp_mpm/simulator/sample_source.py')
-rw-r--r-- | mpm/python/usrp_mpm/simulator/sample_source.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/simulator/sample_source.py b/mpm/python/usrp_mpm/simulator/sample_source.py index 36278efd8..98fc6ff0b 100644 --- a/mpm/python/usrp_mpm/simulator/sample_source.py +++ b/mpm/python/usrp_mpm/simulator/sample_source.py @@ -7,6 +7,7 @@ This module contains the interface for providing data to a simulator stream and receiving data from a simulator stream. """ +import importlib.util sources = {} sinks = {} @@ -21,6 +22,22 @@ def cli_sink(cls): sinks[cls.__name__] = cls return cls +name_index = 0 +module_lookup = {} +def from_import_path(class_name, import_path): + global name_index + global module_lookup + module = None + if import_path in module_lookup: + module = module_lookup[import_path] + else: + spec = importlib.util.spec_from_file_location("simsample." + str(name_index), import_path) + name_index =+ 1 + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + module_lookup[import_path] = module + return getattr(module, class_name) + class SampleSource: """This class defines the interface of a SampleSource. It provides samples to the simulator which are then sent over the |