From af35903d17d8cd314a2626f38eded72956459e23 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 2 May 2017 22:13:15 -0700 Subject: mpm: Renamed types submodule mpmtypes to avoid import confusion --- mpm/python/usrp_mpm/CMakeLists.txt | 2 +- mpm/python/usrp_mpm/__init__.py | 2 +- mpm/python/usrp_mpm/mpmtypes.py | 102 ++++++++++++++++++++++ mpm/python/usrp_mpm/periph_manager/__init__.py.in | 2 +- mpm/python/usrp_mpm/periph_manager/n310.py | 2 +- mpm/python/usrp_mpm/types.py | 102 ---------------------- 6 files changed, 106 insertions(+), 106 deletions(-) create mode 100644 mpm/python/usrp_mpm/mpmtypes.py delete mode 100644 mpm/python/usrp_mpm/types.py (limited to 'mpm/python/usrp_mpm') diff --git a/mpm/python/usrp_mpm/CMakeLists.txt b/mpm/python/usrp_mpm/CMakeLists.txt index 44c70619f..e9e95555c 100644 --- a/mpm/python/usrp_mpm/CMakeLists.txt +++ b/mpm/python/usrp_mpm/CMakeLists.txt @@ -26,7 +26,7 @@ SET(USRP_MPM_TOP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/nijesdcore.py ${CMAKE_CURRENT_SOURCE_DIR}/rpc_server.py ${CMAKE_CURRENT_SOURCE_DIR}/sysfs_gpio.py - ${CMAKE_CURRENT_SOURCE_DIR}/types.py + ${CMAKE_CURRENT_SOURCE_DIR}/mpmtypes.py ${CMAKE_CURRENT_SOURCE_DIR}/uio.py ) LIST(APPEND USRP_MPM_FILES ${USRP_MPM_TOP_FILES}) diff --git a/mpm/python/usrp_mpm/__init__.py b/mpm/python/usrp_mpm/__init__.py index b91896542..29e0b1a09 100644 --- a/mpm/python/usrp_mpm/__init__.py +++ b/mpm/python/usrp_mpm/__init__.py @@ -20,7 +20,7 @@ MPM Module from .discovery import spawn_discovery_process from .rpc_server import spawn_rpc_process -from . import types +from . import mpmtypes from . import periph_manager from . import dboard_manager from .mpmlog import get_main_logger diff --git a/mpm/python/usrp_mpm/mpmtypes.py b/mpm/python/usrp_mpm/mpmtypes.py new file mode 100644 index 000000000..1fbddb934 --- /dev/null +++ b/mpm/python/usrp_mpm/mpmtypes.py @@ -0,0 +1,102 @@ +# +# 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 . +# +""" +MPM types +""" +import ctypes +from multiprocessing import Value +from multiprocessing import Array +from multiprocessing import RLock +import struct + +MPM_RPC_PORT = 49601 +MPM_DISCOVERY_PORT = 49600 + +MPM_DISCOVERY_MESSAGE = "MPM-DISC" + + +class SharedState(object): + """ + Holds information which should be shared between processes + Usage should be kept to a minimum + """ + + def __init__(self): + self.lock = RLock() + self.claim_status = Value( + ctypes.c_bool, + False, lock=self.lock) # lock + self.claim_token = Array( + ctypes.c_char, 256, + lock=self.lock) # String with max length of 256 + + +class SID(object): + def __init__(self, sid=0): + self.src_addr = sid >> 24 + self.src_ep = (sid >> 16) & 0xFF + self.dst_addr = (sid >> 8) & 0xFF + self.dst_ep = sid & 0xFF + + def set_src_addr(self, new_addr): + self.src_addr = new_addr & 0xFF + + def set_dst_addr(self, new_addr): + self.dst_addr = new_addr & 0xFF + + def set_src_ep(self, new_addr): + self.src_ep = new_addr & 0xFF + + def set_dst_ep(self, new_addr): + self.dst_ep = new_addr & 0xFF + + def get(self): + return (self.src_addr << 24) | (self.src_ep << 16) | (self.dst_addr << 8) | self.dst_ep + + +class EEPROM(object): + """ + Reads out common properties and rawdata out of a nvmem path + """ + # eeprom_header contains: + # 4 bytes magic + # 4 bytes version + # 4x4 bytes mcu_flags -> throw them away + # 2 bytes hw_pid + # 2 bytes hw_rev + # + # 28 bytes in total + eeprom_header = struct.Struct("!I I 16x H H") + + def read_eeprom(self, nvmem_path): + """ + Read the EEPROM located at nvmem_path and return a tuple (header, data) + Header is already parsed in the common header fields + Data contains the full eeprom data structure + """ + with open(nvmem_path, "rb") as nvmem_file: + data = nvmem_file.read(256) + _header = self.eeprom_header.unpack_from(data) + print hex(_header[0]), hex(_header[1]), hex(_header[2]), hex(_header[3]) + header = { + "magic": _header[0], + "version": _header[1], + "hw_pid": _header[2], + "hw_rev": _header[3], + } + print header + return (header, data) diff --git a/mpm/python/usrp_mpm/periph_manager/__init__.py.in b/mpm/python/usrp_mpm/periph_manager/__init__.py.in index c2dd7927c..34d29137a 100644 --- a/mpm/python/usrp_mpm/periph_manager/__init__.py.in +++ b/mpm/python/usrp_mpm/periph_manager/__init__.py.in @@ -21,6 +21,6 @@ periph_manager __init__.py # This is where the import magic happens from .. import libpyusrp_periphs as lib from .. import dboard_manager -from .. import types +from .. import mpmtypes from .${MPM_DEVICE} import ${MPM_DEVICE} as periph_manager diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 56dba2ca8..8cc33cc9c 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -25,7 +25,7 @@ from .base import PeriphManagerBase from .net import get_iface_addrs from .net import byte_to_mac from .net import get_mac_addr -from ..types import SID +from ..mpmtypes import SID from ..uio import UIO from ..sysfs_gpio import SysFSGPIO from .. import libpyusrp_periphs as lib diff --git a/mpm/python/usrp_mpm/types.py b/mpm/python/usrp_mpm/types.py deleted file mode 100644 index 1fbddb934..000000000 --- a/mpm/python/usrp_mpm/types.py +++ /dev/null @@ -1,102 +0,0 @@ -# -# 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 . -# -""" -MPM types -""" -import ctypes -from multiprocessing import Value -from multiprocessing import Array -from multiprocessing import RLock -import struct - -MPM_RPC_PORT = 49601 -MPM_DISCOVERY_PORT = 49600 - -MPM_DISCOVERY_MESSAGE = "MPM-DISC" - - -class SharedState(object): - """ - Holds information which should be shared between processes - Usage should be kept to a minimum - """ - - def __init__(self): - self.lock = RLock() - self.claim_status = Value( - ctypes.c_bool, - False, lock=self.lock) # lock - self.claim_token = Array( - ctypes.c_char, 256, - lock=self.lock) # String with max length of 256 - - -class SID(object): - def __init__(self, sid=0): - self.src_addr = sid >> 24 - self.src_ep = (sid >> 16) & 0xFF - self.dst_addr = (sid >> 8) & 0xFF - self.dst_ep = sid & 0xFF - - def set_src_addr(self, new_addr): - self.src_addr = new_addr & 0xFF - - def set_dst_addr(self, new_addr): - self.dst_addr = new_addr & 0xFF - - def set_src_ep(self, new_addr): - self.src_ep = new_addr & 0xFF - - def set_dst_ep(self, new_addr): - self.dst_ep = new_addr & 0xFF - - def get(self): - return (self.src_addr << 24) | (self.src_ep << 16) | (self.dst_addr << 8) | self.dst_ep - - -class EEPROM(object): - """ - Reads out common properties and rawdata out of a nvmem path - """ - # eeprom_header contains: - # 4 bytes magic - # 4 bytes version - # 4x4 bytes mcu_flags -> throw them away - # 2 bytes hw_pid - # 2 bytes hw_rev - # - # 28 bytes in total - eeprom_header = struct.Struct("!I I 16x H H") - - def read_eeprom(self, nvmem_path): - """ - Read the EEPROM located at nvmem_path and return a tuple (header, data) - Header is already parsed in the common header fields - Data contains the full eeprom data structure - """ - with open(nvmem_path, "rb") as nvmem_file: - data = nvmem_file.read(256) - _header = self.eeprom_header.unpack_from(data) - print hex(_header[0]), hex(_header[1]), hex(_header[2]), hex(_header[3]) - header = { - "magic": _header[0], - "version": _header[1], - "hw_pid": _header[2], - "hw_rev": _header[3], - } - print header - return (header, data) -- cgit v1.2.3