diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-01-15 15:42:15 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-02-08 22:18:14 +0100 |
commit | 832cbe095ae5e851aadddce66e1510d33a4430f3 (patch) | |
tree | 72ce19679463547f074dea956249ad8d78cdc650 /mpm/python/usrp_mpm | |
parent | 44533fb035d4e9629d62f79a95ea9eb0487dcfef (diff) | |
download | uhd-832cbe095ae5e851aadddce66e1510d33a4430f3.tar.gz uhd-832cbe095ae5e851aadddce66e1510d33a4430f3.tar.bz2 uhd-832cbe095ae5e851aadddce66e1510d33a4430f3.zip |
mpm: Use prefs API for periph manager
- Allow to set default args via config file
- Read them from prefs API
- override-db-pids uses the same APIs now ([overrides] section in
config file, prefs API, and same dictionary as --default-args when
used on the command line
Diffstat (limited to 'mpm/python/usrp_mpm')
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 39 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n310.py | 6 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/prefs.py | 3 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/rpc_server.py | 2 |
4 files changed, 43 insertions, 7 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index 69a20c369..384be99f3 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -22,6 +22,7 @@ from usrp_mpm.sys_utils.udev import get_spidev_nodes from usrp_mpm.sys_utils import dtoverlay from usrp_mpm import eeprom from usrp_mpm.rpc_server import no_claim, no_rpc +from usrp_mpm import prefs def get_dboard_class_from_pid(pid): """ @@ -132,17 +133,28 @@ class PeriphManagerBase(object): # Device initialization (at MPM startup) ########################################################################### def __init__(self, args): - # First, make some checks to see if the child class is correctly set up: + # Note: args is a dictionary. assert len(self.pids) > 0 assert self.mboard_eeprom_magic is not None # Set up logging self.log = get_logger('PeriphManager') self.claimed = False + # The _init_args are a check for the args that passed into init(). This + # should always be a dictionary (or dictionary-like object). self._init_args = {} try: self._init_mboard_with_eeprom() - self._init_mboard_overlays(self._eeprom_head, args) - self._init_dboards(args.override_db_pids, args) + self._default_args = self._update_default_args(args) + self.log.debug("Using default args: {}".format(self._default_args)) + self._init_mboard_overlays(self._eeprom_head, self._default_args) + override_db_pids_str = self._default_args.get('override_db_pids') + if override_db_pids_str: + override_db_pids = [ + int(x, 0) for x in override_db_pids_str.split(",") + ] + else: + override_db_pids = [] + self._init_dboards(override_db_pids, self._default_args) self._device_initialized = True self._initialization_status = "No errors." except Exception as ex: @@ -212,6 +224,24 @@ class PeriphManagerBase(object): self.log.info("Device serial number: {}" .format(self.mboard_info.get('serial', 'n/a'))) + def _update_default_args(self, default_args): + """ + Pipe the default_args (that get passed into us from the RPC server) + through the prefs API. This way, we respect both the config file and + command line arguments. + """ + prefs_cache = prefs.get_prefs() + periph_section_name = None + if prefs_cache.has_section(self.mboard_info.get('product')): + periph_section_name = self.mboard_info.get('product') + elif prefs_cache.has_section(self.mboard_info.get('type')): + periph_section_name = self.mboard_info.get('type') + if periph_section_name is not None: + prefs_cache.read_dict({periph_section_name: default_args}) + return dict(prefs_cache[periph_section_name]) + else: + return default_args + def _init_mboard_overlays(self, eeprom_md, device_args): """ Load all required overlays for this motherboard @@ -235,6 +265,9 @@ class PeriphManagerBase(object): """ # Go, go, go! override_dboard_pids = override_dboard_pids or [] + if override_dboard_pids: + self.log.warning("Overriding daughterboard PIDs! {}" + .format(override_dboard_pids)) dboard_eeprom_addrs = self.dboard_eeprom_addr \ if isinstance(self.dboard_eeprom_addr, list) \ else [self.dboard_eeprom_addr] diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index be18228a1..0e4f8e0ce 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -537,12 +537,12 @@ class n310(PeriphManagerBase): self.enable_1g_ref_clock() self.enable_gps( enable=str2bool( - args.default_args.get('enable_gps', N3XX_DEFAULT_ENABLE_GPS) + args.get('enable_gps', N3XX_DEFAULT_ENABLE_GPS) ) ) self.enable_fp_gpio( enable=str2bool( - args.default_args.get( + args.get( 'enable_fp_gpio', N3XX_DEFAULT_ENABLE_FPGPIO ) @@ -557,7 +557,7 @@ class n310(PeriphManagerBase): # Init clocking self.enable_ref_clock(enable=True) self._ext_clock_freq = None - self._init_ref_clock_and_time(args.default_args) + self._init_ref_clock_and_time(args) self._init_meas_clock() # Init CHDR transports self._xport_mgrs = { diff --git a/mpm/python/usrp_mpm/prefs.py b/mpm/python/usrp_mpm/prefs.py index d244a0b42..8ed6f13ff 100644 --- a/mpm/python/usrp_mpm/prefs.py +++ b/mpm/python/usrp_mpm/prefs.py @@ -37,6 +37,9 @@ class _MPMPrefs(configparser.ConfigParser): 'log_level': MPM_DEFAULT_LOG_LEVEL, 'log_buf_size': MPM_DEFAULT_LOG_BUF_SIZE, }, + 'overrides': { + 'override_db_pids': '', + }, } def __init__(self): diff --git a/mpm/python/usrp_mpm/rpc_server.py b/mpm/python/usrp_mpm/rpc_server.py index 062396082..abb3b4327 100644 --- a/mpm/python/usrp_mpm/rpc_server.py +++ b/mpm/python/usrp_mpm/rpc_server.py @@ -63,7 +63,7 @@ class MPMServer(RPCServer): # Setting this to True will disable an unclaim on timeout. Use with # care, and make sure to set it to False again when finished. self._disable_timeouts = False - self._timeout_interval = float(default_args.default_args.get( + self._timeout_interval = float(default_args.get( "rpc_timeout_interval", TIMEOUT_INTERVAL )) |