aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mpm/python/usrp_mpm/periph_manager/sim.py11
-rw-r--r--mpm/python/usrp_mpm/simulator/CMakeLists.txt1
-rw-r--r--mpm/python/usrp_mpm/simulator/chdr_endpoint.py12
-rw-r--r--mpm/python/usrp_mpm/simulator/config.py52
-rw-r--r--mpm/python/usrp_mpm/simulator/sample_source.py1
5 files changed, 68 insertions, 9 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/sim.py b/mpm/python/usrp_mpm/periph_manager/sim.py
index b5cc45807..3e761c809 100644
--- a/mpm/python/usrp_mpm/periph_manager/sim.py
+++ b/mpm/python/usrp_mpm/periph_manager/sim.py
@@ -17,6 +17,7 @@ from usrp_mpm.rpc_server import no_claim
from usrp_mpm.periph_manager import PeriphManagerBase
from usrp_mpm.simulator.sim_dboard_catalina import SimulatedCatalinaDboard
from usrp_mpm.simulator.chdr_endpoint import ChdrEndpoint
+from usrp_mpm.simulator.config import Config
CLOCK_SOURCE_INTERNAL = "internal"
@@ -81,9 +82,17 @@ class sim(PeriphManagerBase):
###########################################################################
def __init__(self, args):
super().__init__()
+ if 'config' in args:
+ config_path = args['config']
+ self.log.info("Loading config from {}".format(config_path))
+ self.config = Config.from_path(config_path)
+ else:
+ self.log.warn("No config specified, using default")
+ self.config = Config.default()
+
self.device_id = 1
- self.chdr_endpoint = ChdrEndpoint(self.log, args)
+ self.chdr_endpoint = ChdrEndpoint(self.log, self.config)
# Unlike the real hardware drivers, if there is an exception here,
# we just crash. No use missing an error when testing.
diff --git a/mpm/python/usrp_mpm/simulator/CMakeLists.txt b/mpm/python/usrp_mpm/simulator/CMakeLists.txt
index e95709249..21f281e52 100644
--- a/mpm/python/usrp_mpm/simulator/CMakeLists.txt
+++ b/mpm/python/usrp_mpm/simulator/CMakeLists.txt
@@ -21,6 +21,7 @@ set(USRP_MPM_SIMULATOR_FILES
${CMAKE_CURRENT_SOURCE_DIR}/chdr_stream.py
${CMAKE_CURRENT_SOURCE_DIR}/rfnoc_common.py
${CMAKE_CURRENT_SOURCE_DIR}/stream_endpoint_node.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/config.py
)
list(APPEND USRP_MPM_FILES ${USRP_MPM_SIMULATOR_FILES})
set(USRP_MPM_FILES ${USRP_MPM_FILES} PARENT_SCOPE)
diff --git a/mpm/python/usrp_mpm/simulator/chdr_endpoint.py b/mpm/python/usrp_mpm/simulator/chdr_endpoint.py
index 303f3268d..17d707ae7 100644
--- a/mpm/python/usrp_mpm/simulator/chdr_endpoint.py
+++ b/mpm/python/usrp_mpm/simulator/chdr_endpoint.py
@@ -15,7 +15,6 @@ import select
from uhd.chdr import ChdrPacket, ChdrWidth
from .rfnoc_graph import XbarNode, XportNode, StreamEndpointNode, RFNoCGraph, NodeType
from .chdr_stream import SendWrapper, ChdrOutputStream, ChdrInputStream, SelectableQueue
-from .sample_source import NullSamples
CHDR_W = ChdrWidth.W64
@@ -25,14 +24,13 @@ class ChdrEndpoint:
traffic to the appropriate destination, and responding to said
traffic.
- The extra_args parameter is passed in from the periph_manager, and
- coresponds to the --default_args flag of usrp_hwd.py on the
- command line
+ The config parameter is a Config object (see simulator/config.py)
"""
- def __init__(self, log, extra_args):
+ def __init__(self, log, config):
self.log = log.getChild("ChdrEndpoint")
- self.source_gen = NullSamples
- self.sink_gen = NullSamples
+ self.config = config
+ self.source_gen = config.source_gen
+ self.sink_gen = config.sink_gen
self.xport_map = {}
self.send_queue = SelectableQueue()
diff --git a/mpm/python/usrp_mpm/simulator/config.py b/mpm/python/usrp_mpm/simulator/config.py
new file mode 100644
index 000000000..a5f07950d
--- /dev/null
+++ b/mpm/python/usrp_mpm/simulator/config.py
@@ -0,0 +1,52 @@
+#
+# Copyright 2020 Ettus Research, a National Instruments Brand
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+"""
+This module contains the logic to read configuration files from the
+filesystem and parse configuration data from them. This data includes
+anything from the serial number of the radio to the type of hardware
+it identifies itself as.
+"""
+
+import configparser
+from .sample_source import sinks, sources, NullSamples
+
+class Config:
+ """This class represents a configuration file for the usrp simulator.
+ This file should conform to the .ini format defined by the
+ configparser module
+
+ It should have a [sample.source] section and a [sample.sink] section.
+ Each section should have a 'class' key, which gives the name of the
+ Source/Sink class to instanitate (see the decorators in
+ sample_source.py). The other key value pairs in the section are
+ passed to the source/sink constructor as strings through **kwargs
+ """
+ def __init__(self, source_gen, sink_gen):
+ self.source_gen = source_gen
+ self.sink_gen = sink_gen
+
+ @classmethod
+ def from_path(cls, path):
+ """Parse a config .ini file from a path"""
+ parser = configparser.ConfigParser()
+ parser.read(path)
+ source_gen = Config._read_sample_section(parser['sample.source'], sources)
+ sink_gen = Config._read_sample_section(parser['sample.sink'], sinks)
+ return cls(source_gen, sink_gen)
+
+ @staticmethod
+ def _read_sample_section(section, lookup):
+ args = dict(section)
+ class_name = args.pop("class")
+ constructor = lookup[class_name]
+ def section_gen():
+ return constructor(**args)
+ return section_gen
+
+ @classmethod
+ def default(cls):
+ """Return a default config"""
+ return cls(NullSamples, NullSamples)
diff --git a/mpm/python/usrp_mpm/simulator/sample_source.py b/mpm/python/usrp_mpm/simulator/sample_source.py
index 184649994..36278efd8 100644
--- a/mpm/python/usrp_mpm/simulator/sample_source.py
+++ b/mpm/python/usrp_mpm/simulator/sample_source.py
@@ -8,7 +8,6 @@ This module contains the interface for providing data to a simulator
stream and receiving data from a simulator stream.
"""
-#TODO: This is currently unused, as the cli is largely incomplete
sources = {}
sinks = {}