Skip to content

Commit 5734f37

Browse files
authored
Export PdoMap and PdoVariable classes in pdo module (#464)
* Reintroduce PdoMap and PdoVariable to public API of sub-package pdo. With commit 0285f58, the Map class was inadvertently removed from the imports directly available within the canopen.pdo package. However, it is referenced as canopen.pdo.PdoMap in the p402 module and documentation. Restore that import using the new names PdoMap and PdoVariable. Move the compatibility define to the very bottom, just like in other modules. Provide an __all__ listing to clarify what constitutes the public API. * Use type hints for PdoMap in BaseNode402. Replace the sphinx parameter type documentation with a proper type hint annotation. Same for the tpdo_pointers and rpdo_pointers attributes.
1 parent 5db5913 commit 5734f37

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

canopen/pdo/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import logging
22

33
from canopen import node
4-
from canopen.pdo.base import PdoBase, PdoMaps
4+
from canopen.pdo.base import PdoBase, PdoMap, PdoMaps, PdoVariable
55

6-
# Compatibility
7-
from canopen.pdo.base import Variable
6+
7+
__all__ = [
8+
"PdoBase",
9+
"PdoMap",
10+
"PdoMaps",
11+
"PdoVariable",
12+
"PDO",
13+
"RPDO",
14+
"TPDO",
15+
]
816

917
logger = logging.getLogger(__name__)
1018

@@ -77,3 +85,7 @@ def stop(self):
7785
pdo.stop()
7886
else:
7987
raise TypeError('The node type does not support this function.')
88+
89+
90+
# Compatibility
91+
Variable = PdoVariable

canopen/profiles/p402.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# inspired by the NmtMaster code
22
import logging
33
import time
4+
from typing import Dict
45

56
from canopen.node import RemoteNode
7+
from canopen.pdo import PdoMap
68
from canopen.sdo import SdoCommunicationError
79

810
logger = logging.getLogger(__name__)
@@ -212,8 +214,8 @@ class BaseNode402(RemoteNode):
212214
def __init__(self, node_id, object_dictionary):
213215
super(BaseNode402, self).__init__(node_id, object_dictionary)
214216
self.tpdo_values = {} # { index: value from last received TPDO }
215-
self.tpdo_pointers = {} # { index: pdo.PdoMap instance }
216-
self.rpdo_pointers = {} # { index: pdo.PdoMap instance }
217+
self.tpdo_pointers: Dict[int, PdoMap] = {}
218+
self.rpdo_pointers: Dict[int, PdoMap] = {}
217219

218220
def setup_402_state_machine(self, read_pdos=True):
219221
"""Configure the state machine by searching for a TPDO that has the StatusWord mapped.
@@ -453,11 +455,10 @@ def is_op_mode_supported(self, mode):
453455
bits = OperationMode.SUPPORTED[mode]
454456
return self._op_mode_support & bits == bits
455457

456-
def on_TPDOs_update_callback(self, mapobject):
458+
def on_TPDOs_update_callback(self, mapobject: PdoMap):
457459
"""Cache updated values from a TPDO received from this node.
458460
459461
:param mapobject: The received PDO message.
460-
:type mapobject: canopen.pdo.PdoMap
461462
"""
462463
for obj in mapobject:
463464
self.tpdo_values[obj.index] = obj.raw

0 commit comments

Comments
 (0)