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
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.
canopen/objectdictionary/xdd.py
Outdated
|
|
||
| import re | ||
| import xml.etree.ElementTree as etree | ||
| from configparser import NoOptionError |
canopen/objectdictionary/xdd.py
Outdated
| @@ -0,0 +1,306 @@ | |||
| import logging | |||
|
|
|||
canopen/objectdictionary/xdd.py
Outdated
| 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 |
canopen/objectdictionary/xdd.py
Outdated
| if TYPE_CHECKING: | ||
| import canopen.network |
There was a problem hiding this comment.
| if TYPE_CHECKING: | |
| import canopen.network |
canopen/objectdictionary/xdd.py
Outdated
| 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: |
canopen/objectdictionary/xdd.py
Outdated
| try: | ||
| od.node_id = int(node_id, 0) | ||
| except (ValueError, TypeError): | ||
| pass |
canopen/objectdictionary/xdd.py
Outdated
|
|
||
| return od |
There was a problem hiding this comment.
| return od | |
| return od | |
canopen/objectdictionary/xdd.py
Outdated
|
|
||
| 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.
canopen/objectdictionary/xdd.py
Outdated
| 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.
canopen/objectdictionary/xdd.py
Outdated
| 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 @zaporozhets, thanks for the work on this PR! Are you still planning to continue with it? I have a project where I could really use xdd/xdc parsing right now, so I'd be glad to pick up where you left off and contribute to this effort if you don't have the bandwidth. |
|
@acolomb, thank you for the review, and @tomasbarton-stemcell for your interest in this feature. I was extremely busy last year and didn’t have the chance to address all the comments. I’m currently on sick leave until Monday, so I finally have some time to catch up. Please give me a few days to refresh my memory and go through all the suggestions. I’ll keep you posted. I’ll definitely appreciate a thorough review here, as Python isn’t really my main area of expertise. BR, |
bc0551f to
3070327
Compare
Signed-off-by: Taras Zaporozhets <[email protected]>
3070327 to
47656be
Compare
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