-
Notifications
You must be signed in to change notification settings - Fork 214
xdd: Implement option to load object dictionary from XDD file. #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a leftover from eds?
| @@ -0,0 +1,306 @@ | |||
| import logging | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import re | ||
| import xml.etree.ElementTree as etree | ||
| from configparser import NoOptionError | ||
| from typing import TYPE_CHECKING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from typing import TYPE_CHECKING |
| if TYPE_CHECKING: | ||
| import canopen.network |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if TYPE_CHECKING: | |
| import canopen.network |
| RECORD = 9 | ||
|
|
||
|
|
||
| def import_xdd(xdd, node_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No logging of this failure?
|
|
||
| return od |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return od | |
| return od | |
|
|
||
| return od | ||
|
|
||
| def _add_device_information_to_od(od, root): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ("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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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