-
Notifications
You must be signed in to change notification settings - Fork 354
Custom Options for EDS file #615
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -209,6 +209,8 @@ def __init__(self, name: str, index: int): | |||||
| self.storage_location = None | ||||||
| self.subindices = {} | ||||||
| self.names = {} | ||||||
| #: Key-Value pairs not defined by the standard | ||||||
| self.custom_options = {} | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For new code, we require proper typing hints now, to avoid an ever-growing error list from the mypy checker. (Same thing below.)
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always copy the format of existing code. |
||||||
|
|
||||||
| def __repr__(self) -> str: | ||||||
| return f"<{type(self).__qualname__} {self.name!r} at {pretty_index(self.index)}>" | ||||||
|
|
@@ -268,6 +270,8 @@ def __init__(self, name: str, index: int): | |||||
| self.storage_location = None | ||||||
| self.subindices = {} | ||||||
| self.names = {} | ||||||
| #: Key-Value pairs not defined by the standard | ||||||
| self.custom_options = {} | ||||||
|
|
||||||
| def __repr__(self) -> str: | ||||||
| return f"<{type(self).__qualname__} {self.name!r} at {pretty_index(self.index)}>" | ||||||
|
|
@@ -374,6 +378,8 @@ def __init__(self, name: str, index: int, subindex: int = 0): | |||||
| self.storage_location = None | ||||||
| #: Can this variable be mapped to a PDO | ||||||
| self.pdo_mappable = False | ||||||
| #: Key-Value pairs not defined by the standard | ||||||
| self.custom_options = {} | ||||||
|
|
||||||
| def __repr__(self) -> str: | ||||||
| subindex = self.subindex if isinstance(self.parent, (ODRecord, ODArray)) else None | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -140,14 +140,17 @@ def import_eds(source, node_id): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.add_member(last_subindex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.add_member(build_variable(eds, section, node_id, index, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.storage_location = storage_location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.custom_options = _get_custom_options(eds, section) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| od.add_object(arr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif object_type == ARR: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr = objectdictionary.ODArray(name, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.storage_location = storage_location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arr.custom_options = _get_custom_options(eds, section) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| od.add_object(arr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif object_type == RECORD: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| record = objectdictionary.ODRecord(name, index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| record.storage_location = storage_location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| record.custom_options = _get_custom_options(eds, section) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| od.add_object(record) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -253,6 +256,19 @@ def _revert_variable(var_type, value): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"0x{value:02X}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _STANDARD_OPTIONS = ["objecttype" , "parametername" , "datatype" , "accesstype" , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "pdomapping" , "lowlimit" , "highlimit" , "defaultvalue" , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "parametervalue" , "factor" , "description" , "unit" , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "storagelocation" , "compactsubobj" , "nrofentries" , "subnumber" , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "objflags" , "denotation" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+259
to
+264
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is definitely funky formatting. We mostly follow "black" style, though not strictly enforded. A simple list, one item per row, would be fine here, however. Makes it easier to insert grouping comments. As for the name, I think This would be my approach, sorted as in CiA 306:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _get_custom_options(eds, section): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hints, please, for new code. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_options = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for option, value in eds.items(section): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not (option.lower() in _STANDARD_OPTIONS or option.isdigit()) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please pay attention to code formatting. The space before Same thing with the number of blank lines between top-level definitions, btw. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_options[option] = value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole function would be a good candidate for a dict comprehension instead of an explicit loop.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be too complicated/long: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return custom_options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def build_variable(eds, section, node_id, index, subindex=0): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Creates a object dictionary entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -332,6 +348,8 @@ def build_variable(eds, section, node_id, index, subindex=0): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var.unit = eds.get(section, "Unit") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ValueError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var.custom_options = _get_custom_options(eds, section) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -406,12 +424,17 @@ def export_variable(var, eds): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if getattr(var, 'unit', '') != '': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eds.set(section, "Unit", var.unit) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for option, value in var.custom_options.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eds.set(section, option, value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def export_record(var, eds): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| section = f"{var.index:04X}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export_common(var, eds, section) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eds.set(section, "SubNumber", f"0x{len(var.subindices):X}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ot = RECORD if isinstance(var, objectdictionary.ODRecord) else ARR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eds.set(section, "ObjectType", f"0x{ot:X}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for option, value in var.custom_options.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eds.set(section, option, value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in var: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export_variable(var[i], eds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
The library already uses some nonstandard options, so the description is a bit misleading. We should call them "not handled explicitly" instead.