diff --git a/canopen/node/local.py b/canopen/node/local.py index eb74b98d..a70373ab 100644 --- a/canopen/node/local.py +++ b/canopen/node/local.py @@ -7,6 +7,7 @@ from canopen.nmt import NmtSlave from canopen.emcy import EmcyProducer from canopen.objectdictionary import ObjectDictionary +from canopen.utils import pretty_index from canopen import objectdictionary logger = logging.getLogger(__name__) @@ -86,7 +87,7 @@ def get_data( return obj.encode_raw(obj.default) # Resource not available - logger.info("Resource unavailable for 0x%04X:%02X", index, subindex) + logger.info("Resource unavailable for %s", pretty_index(index, subindex)) raise SdoAbortedError(0x060A0023) def set_data( diff --git a/canopen/node/remote.py b/canopen/node/remote.py index 37eb2ab2..de813f2b 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -7,6 +7,7 @@ from canopen.pdo import TPDO, RPDO, PDO from canopen.objectdictionary import ODRecord, ODArray, ODVariable, ObjectDictionary from canopen.node.base import BaseNode +from canopen.utils import pretty_index logger = logging.getLogger(__name__) @@ -122,13 +123,13 @@ def __load_configuration_helper(self, index, subindex, name, value): """ try: if subindex is not None: - logger.info('SDO [0x%04X][0x%02X]: %s: %#06x', - index, subindex, name, value) + logger.info('SDO [%s]: %s: %#06x', + pretty_index(index, subindex), name, value) self.sdo[index][subindex].raw = value else: self.sdo[index].raw = value - logger.info('SDO [0x%04X]: %s: %#06x', - index, name, value) + logger.info('SDO [%s]: %s: %#06x', + pretty_index(index), name, value) except SdoCommunicationError as e: logger.warning(str(e)) except SdoAbortedError as e: @@ -137,8 +138,8 @@ def __load_configuration_helper(self, index, subindex, name, value): if e.code != 0x06010002: # Abort codes other than "Attempt to write a read-only object" # should still be reported. - logger.warning('[ERROR SETTING object 0x%04X:%02X] %s', - index, subindex, e) + logger.warning('[ERROR SETTING object %s] %s', + pretty_index(index, subindex), e) raise def load_configuration(self): diff --git a/canopen/pdo/base.py b/canopen/pdo/base.py index 1f4bf3e4..54b43e6f 100644 --- a/canopen/pdo/base.py +++ b/canopen/pdo/base.py @@ -8,6 +8,7 @@ from canopen.sdo import SdoAbortedError from canopen import objectdictionary from canopen import variable +from canopen.utils import pretty_index PDO_NOT_VALID = 1 << 31 RTR_NOT_ALLOWED = 1 << 30 @@ -398,8 +399,8 @@ def save(self) -> None: self._fill_map(self.map_array[0].raw) subindex = 1 for var in self.map: - logger.info("Writing %s (0x%04X:%02X, %d bits) to PDO map", - var.name, var.index, var.subindex, var.length) + logger.info("Writing %s (%s, %d bits) to PDO map", + var.name, pretty_index(var.index, var.subindex), var.length) if hasattr(self.pdo_node.node, "curtis_hack") and self.pdo_node.node.curtis_hack: # Curtis HACK: mixed up field order self.map_array[subindex].raw = (var.index | var.subindex << 16 | @@ -467,8 +468,8 @@ def add_variable( # We want to see the bit fields within the PDO start_bit = var.offset end_bit = start_bit + var.length - 1 - logger.info("Adding %s (0x%04X:%02X) at bits %d - %d to PDO map", - var.name, var.index, var.subindex, start_bit, end_bit) + logger.info("Adding %s (%s) at bits %d - %d to PDO map", + var.name, pretty_index(var.index, var.subindex), start_bit, end_bit) self.map.append(var) self.length += var.length except KeyError as exc: diff --git a/canopen/profiles/p402.py b/canopen/profiles/p402.py index c2b08997..e09ea775 100644 --- a/canopen/profiles/p402.py +++ b/canopen/profiles/p402.py @@ -4,6 +4,7 @@ from canopen.node import RemoteNode from canopen.sdo import SdoCommunicationError +from canopen.utils import pretty_index logger = logging.getLogger(__name__) @@ -249,7 +250,7 @@ def _init_tpdo_values(self): if tpdo.enabled: tpdo.add_callback(self.on_TPDOs_update_callback) for obj in tpdo: - logger.debug('Configured TPDO: %s', obj.index) + logger.debug('Configured TPDO: %s', pretty_index(obj.index)) if obj.index not in self.tpdo_values: self.tpdo_values[obj.index] = 0 self.tpdo_pointers[obj.index] = obj @@ -260,7 +261,7 @@ def _init_rpdo_pointers(self): for rpdo in self.rpdo.values(): if rpdo.enabled: for obj in rpdo: - logger.debug('Configured RPDO: %s', obj.index) + logger.debug('Configured RPDO: %s', pretty_index(obj.index)) if obj.index not in self.rpdo_pointers: self.rpdo_pointers[obj.index] = obj diff --git a/canopen/sdo/client.py b/canopen/sdo/client.py index 8d64a517..26b4ff6e 100644 --- a/canopen/sdo/client.py +++ b/canopen/sdo/client.py @@ -245,7 +245,7 @@ def __init__(self, sdo_client, index, subindex=0): self._toggle = 0 self.pos = 0 - logger.debug("Reading 0x%04X:%02X from node %d", index, subindex, + logger.debug("Reading %s from node %d", pretty_index(index, subindex), sdo_client.rx_cobid - 0x600) request = bytearray(8) SDO_STRUCT.pack_into(request, 0, REQUEST_UPLOAD, index, subindex) @@ -474,7 +474,7 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True): self._ackseq = 0 self._error = False - logger.debug("Reading 0x%04X:%02X from node %d", index, subindex, + logger.debug("Reading %s from node %d", pretty_index(index, subindex), sdo_client.rx_cobid - 0x600) # Initiate Block Upload request = bytearray(8) @@ -644,7 +644,7 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support if request_crc_support: command |= CRC_SUPPORTED request = bytearray(8) - logger.info("Initiating block download for 0x%04X:%02X", index, subindex) + logger.info("Initiating block download for %s", pretty_index(index, subindex)) if size is not None: logger.debug("Expected size of data is %d bytes", size) command |= BLOCK_SIZE_SPECIFIED diff --git a/canopen/sdo/server.py b/canopen/sdo/server.py index d9fdd29e..bfc33b55 100644 --- a/canopen/sdo/server.py +++ b/canopen/sdo/server.py @@ -3,6 +3,7 @@ from canopen.sdo.base import SdoBase from canopen.sdo.constants import * from canopen.sdo.exceptions import * +from canopen.utils import pretty_index logger = logging.getLogger(__name__) @@ -66,12 +67,12 @@ def init_upload(self, request): data = self._node.get_data(index, subindex, check_readable=True) size = len(data) if size <= 4: - logger.info("Expedited upload for 0x%04X:%02X", index, subindex) + logger.info("Expedited upload for %s", pretty_index(index, subindex)) res_command |= EXPEDITED res_command |= (4 - size) << 2 response[4:4 + size] = data else: - logger.info("Initiating segmented upload for 0x%04X:%02X", index, subindex) + logger.info("Initiating segmented upload for %s", pretty_index(index, subindex)) struct.pack_into("> 2) & 0x3) else: size = 4 self._node.set_data(index, subindex, request[4:4 + size], check_writable=True) else: - logger.info("Initiating segmented download for 0x%04X:%02X", index, subindex) + logger.info("Initiating segmented download for %s", pretty_index(index, subindex)) if command & SIZE_SPECIFIED: size, = struct.unpack_from(" Union[int, bool, float, str, bytes]: @raw.setter def raw(self, value: Union[int, bool, float, str, bytes]): - logger.debug("Writing %r (0x%04X:%02X) = %r", - self.name, self.index, - self.subindex, value) + logger.debug("Writing %r (%s) = %r", + self.name, pretty_index(self.index, self.subindex), value) self.data = self.od.encode_raw(value) @property