xdd: Implement option to load object dictionary from XDD file.#614
xdd: Implement option to load object dictionary from XDD file.#614zaporozhets wants to merge 1 commit intocanopen-python:masterfrom
Conversation
505c938 to
ea733fe
Compare
Signed-off-by: Taras Zaporozhets <zaporozhets.taras@gmail.com>
ea733fe to
466b1b2
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Hi @acolomb, could you please take a look? |
|
Thank you very much for this contribution. Happy to see some progress on the XDD front. I started taking a look and overall I think it's going in a good direction. Need to take some more time to put down my thoughts in detail, but some high-level pointers first:
|
acolomb
left a comment
There was a problem hiding this comment.
Just a partial review again, but I hope you get the general idea... More to come when I get another look with a fresher brain.
|
|
||
| import re | ||
| import xml.etree.ElementTree as etree | ||
| from configparser import NoOptionError |
| @@ -0,0 +1,306 @@ | |||
| import logging | |||
|
|
|||
| import re | ||
| import xml.etree.ElementTree as etree | ||
| from configparser import NoOptionError | ||
| from typing import TYPE_CHECKING |
There was a problem hiding this comment.
| from typing import TYPE_CHECKING |
| if TYPE_CHECKING: | ||
| import canopen.network |
There was a problem hiding this comment.
| if TYPE_CHECKING: | |
| import canopen.network |
| RECORD = 9 | ||
|
|
||
|
|
||
| def import_xdd(xdd, node_id): |
There was a problem hiding this comment.
With static type hints, something like this:
| def import_xdd(xdd, node_id): | |
| def import_xdd( | |
| xdd: Union[etree.Element, str, bytes, os.PathLike], | |
| node_id: Optional[int], | |
| ) -> ObjectDictionary: |
| try: | ||
| od.node_id = int(node_id, 0) | ||
| except (ValueError, TypeError): | ||
| pass |
|
|
||
| return od |
There was a problem hiding this comment.
| return od | |
| return od | |
|
|
||
| return od | ||
|
|
||
| def _add_device_information_to_od(od, root): |
There was a problem hiding this comment.
| def _add_device_information_to_od(od, root): | |
| def _add_device_information(od: ObjectDictionary, root: etree.Element): |
Keep the names slightly shorter, it's all already in the context of the OD.
| device_identity = root.find('.//{*}DeviceIdentity') | ||
| if device_identity is not None: | ||
| for src_prop, dst_prop, f in [ | ||
| ("vendorName", "vendor_name", lambda val: str(val)), |
There was a problem hiding this comment.
| ("vendorName", "vendor_name", lambda val: str(val)), | |
| ("vendorName", "vendor_name", str), |
This can be simplified in many places, no need for a lambda.
| if device_identity is not None: | ||
| for src_prop, dst_prop, f in [ | ||
| ("vendorName", "vendor_name", lambda val: str(val)), | ||
| ("vendorID", "vendor_number", lambda val: int(val, 0)), |
There was a problem hiding this comment.
You could create a autoint = functools.partial(int, base=0) constructor once in this module, then use it to simplify in these cases.
Hi All,
This is a WIP merge request that adds support for XDD import to CANopen. I'm still in the process of testing and making improvements, but I’d appreciate any feedback you might have in the meantime.
Feel free to share any questions or suggestions.
Best regards,
Taras