Skip to content

Commit

Permalink
Rename Maps to PdoMaps and Map to PdoMap (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinse committed May 15, 2024
1 parent 26a68b5 commit d38045f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions canopen/pdo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from canopen import node
from canopen.pdo.base import PdoBase, Maps
from canopen.pdo.base import PdoBase, PdoMaps

# Compatibility
from canopen.pdo.base import Variable
Expand Down Expand Up @@ -38,7 +38,7 @@ class RPDO(PdoBase):

def __init__(self, node):
super(RPDO, self).__init__(node)
self.map = Maps(0x1400, 0x1600, self, 0x200)
self.map = PdoMaps(0x1400, 0x1600, self, 0x200)
logger.debug('RPDO Map as {0}'.format(len(self.map)))

def stop(self):
Expand All @@ -63,7 +63,7 @@ class TPDO(PdoBase):

def __init__(self, node):
super(TPDO, self).__init__(node)
self.map = Maps(0x1800, 0x1A00, self, 0x180)
self.map = PdoMaps(0x1800, 0x1A00, self, 0x180)
logger.debug('TPDO Map as {0}'.format(len(self.map)))

def stop(self):
Expand Down
18 changes: 10 additions & 8 deletions canopen/pdo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PdoBase(Mapping):

def __init__(self, node):
self.network = None
self.map = None # instance of Maps
self.map = None # instance of PdoMaps
self.node = node

def __iter__(self):
Expand Down Expand Up @@ -121,7 +121,7 @@ def stop(self):
pdo_map.stop()


class Maps(Mapping):
class PdoMaps(Mapping):
"""A collection of transmit or receive maps."""

def __init__(self, com_offset, map_offset, pdo_node: PdoBase, cob_base=None):
Expand All @@ -131,10 +131,10 @@ def __init__(self, com_offset, map_offset, pdo_node: PdoBase, cob_base=None):
:param pdo_node:
:param cob_base:
"""
self.maps: Dict[int, "Map"] = {}
self.maps: Dict[int, "PdoMap"] = {}
for map_no in range(512):
if com_offset + map_no in pdo_node.node.object_dictionary:
new_map = Map(
new_map = PdoMap(
pdo_node,
pdo_node.node.sdo[com_offset + map_no],
pdo_node.node.sdo[map_offset + map_no])
Expand All @@ -143,7 +143,7 @@ def __init__(self, com_offset, map_offset, pdo_node: PdoBase, cob_base=None):
new_map.predefined_cob_id = cob_base + map_no * 0x100 + pdo_node.node.id
self.maps[map_no + 1] = new_map

def __getitem__(self, key: int) -> "Map":
def __getitem__(self, key: int) -> "PdoMap":
return self.maps[key]

def __iter__(self) -> Iterable[int]:
Expand All @@ -153,7 +153,7 @@ def __len__(self) -> int:
return len(self.maps)


class Map:
class PdoMap:
"""One message which can have up to 8 bytes of variables mapped."""

def __init__(self, pdo_node, com_record, map_array):
Expand Down Expand Up @@ -301,12 +301,12 @@ def on_message(self, can_id, data, timestamp):
for callback in self.callbacks:
callback(self)

def add_callback(self, callback: Callable[["Map"], None]) -> None:
def add_callback(self, callback: Callable[["PdoMap"], None]) -> None:
"""Add a callback which will be called on receive.
:param callback:
The function to call which must take one argument of a
:class:`~canopen.pdo.Map`.
:class:`~canopen.pdo.PdoMap`.
"""
self.callbacks.append(callback)

Expand Down Expand Up @@ -606,3 +606,5 @@ def set_data(self, data: bytes):

# For compatibility
Variable = PdoVariable
Maps = PdoMaps
Map = PdoMap
6 changes: 3 additions & 3 deletions canopen/profiles/p402.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class BaseNode402(RemoteNode):
def __init__(self, node_id, object_dictionary):
super(BaseNode402, self).__init__(node_id, object_dictionary)
self.tpdo_values = {} # { index: value from last received TPDO }
self.tpdo_pointers = {} # { index: pdo.Map instance }
self.rpdo_pointers = {} # { index: pdo.Map instance }
self.tpdo_pointers = {} # { index: pdo.PdoMap instance }
self.rpdo_pointers = {} # { index: pdo.PdoMap instance }

def setup_402_state_machine(self, read_pdos=True):
"""Configure the state machine by searching for a TPDO that has the StatusWord mapped.
Expand Down Expand Up @@ -459,7 +459,7 @@ def on_TPDOs_update_callback(self, mapobject):
"""Cache updated values from a TPDO received from this node.
:param mapobject: The received PDO message.
:type mapobject: canopen.pdo.Map
:type mapobject: canopen.pdo.PdoMap
"""
for obj in mapobject:
self.tpdo_values[obj.index] = obj.raw
Expand Down
4 changes: 2 additions & 2 deletions doc/pdo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ API

.. describe:: pdo[no]

Return the :class:`canopen.pdo.Map` for the specified map number.
Return the :class:`canopen.pdo.PdoMap` for the specified map number.
First map starts at 1.

.. describe:: iter(pdo)
Expand All @@ -101,7 +101,7 @@ API
Return the number of supported maps.


.. autoclass:: canopen.pdo.Map
.. autoclass:: canopen.pdo.PdoMap
:members:

.. describe:: map[name]
Expand Down

0 comments on commit d38045f

Please sign in to comment.