-
Notifications
You must be signed in to change notification settings - Fork 93
Implement the ECU-CONFIG category #428
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf267bd
`.odx-e`: implement support for the ECU-CONFIG category (`.odx-e`)
andlaus 243783d
`.odx-e`: work around some Mercedes-specific issues
andlaus ea1766a
`.odx-e`: ECU-CONFIG: add unit test
andlaus 83c036d
`.odx-e`: add output writing code for the ECU-CONFIG category
andlaus b15c00f
provide the data specified by flashdata and data-record
andlaus b7f38e7
make mypy 1.16.0 happy
andlaus b5e6635
remove some commented out code
andlaus aa5e9ec
Use the 'bincopy' python python module to handle MOTOROLA-S and INTEL…
andlaus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass, field | ||
from typing import Any | ||
from xml.etree import ElementTree | ||
|
||
from .configrecord import ConfigRecord | ||
from .element import NamedElement | ||
from .nameditemlist import NamedItemList | ||
from .odxdoccontext import OdxDocContext | ||
from .odxlink import OdxLinkDatabase, OdxLinkId | ||
from .snrefcontext import SnRefContext | ||
from .specialdatagroup import SpecialDataGroup | ||
from .utils import dataclass_fields_asdict | ||
from .validbasevariant import ValidBaseVariant | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ConfigData(NamedElement): | ||
"""This class represents a CONFIG-DATA.""" | ||
valid_base_variants: list[ValidBaseVariant] | ||
config_records: NamedItemList[ConfigRecord] | ||
sdgs: list[SpecialDataGroup] = field(default_factory=list) | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "ConfigData": | ||
kwargs = dataclass_fields_asdict(NamedElement.from_et(et_element, context)) | ||
|
||
valid_base_variants = [ | ||
ValidBaseVariant.from_et(vbv_elem, context) | ||
for vbv_elem in et_element.iterfind("VALID-BASE-VARIANTS/VALID-BASE-VARIANT") | ||
] | ||
config_records = NamedItemList([ | ||
ConfigRecord.from_et(cr_elem, context) | ||
for cr_elem in et_element.iterfind("CONFIG-RECORDS/CONFIG-RECORD") | ||
]) | ||
sdgs = [SpecialDataGroup.from_et(sdge, context) for sdge in et_element.iterfind("SDGS/SDG")] | ||
|
||
return ConfigData( | ||
valid_base_variants=valid_base_variants, | ||
config_records=config_records, | ||
sdgs=sdgs, | ||
**kwargs) | ||
|
||
def _build_odxlinks(self) -> dict[OdxLinkId, Any]: | ||
result = {} | ||
|
||
for valid_base_variant in self.valid_base_variants: | ||
result.update(valid_base_variant._build_odxlinks()) | ||
for config_record in self.config_records: | ||
result.update(config_record._build_odxlinks()) | ||
for sdg in self.sdgs: | ||
result.update(sdg._build_odxlinks()) | ||
|
||
return result | ||
|
||
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: | ||
for valid_base_variant in self.valid_base_variants: | ||
valid_base_variant._resolve_odxlinks(odxlinks) | ||
for config_record in self.config_records: | ||
config_record._resolve_odxlinks(odxlinks) | ||
for sdg in self.sdgs: | ||
sdg._resolve_odxlinks(odxlinks) | ||
|
||
def _resolve_snrefs(self, context: SnRefContext) -> None: | ||
for valid_base_variant in self.valid_base_variants: | ||
valid_base_variant._resolve_snrefs(context) | ||
for config_record in self.config_records: | ||
config_record._resolve_snrefs(context) | ||
for sdg in self.sdgs: | ||
sdg._resolve_snrefs(context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass, field | ||
from typing import Any | ||
from xml.etree import ElementTree | ||
|
||
from .dataobjectproperty import DataObjectProperty | ||
from .nameditemlist import NamedItemList | ||
from .odxdoccontext import OdxDocContext | ||
from .odxlink import OdxLinkDatabase, OdxLinkId | ||
from .snrefcontext import SnRefContext | ||
from .unitspec import UnitSpec | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ConfigDataDictionarySpec: | ||
data_object_props: NamedItemList[DataObjectProperty] = field(default_factory=NamedItemList) | ||
unit_spec: UnitSpec | None = None | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, | ||
context: OdxDocContext) -> "ConfigDataDictionarySpec": | ||
data_object_props = NamedItemList([ | ||
DataObjectProperty.from_et(dop_element, context) | ||
for dop_element in et_element.iterfind("DATA-OBJECT-PROPS/DATA-OBJECT-PROP") | ||
]) | ||
|
||
if (spec_elem := et_element.find("UNIT-SPEC")) is not None: | ||
unit_spec = UnitSpec.from_et(spec_elem, context) | ||
else: | ||
unit_spec = None | ||
|
||
return ConfigDataDictionarySpec( | ||
data_object_props=data_object_props, | ||
unit_spec=unit_spec, | ||
) | ||
|
||
def _build_odxlinks(self) -> dict[OdxLinkId, Any]: | ||
odxlinks = {} | ||
|
||
for data_object_prop in self.data_object_props: | ||
odxlinks.update(data_object_prop._build_odxlinks()) | ||
if self.unit_spec is not None: | ||
odxlinks.update(self.unit_spec._build_odxlinks()) | ||
|
||
return odxlinks | ||
|
||
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: | ||
for data_object_prop in self.data_object_props: | ||
data_object_prop._resolve_odxlinks(odxlinks) | ||
if self.unit_spec is not None: | ||
self.unit_spec._resolve_odxlinks(odxlinks) | ||
|
||
def _resolve_snrefs(self, context: SnRefContext) -> None: | ||
for data_object_prop in self.data_object_props: | ||
data_object_prop._resolve_snrefs(context) | ||
if self.unit_spec is not None: | ||
self.unit_spec._resolve_snrefs(context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from xml.etree import ElementTree | ||
|
||
from .configitem import ConfigItem | ||
from .odxdoccontext import OdxDocContext | ||
from .utils import dataclass_fields_asdict | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ConfigIdItem(ConfigItem): | ||
"""This class represents a CONFIG-ID-ITEM.""" | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "ConfigIdItem": | ||
kwargs = dataclass_fields_asdict(ConfigItem.from_et(et_element, context)) | ||
|
||
return ConfigIdItem(**kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass, field | ||
from typing import Any | ||
from xml.etree import ElementTree | ||
|
||
from .dopbase import DopBase | ||
from .element import NamedElement | ||
from .exceptions import odxrequire | ||
from .odxdoccontext import OdxDocContext | ||
from .odxlink import OdxLinkDatabase, OdxLinkId, OdxLinkRef, resolve_snref | ||
from .snrefcontext import SnRefContext | ||
from .specialdatagroup import SpecialDataGroup | ||
from .utils import dataclass_fields_asdict | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class ConfigItem(NamedElement): | ||
"""This class represents a CONFIG-ITEM. | ||
|
||
CONFIG-ITEM is the base class for CONFIG-ID-ITEM, DATA-ID-ITEM, | ||
OPTION-ITEM, and SYSTEM-ITEM. | ||
""" | ||
byte_position: int | None = None | ||
bit_position: int | None = None | ||
|
||
# according to the spec exactly one of the following two | ||
# attributes is not None...x | ||
data_object_prop_ref: OdxLinkRef | None = None | ||
data_object_prop_snref: str | None = None | ||
sdgs: list[SpecialDataGroup] = field(default_factory=list) | ||
|
||
@property | ||
def data_object_prop(self) -> DopBase: | ||
return self._data_object_prop | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, context: OdxDocContext) -> "ConfigItem": | ||
kwargs = dataclass_fields_asdict(NamedElement.from_et(et_element, context)) | ||
|
||
byte_position = None | ||
if (byte_pos_elem := et_element.findtext("BYTE-POSITION")) is not None: | ||
byte_position = int(byte_pos_elem) | ||
|
||
bit_position = None | ||
if (bit_pos_elem := et_element.findtext("BIT-POSITION")) is not None: | ||
bit_position = int(bit_pos_elem) | ||
|
||
data_object_prop_ref = OdxLinkRef.from_et(et_element.find("DATA-OBJECT-PROP-REF"), context) | ||
data_object_prop_snref = None | ||
if (data_object_prop_snref_elem := et_element.find("DATA-OBJECT-PROP-SNREF")) is not None: | ||
data_object_prop_snref = odxrequire( | ||
data_object_prop_snref_elem.attrib.get("SHORT-NAME")) | ||
sdgs = [SpecialDataGroup.from_et(sdge, context) for sdge in et_element.iterfind("SDGS/SDG")] | ||
|
||
return ConfigItem( | ||
byte_position=byte_position, | ||
bit_position=bit_position, | ||
data_object_prop_ref=data_object_prop_ref, | ||
data_object_prop_snref=data_object_prop_snref, | ||
sdgs=sdgs, | ||
**kwargs) | ||
|
||
def _build_odxlinks(self) -> dict[OdxLinkId, Any]: | ||
result = {} | ||
|
||
for sdg in self.sdgs: | ||
result.update(sdg._build_odxlinks()) | ||
|
||
return result | ||
|
||
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: | ||
if self.data_object_prop_ref is not None: | ||
self._data_object_prop = odxlinks.resolve(self.data_object_prop_ref, DopBase) | ||
|
||
for sdg in self.sdgs: | ||
sdg._resolve_odxlinks(odxlinks) | ||
|
||
def _resolve_snrefs(self, context: SnRefContext) -> None: | ||
if self.data_object_prop_snref is not None: | ||
ddds = odxrequire(context.diag_layer).diag_data_dictionary_spec | ||
self._data_object_prop = resolve_snref(self.data_object_prop_snref, | ||
ddds.all_data_object_properties, DopBase) | ||
|
||
for sdg in self.sdgs: | ||
sdg._resolve_snrefs(context) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.