diff options
| author | Martin Braun <martin.braun@ettus.com> | 2017-04-19 18:45:29 -0700 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:45 -0800 | 
| commit | 285f14392b4494501b462796743e67cc54c4cca8 (patch) | |
| tree | e680bf89d33f73b58f515bb9558a4c3db6ec07f5 /mpm/python/usrp_mpm | |
| parent | b05f72f339dcb02cc6efc6f2bc7d92c4476b5cc9 (diff) | |
| download | uhd-285f14392b4494501b462796743e67cc54c4cca8.tar.gz uhd-285f14392b4494501b462796743e67cc54c4cca8.tar.bz2 uhd-285f14392b4494501b462796743e67cc54c4cca8.zip  | |
mpm: Moved over to new logging infrastructure
Also currently hardcodes some settings.
Diffstat (limited to 'mpm/python/usrp_mpm')
| -rw-r--r-- | mpm/python/usrp_mpm/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/__init__.py | 1 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/base.py | 6 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/eiscat.py | 2 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/magnesium.py | 101 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/test.py | 7 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/unknown.py | 3 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/discovery.py | 18 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/mpmlog.py | 126 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 47 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n310.py | 22 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/net.py | 7 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/udev.py | 19 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/rpc_server.py | 29 | 
14 files changed, 293 insertions, 99 deletions
diff --git a/mpm/python/usrp_mpm/CMakeLists.txt b/mpm/python/usrp_mpm/CMakeLists.txt index b401ac6c4..4ce21ce11 100644 --- a/mpm/python/usrp_mpm/CMakeLists.txt +++ b/mpm/python/usrp_mpm/CMakeLists.txt @@ -25,7 +25,9 @@ SET(USRP_MPM_TOP_FILES      ${CMAKE_CURRENT_SOURCE_DIR}/discovery.py      ${CMAKE_CURRENT_SOURCE_DIR}/rpc_server.py      ${CMAKE_CURRENT_SOURCE_DIR}/uio.py -    ) +    ${CMAKE_CURRENT_SOURCE_DIR}/nijesdcore.py +    ${CMAKE_CURRENT_SOURCE_DIR}/mpmlog.py +)  LIST(APPEND USRP_MPM_FILES ${USRP_MPM_TOP_FILES})  ADD_SUBDIRECTORY(periph_manager)  ADD_SUBDIRECTORY(dboard_manager) diff --git a/mpm/python/usrp_mpm/__init__.py b/mpm/python/usrp_mpm/__init__.py index 7606f33ce..b91896542 100644 --- a/mpm/python/usrp_mpm/__init__.py +++ b/mpm/python/usrp_mpm/__init__.py @@ -23,3 +23,4 @@ from .rpc_server import spawn_rpc_process  from . import types  from . import periph_manager  from . import dboard_manager +from .mpmlog import get_main_logger diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py index 37e7dd2b8..0e8d1b7e4 100644 --- a/mpm/python/usrp_mpm/dboard_manager/base.py +++ b/mpm/python/usrp_mpm/dboard_manager/base.py @@ -17,11 +17,8 @@  """  dboard base implementation module  """ -import logging  import struct - -LOG = logging.Logger(__name__) - +from ..mpmlog import get_logger  class DboardManagerBase(object):      """ @@ -33,6 +30,7 @@ class DboardManagerBase(object):      def __init__(self, eeprom=None):          self._eeprom = eeprom or {} +        self.log = get_logger('dboardManager')      def get_serial(self):          return self._eeprom.get("serial", "") diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 101290574..436307c1e 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -19,8 +19,6 @@ EISCAT rx board implementation module  """  from . import lib  from .base import DboardManagerBase -from .base import LOG -  class eiscat(DboardManagerBase):      hw_pid = 3 diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index f13f1de77..45a19ded6 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -17,13 +17,13 @@  """  magnesium dboard implementation module  """ -from . import lib -from .base import DboardManagerBase -import struct -from logging import getLogger - -LOG = getLogger(__name__) +import struct +import time +from . import lib # Pulls in everything from C++-land +from .base import DboardManagerBase +from .. import nijesdcore +from ..uio import uio  class magnesium(DboardManagerBase):      """ @@ -31,33 +31,104 @@ class magnesium(DboardManagerBase):      """      hw_pid = 2      special_eeprom_addrs = {"special0": "something"} -    spi_chipselect = {"0": "lmk", "1": "mykonos", "2": "random"} +    spi_chipselect = {"0": "lmk", "1": "mykonos",}      spidevs = {}      lmk = ""      mykonos = ""      random = ""      def __init__(self, spi_devices, eeprom_data, *args, **kwargs): +        super(magnesium, self).__init__(*args, **kwargs)          # eeprom_data is a tuple (head_dict, raw_data)          if len(spi_devices) != len(self.spi_chipselect): -            LOG.error("Expected {0} spi devices, found {1} spi devices".format(len(spi_devices), len(self.spi_chipselect))) +            self.log.error("Expected {0} spi devices, found {1} spi devices".format( +                len(self.spi_chipselect), len(spi_devices), +            ))              exit(1)          for spi in spi_devices:              device = self.spi_chipselect.get(spi[-1], None) -            if self.chipselect is None: -                LOG.error("Unexpected chipselect {0}".format(spi[-1])) -                exit(1) +            # if self.chipselect is None: +                # self.log.error("Unexpected chipselect {0}".format(spi[-1])) +                # exit(1)              setattr(self, device, spi) -        super(magnesium, self).__init__(*args, **kwargs) +            self.log.debug("Setting spi device for {device}: {spidev}".format( +                device=device, spidev=spi +            ))      def init_device(self):          """          Execute necessary init dance to bring up dboard          """ -        LOG.debug("initialize hardware") +        self.log.debug("initialize hardware") +        self._device = lib.dboards.magnesium_periph_manager( +            # self.lmk.encode('ascii'), self.mykonos.encode('ascii') +            '/dev/spidev0.0', +            '/dev/spidev0.1', +        ) +        self.lmk = self._device.get_clock_ctrl() +        self.mykonos = self._device.get_radio_ctrl() + +        # uio_path, uio_size = get_uio_node("misc-enet-regs0") +        self.log.debug("getting Mg A uio") +        uio_path = "/dev/uio2" # TODO use labels +        uio_size = 0x4000 +        self.log.debug("got uio_path and size") +        self.uio = uio(uio_path, uio_size, read_only=False) +        self.log.info("got my uio") +        self.init_jesd(self.uio) + +    def init_jesd(self, uio): +        """ +        Bring up the JESD link between Mykonos and the N310 +        """ +        self.log.trace("Creating jesdcore object") +        self.jesdcore = nijesdcore.NIMgJESDCore(uio) + +        self.log.trace("Checking JESD core...") +        self.jesdcore.check_core() +        self.log.trace("Initializing LMK...") +        self.lmk.init() +        self.lmk.verify_chip_id() +        self.log.trace("Enabling SYSREF pulses...") +        self.lmk.enable_sysref_pulse() + +        self.jesdcore.unreset_mmcm() + +        self.jesdcore.init() +        self.log.trace("Resetting Mykonos...") +        self.reset_mykonos() #not sure who owns the reset + +        self.log.trace("Initializing Mykonos...") +        self.mykonos.begin_initialization() +        self.jesdcore.send_sysref_pulse() +        self.jesdcore.send_sysref_pulse() +        self.mykonos.finish_initialization() + +        self.log.trace("Stargin Mykonos JESD framing...") +        self.mykonos.start_jesd_rx() +        self.jesdcore.init_deframer() +        self.jesdcore.init_framer() +        self.mykonos.start_jesd_tx() + +        #TODO add function for Enable FPGA LMFC Generator +        self.jesdcore.send_sysref_pulse() +        time.sleep(0.2) +        if not self.jesdcore.get_framer_status(): +            raise Exception('JESD Core Framer is not synced!') +        if not self.jesdcore.get_deframer_status(): +            raise Exception('JESD Core Deframer is not synced!') +        #if (!self.mykonos.get_framer_status()) +        #    raise Exception('Mykonos Framer is not synced!') +        #if (!self.mykonos.get_deframer_status()) +        #    raise Exception('Mykonos Deframer is not synced!') -        self._device = lib.dboards.magnesium( -            self.lmk, self.mykonos, self.random) +    def reset_mykonos(self): +        " Toggle reset line on Mykonos " +        # SUPER GHETTO FIXME +        import os +        os.system('devmem2 0x4001000C w 2') # Active low reset +        time.sleep(0.001) +        os.system('devmem2 0x4001000C w 10')      def read_eeprom_v1(self, data):          """ diff --git a/mpm/python/usrp_mpm/dboard_manager/test.py b/mpm/python/usrp_mpm/dboard_manager/test.py index 80299ee41..da7b34c7a 100644 --- a/mpm/python/usrp_mpm/dboard_manager/test.py +++ b/mpm/python/usrp_mpm/dboard_manager/test.py @@ -21,9 +21,6 @@ from . import lib  from .base import DboardManagerBase  from logging import getLogger -LOG = getLogger(__name__) - -  class fake_spi(object):      def __init__(self, addr):          self.addr = addr @@ -54,8 +51,6 @@ class test(DboardManagerBase):          self.dev3 = "2"      def init_device(self): -        LOG.debug("initialize hardware") +        self.log.debug("initialize hardware")          self._device = test_device(self.dev1, self.dev2, self.dev3) - - diff --git a/mpm/python/usrp_mpm/dboard_manager/unknown.py b/mpm/python/usrp_mpm/dboard_manager/unknown.py index de2354f3d..d954154f9 100644 --- a/mpm/python/usrp_mpm/dboard_manager/unknown.py +++ b/mpm/python/usrp_mpm/dboard_manager/unknown.py @@ -20,9 +20,6 @@ EISCAT rx board implementation module  from .base import DboardManagerBase  from logging import getLogger -LOG = getLogger(__name__) - -  class unknown(DboardManagerBase):      hw_pid = 0      special_eeprom_addrs = {} diff --git a/mpm/python/usrp_mpm/discovery.py b/mpm/python/usrp_mpm/discovery.py index 595368c76..a8044d49e 100644 --- a/mpm/python/usrp_mpm/discovery.py +++ b/mpm/python/usrp_mpm/discovery.py @@ -19,19 +19,16 @@ Code to run the discovery port  """  from __future__ import print_function -from logging import getLogger  from multiprocessing import Process -from six import iteritems  import socket +from six import iteritems  from usrp_mpm.types import MPM_DISCOVERY_PORT - -LOG = getLogger(__name__) +from .mpmlog import get_main_logger  RESPONSE_PREAMBLE = "USRP-MPM"  RESPONSE_SEP = ";"  RESPONSE_CLAIMED_KEY = "claimed" -  def spawn_discovery_process(device_info, shared_state):      """      Returns a process that contains the device discovery. @@ -59,6 +56,7 @@ def _discovery_process(device_info, state):              ["{k}={v}".format(k=RESPONSE_CLAIMED_KEY, v=state.claim_status.value)] + \              ["{k}={v}".format(k="token", v=state.claim_token.value)]          ) +    log = get_main_logger().getChild('discovery')      sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)      sock.bind((("0.0.0.0", MPM_DISCOVERY_PORT))) @@ -68,19 +66,19 @@ def _discovery_process(device_info, state):      # try:      while True:          data, sender = sock.recvfrom(8000) -        LOG.info("Got poked by: %s", sender[0]) +        log.info("Got poked by: %s", sender[0])          if data.strip("\0") == "MPM-DISC": -            LOG.info("Sending discovery response to %s port: %d", +            log.info("Sending discovery response to %s port: %d",                       sender[0], sender[1])              send_data = create_response_string()              send_sock.sendto(send_data, sender)          elif data.strip("\0").startswith("MPM-ECHO"): -            LOG.info("Received echo request") +            log.info("Received echo request from {sender}".format(sender=sender[0]))              send_data = data              send_sock.sendto(send_data, sender)      # except Exception as err: -    #     LOG.info("Error: %s", err) -    #     LOG.info("Error type: %s", type(err)) +    #     log.info("Error: %s", err) +    #     log.info("Error type: %s", type(err))      #     sock.close()      #     send_sock.close() diff --git a/mpm/python/usrp_mpm/mpmlog.py b/mpm/python/usrp_mpm/mpmlog.py new file mode 100644 index 000000000..3df505f1a --- /dev/null +++ b/mpm/python/usrp_mpm/mpmlog.py @@ -0,0 +1,126 @@ +# +# Copyright 2017 Ettus Research (National Instruments) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. +# +""" +MPM Logging +""" + +from __future__ import print_function +import copy +import logging +from logging import CRITICAL, ERROR, WARNING, INFO, DEBUG + +# Colors +BOLD = str('\033[1m') +RED = str('\x1b[31m') +YELLOW = str('\x1b[33m') +GREEN = str('\x1b[32m') +PINK = str('\x1b[35m') +GREY = str('\x1b[90m') +RESET = str('\x1b[0m') + +# Additional log level +TRACE = 1 + +class ColorStreamHandler(logging.StreamHandler): +    """ +    StreamHandler that prints colored output +    """ +    def emit(self, record): +        """ +        Prints record with colors. +        record is not modified. +        """ +        record_ = copy.copy(record) +        levelno = record_.levelno +        if levelno >= CRITICAL: +            color = RED +        elif levelno >= ERROR: +            color = RED +        elif levelno >= WARNING: +            color = YELLOW +        elif levelno >= INFO: +            color = GREEN +        elif levelno >= DEBUG: +            color = PINK +        elif levelno >= TRACE: +            color = '' +        else: # NOTSET and anything else +            color = RESET +        record_.msg = BOLD + color + str(record_.msg) + RESET +        logging.StreamHandler.emit(self, record_) + +class MPMLogger(logging.getLoggerClass()): +    """ +    Extends the regular Python logging with level 'trace' (like UHD) +    """ +    def __init__(self, *args, **kwargs): +        logging.Logger.__init__(self, *args, **kwargs) + +    def trace(self, *args, **kwargs): +        """ Extends logging for super-high verbosity """ +        self.log(TRACE, *args, **kwargs) + + +LOGGER = None # Logger singleton +def get_main_logger(use_console=True, use_journal=False, console_color=True): +    """ +    Returns the top-level logger object. This is the only API call from this +    file that should be used outside. +    """ +    global LOGGER +    if LOGGER is not None: +        return LOGGER +    logging.addLevelName(TRACE, 'TRACE') +    logging.setLoggerClass(MPMLogger) +    LOGGER = logging.getLogger('MPM') +    if use_console: +        console_handler = ColorStreamHandler() if console_color else logging.StreamHandler() +        console_formatter = logging.Formatter("[%(name)s] [%(levelname)s] %(message)s") +        console_handler.setFormatter(console_formatter) +        LOGGER.addHandler(console_handler) +    if use_journal: +        from systemd.journal import JournalHandler +        journal_handler = JournalHandler(SYSLOG_IDENTIFIER='usrp_hwd') +        journal_formatter = logging.Formatter('[%(levelname)s] [%(module)s] %(message)s') +        journal_handler.setFormatter(journal_formatter) +        LOGGER.addHandler(journal_handler) +    # Set default level: +    default_log_level = TRACE +    LOGGER.setLevel(default_log_level) +    return LOGGER + +def get_logger(child_name): +    """docstring for get_logger""" +    assert LOGGER is not None +    return get_main_logger().getChild(child_name) +     + +if __name__ == "__main__": +    print("Testing logger: ") +    LOG = get_main_logger().getChild('test') +    LOG.setLevel(TRACE) +    LOG.trace("trace message") +    LOG.debug("debug message") +    LOG.info("info message") +    LOG.warning("warning message") +    LOG.error("error message") +    LOG.critical("critical message") + +    LOG2 = get_main_logger() +    LOG3 = get_main_logger() +    assert LOG2 is LOG3 + diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index 77414c034..459f8833f 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -19,12 +19,13 @@ Mboard implementation base class  """  import os +from six import iteritems +from ..mpmlog import get_logger +from logging import getLogger  from ..types import EEPROM  from .. import dboard_manager  from .udev import get_eeprom_path  from .udev import get_spidev_nodes -from six import iteritems -  class PeriphManagerBase(object):      """" @@ -48,22 +49,38 @@ class PeriphManagerBase(object):      available_endpoints = range(256)      def __init__(self): +        self.log = get_logger('PeriphManager')          # I know my EEPROM address, lets use it          self.overlays = "" -        (self._eeprom_head, self._eeprom_rawdata) = EEPROM().read_eeprom( -            get_eeprom_path(self.mboard_eeprom_addr)) -        print self._eeprom_head +        # (self._eeprom_head, self._eeprom_rawdata) = EEPROM().read_eeprom( +            # get_eeprom_path(self.mboard_eeprom_addr)) +        # print self._eeprom_head          self._dboard_eeproms = {} -        for dboard_slot, eeprom_addr in self.dboard_eeprom_addrs.iteritems(): -            spi_devices = [] -            # I know EEPROM adresses for my dboard slots -            eeprom_data = EEPROM().read_eeprom(get_eeprom_path(eeprom_addr)) -            # I know spidev masters on the dboard slots -            hw_pid = eeprom_data[0].get("hw_pid", 0) -            if hw_pid in dboard_manager.HW_PIDS: -                spi_devices = get_spidev_nodes(self.dboard_spimaster_addrs.get(dboard_slot)) -            dboard = dboard_manager.HW_PIDS.get(hw_pid, dboard_manager.unknown) -            self.dboards.update({dboard_slot: dboard(spi_devices, eeprom_data)}) +        self.log.debug("Initializing dboards") +        # for dboard_slot, eeprom_addr in self.dboard_eeprom_addrs.iteritems(): +            # self.log.debug("Adding dboard for slot {0}".format(dboard_slot)) +            # spi_devices = [] +            # # I know EEPROM adresses for my dboard slots +            # eeprom_data = EEPROM().read_eeprom(get_eeprom_path(eeprom_addr)) +            # # I know spidev masters on the dboard slots +            # hw_pid = eeprom_data[0].get("hw_pid", 0) +            # if hw_pid in dboard_manager.HW_PIDS: +                # spi_devices = get_spidev_nodes(self.dboard_spimaster_addrs.get(dboard_slot)) +            # dboard = dboard_manager.HW_PIDS.get(hw_pid, dboard_manager.unknown) +            # self.dboards.update({dboard_slot: dboard(spi_devices, eeprom_data)}) +        dboard_slot = "A" +        self.log.debug("Adding dboard for slot {0}".format(dboard_slot)) +        spi_devices = [] +        # I know EEPROM adresses for my dboard slots +        # eeprom_data = EEPROM().read_eeprom(get_eeprom_path(eeprom_addr)) +        eeprom_data = None +        # I know spidev masters on the dboard slots +        hw_pid = 2 +        if hw_pid in dboard_manager.HW_PIDS: +            spi_devices = get_spidev_nodes("e0006000.spi") +            self.log.debug("found spidev nodes: {0}".format(spi_devices)) +        dboard = dboard_manager.HW_PIDS.get(hw_pid, dboard_manager.unknown) +        self.dboards.update({dboard_slot: dboard(spi_devices, eeprom_data)})      def safe_list_updateable_components(self):          """ diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 4f193b54b..364d50908 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -31,9 +31,6 @@ from logging import getLogger  import netaddr  import socket -LOG = getLogger(__name__) - -  class n310(PeriphManagerBase):      """      Holds N310 specific attributes and methods @@ -42,13 +39,15 @@ class n310(PeriphManagerBase):      mboard_type = "n310"      mboard_eeprom_addr = "e0005000.i2c"      # dboard_eeprom_addrs = {"A": "something", "B": "else"} +    # dboard_eeprom_addrs = {"A": "e0004000.i2c",}      # dboard_spimaster_addrs = {"A": "something", "B": "else"} +    dboard_spimaster_addrs = {"A": "e0006000.spi",}      interfaces = {}      def __init__(self, *args, **kwargs):          # First initialize parent class - will populate self._eeprom_head and self._eeprom_rawdata          super(n310, self).__init__(*args, **kwargs) -        data = self._read_eeprom_v1(self._eeprom_rawdata) +        # data = self._read_eeprom_v1(self._eeprom_rawdata)          # mac 0: mgmt port, mac1: sfp0, mac2: sfp1          # self.interfaces["mgmt"] = {          #     "mac_addr": byte_to_mac(data[0]), @@ -62,12 +61,15 @@ class n310(PeriphManagerBase):          #     "mac_addr": byte_to_mac(data[2]),          #     "addrs": get_iface_addrs(byte_to_mac(data[2]))          # } -        self.mboard_info["serial"] = data[0]  # some format +        # self.mboard_info["serial"] = data[0]  # some format +        self.mboard_info["serial"] = '123'  # some format          with open("/sys/class/rfnoc_crossbar/crossbar0/local_addr", "w") as xbar:              xbar.write("0x2") -          # if header.get("dataversion", 0) == 1: +        # Initialize our daughterboards: +        self.log.debug("Initializing A-side dboard") +        self.dboards['A'].init_device()      def _read_eeprom_v1(self, data):          """ @@ -119,11 +121,11 @@ class n310(PeriphManagerBase):              # uio_path, uio_size = get_uio_node("misc-enet-regs0")              uio_path = "/dev/uio0"              uio_size = 0x2000 -            LOG.debug("got uio_path and size") +            self.log.debug("got uio_path and size")              uio_obj = uio(uio_path, uio_size, read_only=False) -            LOG.info("got my uio") -            LOG.info("ip_addr: %s", sender_addr) -            # LOG.info("mac_addr: %s", mac_addr) +            self.log.info("got my uio") +            self.log.info("ip_addr: %s", sender_addr) +            # self.log.info("mac_addr: %s", mac_addr)              ip_addr = int(netaddr.IPAddress(sender_addr))              mac_addr = int(netaddr.EUI(mac_addr))              uio_obj.poke32(0x1000 + 4*new_ep, ip_addr) diff --git a/mpm/python/usrp_mpm/periph_manager/net.py b/mpm/python/usrp_mpm/periph_manager/net.py index 2df771549..4eb1890cb 100644 --- a/mpm/python/usrp_mpm/periph_manager/net.py +++ b/mpm/python/usrp_mpm/periph_manager/net.py @@ -20,10 +20,7 @@ N310 implementation module  import itertools  import socket  from pyroute2 import IPRoute -from logging import getLogger - -LOG = getLogger(__name__) - +from ..mpmlog import get_logger  def get_iface_addrs(mac_addr):      """ @@ -57,7 +54,7 @@ def get_mac_addr(remote_addr):      ip2 = IPRoute()      addrs = ip2.get_neighbours(dst=remote_addr)      if len(addrs) > 1: -        LOG.warning("More than one device with the same IP address found. Picking entry at random") +        get_logger('get_mac_addr').warning("More than one device with the same IP address found. Picking entry at random")      if not addrs:          return None      return addrs[0].get_attr('NDA_LLADDR') diff --git a/mpm/python/usrp_mpm/periph_manager/udev.py b/mpm/python/usrp_mpm/periph_manager/udev.py index a42c95ef5..73601e85c 100644 --- a/mpm/python/usrp_mpm/periph_manager/udev.py +++ b/mpm/python/usrp_mpm/periph_manager/udev.py @@ -17,9 +17,7 @@  import pyudev  import os -from logging import getLogger -LOG = getLogger(__name__) - +from ..mpmlog import get_logger  def get_eeprom_path(address):      """ @@ -51,19 +49,20 @@ def get_uio_node(uio_name):      context = pyudev.Context()      paths = [device.sys_path               for device in context.list_devices(subsystem="uio")] -    LOG.debug("get_uio_node") -    LOG.debug("got paths: %s", paths) +    log = get_logger('get_uio_node') +    log.debug("get_uio_node") +    log.debug("got paths: %s", paths)      for path in paths:          with open(os.path.join(path, "maps", "map0", "name"), "r") as uio_file:              name = uio_file.read() -        LOG.debug("uio_node name: %s", name.strip()) +        log.debug("uio_node name: %s", name.strip())          if name.strip() == uio_name:              with open(os.path.join(path, "maps", "map0", "size"), "r") as uio_file:                  size = uio_file.read() -            LOG.debug("uio_node size: %s", size.strip()) -            LOG.debug("uio_node syspath: %s", path) +            log.debug("uio_node size: %s", size.strip()) +            log.debug("uio_node syspath: %s", path)              # device = pyudev.Device.from_sys_path(context, path) -            LOG.debug("got udev device") -            LOG.debug("device_node: %s size: %s", "/dev/uio0", size.strip()) +            log.debug("got udev device") +            log.debug("device_node: %s size: %s", "/dev/uio0", size.strip())              return ("/dev/uio0", int(size.strip()))      return ("", 0) diff --git a/mpm/python/usrp_mpm/rpc_server.py b/mpm/python/usrp_mpm/rpc_server.py index df73b1ab0..734dc1df7 100644 --- a/mpm/python/usrp_mpm/rpc_server.py +++ b/mpm/python/usrp_mpm/rpc_server.py @@ -18,7 +18,6 @@  Implemented RPC Servers  """  from __future__ import print_function -from logging import getLogger  from gevent.server import StreamServer  from gevent.pool import Pool  from gevent import signal @@ -30,11 +29,8 @@ from mprpc import RPCServer  from random import choice  from six import iteritems  from string import ascii_letters, digits -from threading import Timer  from multiprocessing import Process - - -LOG = getLogger(__name__) +from .mpmlog import get_main_logger  class MPMServer(RPCServer): @@ -48,6 +44,7 @@ class MPMServer(RPCServer):      _mb_methods = []      def __init__(self, state, mgr, *args, **kwargs): +        self.log = get_main_logger().getChild('RPCServer')          self._state = state          self._timer = Greenlet()          self.periph_manager = mgr @@ -78,8 +75,7 @@ class MPMServer(RPCServer):          Adds a method with the name command to the RPC server          This command will require an acquired claim on the device          """ -        LOG.debug("adding command %s pointing to %s", command, function) - +        self.log.trace("adding command %s pointing to %s", command, function)          def new_function(token, *args):              if token[:256] != self._state.claim_token.value:                  return False @@ -92,7 +88,7 @@ class MPMServer(RPCServer):          Add a safe method which does not require a claim on the          device          """ -        LOG.debug("adding safe command %s pointing to %s", command, function) +        self.log.trace("adding safe command %s pointing to %s", command, function)          setattr(self, command, function)      def list_methods(self): @@ -109,7 +105,7 @@ class MPMServer(RPCServer):          Take in data as argument and send it back          This is a safe method which can be called without a claim on the device          """ -        LOG.debug("I was pinged from: %s:%s", self.client_host, self.client_port) +        self.log.debug("I was pinged from: %s:%s", self.client_host, self.client_port)          return data      def claim(self, sender_id): @@ -120,14 +116,14 @@ class MPMServer(RPCServer):          self._state.lock.acquire()          if self._state.claim_status.value:              return "" -        LOG.debug("claiming from: %s", self.client_host) +        self.log.debug("claiming from: %s", self.client_host)          self.periph_manager.claimed = True          self._state.claim_token.value = ''.join(choice(ascii_letters + digits) for _ in range(256))          self._state.claim_status.value = True          self._state.lock.release()          self.sender_id = sender_id          self._reset_timer() -        LOG.debug("giving token: %s to host: %s", self._state.claim_token.value, self.client_host) +        self.log.debug("giving token: %s to host: %s", self._state.claim_token.value, self.client_host)          return self._state.claim_token.value      def reclaim(self, token): @@ -140,23 +136,20 @@ class MPMServer(RPCServer):          if self._state.claim_status.value:              if self._state.claim_token.value == token[:256]:                  self._state.lock.release() -                LOG.debug("reclaimed from: %s", self.client_host) +                self.log.debug("reclaimed from: %s", self.client_host)                  self._reset_timer()                  return True              self._state.lock.release() -            LOG.debug("reclaim failed from: %s", self.client_host) +            self.log.debug("reclaim failed from: %s", self.client_host)              return False -        LOG.debug("trying to reclaim unclaimed device from: %s", self.client_host) +        self.log.debug("trying to reclaim unclaimed device from: %s", self.client_host)          return False - - -      def _unclaim(self):          """          unconditional unclaim - for internal use          """ -        LOG.debug("releasing claim") +        self.log.debug("releasing claim")          self._state.claim_status.value = False          self._state.claim_token.value = ""          self.sender_id = None  | 
