diff options
author | Samuel O'Brien <sam.obrien@ni.com> | 2020-07-21 13:59:39 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-10-07 15:29:19 -0500 |
commit | bfff8b79b950f2f1cebfd2db662a4205df5da65a (patch) | |
tree | 58ebe4d31a9d0c459f03454ebded8bb695a6651d /mpm/python/usrp_mpm/simulator/sim_dboard.py | |
parent | 6394a7c6ea395e2d21c3e2b9e43e1b2dc84666b5 (diff) | |
download | uhd-bfff8b79b950f2f1cebfd2db662a4205df5da65a.tar.gz uhd-bfff8b79b950f2f1cebfd2db662a4205df5da65a.tar.bz2 uhd-bfff8b79b950f2f1cebfd2db662a4205df5da65a.zip |
sim: Add Daughterboard Methods
This commit adds daughterboard simulation to the simulator. There is a
sim_dboard class which registers it's methods with the rpc server. These
methods are visible over mpm as well as the mpm_shell.
Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
Diffstat (limited to 'mpm/python/usrp_mpm/simulator/sim_dboard.py')
-rw-r--r-- | mpm/python/usrp_mpm/simulator/sim_dboard.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/simulator/sim_dboard.py b/mpm/python/usrp_mpm/simulator/sim_dboard.py new file mode 100644 index 000000000..a264eae9c --- /dev/null +++ b/mpm/python/usrp_mpm/simulator/sim_dboard.py @@ -0,0 +1,59 @@ +# +# Copyright 2020 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +from usrp_mpm.dboard_manager import DboardManagerBase +from usrp_mpm.mpmlog import get_logger +from usrp_mpm.mpmutils import to_native_str + +class SimulatedDboardBase(DboardManagerBase): + """ + A class to simulate daughterboards in a simulated device. + """ + + # Extra Overridables: + # This is a list of extra methods to add to the class + # Each element should be either a string or a tuple of + # (string, function). Each element is added to the class + # with the name being the string and the function being + # the function, or the default of taking any amount of + # arguments and returning None + extra_methods = [] + + def __init__(self, slot_idx, **kwargs): + super().__init__(slot_idx, **kwargs) + self.log = get_logger("sim_db-{}".format(slot_idx)) + self.device_info = { + 'pid': to_native_str(self.__class__.pids[0]), + 'serial': to_native_str("todo:serial-here"), + 'rev': to_native_str("1"), + 'eeprom_version': to_native_str('0') + } + self.rev = int(self.device_info['rev']) + + self.log.trace("This is a rev: {}".format(chr(65 + self.rev))) + self._make_extra_methods() + + def init(self, args): + self.log.trace("sim_db#init called") + return True + + def tear_down(self): + self.log.trace("sim_db#tear_down called") + + def _make_extra_methods(self): + for entry in self.__class__.extra_methods: + func = None + prop_name = None + if type(entry) is tuple: + func = entry[1] + prop_name = entry[0] + else: + func = lambda *args: None + prop_name = entry + # default values are needed because loop iterations don't create a new scope in python + def wrapped_func(*args, prop_name=prop_name, func=func): + self.log.debug("Called {} with args: {}".format(prop_name, args)) + return func(*args) + setattr(self, prop_name, wrapped_func) |