diff options
Diffstat (limited to 'mpm')
-rwxr-xr-x | mpm/python/usrp_hwd.py | 18 | ||||
-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 |
5 files changed, 52 insertions, 16 deletions
diff --git a/mpm/python/usrp_hwd.py b/mpm/python/usrp_hwd.py index b4d556cfd..2a597c789 100755 --- a/mpm/python/usrp_hwd.py +++ b/mpm/python/usrp_hwd.py @@ -73,10 +73,6 @@ def parse_args(): Return a fully parse args object """ args = setup_arg_parser().parse_args() - if args.override_db_pids is not None: - args.override_db_pids = [ - int(x, 0) for x in args.override_db_pids.split(",") - ] args.default_args = args.default_args or '' try: args.default_args = { @@ -110,7 +106,7 @@ def kill_time(sig, frame): log.info("System exiting") sys.exit(0) -def init_only(log, args): +def init_only(log, default_args): """ Run the full initialization immediately and return """ @@ -124,11 +120,11 @@ def init_only(log, args): from usrp_mpm.periph_manager import periph_manager log.info("Spawning periph manager...") ctor_time_start = time.time() - mgr = periph_manager(args) + mgr = periph_manager(default_args) ctor_duration = time.time() - ctor_time_start log.info("Ctor Duration: {:.02f} s".format(ctor_duration)) init_time_start = time.time() - init_result = mgr.init(args.default_args) + init_result = mgr.init(default_args) init_duration = time.time() - init_time_start if init_result: log.info("Initialization successful! Duration: {:.02f} s" @@ -147,7 +143,8 @@ def spawn_processes(log, args): shared = SharedState() log.info("Spawning RPC process...") _PROCESSES.append( - mpm.spawn_rpc_process(mpm.mpmtypes.MPM_RPC_PORT, shared, args)) + mpm.spawn_rpc_process( + mpm.mpmtypes.MPM_RPC_PORT, shared, args.default_args)) log.debug("RPC process has PID: %d", _PROCESSES[-1].pid) if watchdog.has_watchdog(): watchdog.transfer_control(_PROCESSES[-1].pid) @@ -173,8 +170,11 @@ def main(): log = mpm.get_main_logger( log_default_delta=args.verbose-args.quiet ).getChild('main') + if args.override_db_pids is not None: + log.warning('Overriding daughterboard PIDs!') + args.default_args['override_db_pids'] = args.override_db_pids if args.init_only: - return init_only(log, args) + return init_only(log, args.default_args) return spawn_processes(log, args) if __name__ == '__main__': 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 )) |