-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from andlaus/base_variant_patterns
Implement base variant patterns
- Loading branch information
Showing
21 changed files
with
1,560 additions
and
796 deletions.
There are no files selected for viewing
This file contains 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 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,38 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import List, Union | ||
from xml.etree import ElementTree | ||
|
||
from typing_extensions import override | ||
|
||
from .exceptions import odxassert | ||
from .matchingbasevariantparameter import MatchingBaseVariantParameter | ||
from .matchingparameter import MatchingParameter | ||
from .odxlink import OdxDocFragment | ||
from .variantpattern import VariantPattern | ||
|
||
|
||
@dataclass | ||
class BaseVariantPattern(VariantPattern): | ||
"""Base variant patterns are variant patterns used to identify the | ||
base variant of an ECU. | ||
""" | ||
matching_base_variant_parameters: List[MatchingBaseVariantParameter] | ||
|
||
@override | ||
def get_matching_parameters( | ||
self) -> Union[List[MatchingParameter], List[MatchingBaseVariantParameter]]: | ||
return self.matching_base_variant_parameters | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, | ||
doc_frags: List[OdxDocFragment]) -> "BaseVariantPattern": | ||
|
||
matching_base_variant_parameters = [ | ||
MatchingBaseVariantParameter.from_et(mbvp_el, doc_frags) | ||
for mbvp_el in et_element.iterfind("MATCHING-BASE-VARIANT-PARAMETERS/" | ||
"MATCHING-BASE-VARIANT-PARAMETER") | ||
] | ||
|
||
odxassert(len(matching_base_variant_parameters) > 0) # required by ISO 22901-1 Figure 141 | ||
return BaseVariantPattern(matching_base_variant_parameters=matching_base_variant_parameters) |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,27 +1,38 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import List | ||
from typing import List, Union | ||
from xml.etree import ElementTree | ||
|
||
from .exceptions import odxassert, odxrequire | ||
from typing_extensions import override | ||
|
||
from .exceptions import odxassert | ||
from .matchingbasevariantparameter import MatchingBaseVariantParameter | ||
from .matchingparameter import MatchingParameter | ||
from .odxlink import OdxDocFragment | ||
from .variantpattern import VariantPattern | ||
|
||
|
||
@dataclass | ||
class EcuVariantPattern: | ||
class EcuVariantPattern(VariantPattern): | ||
"""ECU variant patterns are variant patterns used to identify the | ||
concrete variant of an ECU. | ||
""" | ||
matching_parameters: List[MatchingParameter] | ||
|
||
@override | ||
def get_matching_parameters( | ||
self) -> Union[List[MatchingParameter], List[MatchingBaseVariantParameter]]: | ||
return self.matching_parameters | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, | ||
doc_frags: List[OdxDocFragment]) -> "EcuVariantPattern": | ||
|
||
mp_collection_el = odxrequire(et_element.find("MATCHING-PARAMETERS")) | ||
|
||
matching_params = [ | ||
matching_parameters = [ | ||
MatchingParameter.from_et(mp_el, doc_frags) | ||
for mp_el in mp_collection_el.iterfind("MATCHING-PARAMETER") | ||
for mp_el in et_element.iterfind("MATCHING-PARAMETERS/" | ||
"MATCHING-PARAMETER") | ||
] | ||
|
||
odxassert(len(matching_params) > 0) # required by ISO 22901-1 Figure 141 | ||
return EcuVariantPattern(matching_params) | ||
odxassert(len(matching_parameters) > 0) # required by ISO 22901-1 Figure 141 | ||
return EcuVariantPattern(matching_parameters=matching_parameters) |
Oops, something went wrong.