aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/simulator
diff options
context:
space:
mode:
authorSamuel O'Brien <sam.obrien@ni.com>2020-08-06 14:05:36 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-10-28 15:25:48 -0500
commita5091cd52614e01e1a8acf0e77cf4185baa5dd3d (patch)
tree438027eedd6123950dc2ec43123807eef85a0165 /mpm/python/usrp_mpm/simulator
parenta56f4f63e235c7511cccfc291d395481828703f5 (diff)
downloaduhd-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')
-rw-r--r--mpm/python/usrp_mpm/simulator/config.py9
-rw-r--r--mpm/python/usrp_mpm/simulator/sample_source.py17
2 files changed, 24 insertions, 2 deletions
diff --git a/mpm/python/usrp_mpm/simulator/config.py b/mpm/python/usrp_mpm/simulator/config.py
index 6698f9fd0..d97a30266 100644
--- a/mpm/python/usrp_mpm/simulator/config.py
+++ b/mpm/python/usrp_mpm/simulator/config.py
@@ -11,7 +11,7 @@ it identifies itself as.
"""
import configparser
-from .sample_source import sinks, sources, NullSamples
+from .sample_source import sinks, sources, NullSamples, from_import_path
from .hardware_presets import presets
import numbers
@@ -105,7 +105,12 @@ class Config:
def _read_sample_section(section, lookup):
args = dict(section)
class_name = args.pop("class")
- constructor = lookup[class_name]
+ constructor = None
+ if "import_path" in args:
+ import_path = args.pop("import_path")
+ constructor = from_import_path(class_name, import_path)
+ else:
+ constructor = lookup[class_name]
def section_gen():
return constructor(**args)
return section_gen
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