From d601fd03d5655f9e744a7b5454aac40492d7ad09 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 12 Oct 2017 10:47:07 -0700 Subject: mpm: Properly populate device_info dict for dboard classes Prior to this commit, device_info was always an empty dictionary on all dboard classes. The device_info dict is now auto-populated from the EEPROM contents, if any were provided. Dboard classes can still opt to amend that dictionary in specific class implementations. Signed-off-by: Martin Braun --- mpm/python/usrp_mpm/dboard_manager/base.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'mpm/python/usrp_mpm/dboard_manager/base.py') diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py index cf3510abf..2b42e47c5 100644 --- a/mpm/python/usrp_mpm/dboard_manager/base.py +++ b/mpm/python/usrp_mpm/dboard_manager/base.py @@ -61,7 +61,24 @@ class DboardManagerBase(object): def __init__(self, slot_idx, **kwargs): self.log = get_logger('dboardManager') self.slot_idx = slot_idx - self.device_info = {} + if 'eeprom_md' not in kwargs: + self.log.warn("No EEPROM metadata given!") + def anystr_to_str(any_str): + """ + Convert byte-string or regular string to regular string, regardless + of Python version (2 or 3). + """ + try: + return str(any_str, 'ascii') + except TypeError: + return str(any_str) + # In C++, we can only handle dicts if all the values are of the + # same type. So we must convert them all to strings here: + self.device_info = { + key: anystr_to_str(kwargs.get('eeprom_md', {}).get(key, 'n/a')) + for key in ('pid', 'serial', 'rev', 'eeprom_version') + } + self.log.trace("Dboard device info: `{}'".format(self.device_info)) self._init_spi_nodes(kwargs.get('spi_nodes', [])) -- cgit v1.2.3