Skip to content

Commit

Permalink
ParentRef: do not rely on the xsi:type attribute to determine the k…
Browse files Browse the repository at this point in the history
…ind of parent layer

this basically means the specialized PARENT-REFs (i.e.,
BASE-VARIANT-REF, PROTOCOL-REF, etc.) are kind of useless in the spec.

thanks to [at]kayoub5 for wondering about this!

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Gerrit Ecke <gerrit.ecke@mbition.io>
  • Loading branch information
andlaus committed Jun 5, 2023
1 parent e7a3652 commit 1a204e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
2 changes: 0 additions & 2 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,6 @@ def extract_constant_bytes(params):
parent_refs=[
ParentRef(
parent_layer_ref=OdxLinkRef.from_id(somersault_diaglayer.odx_id),
parent_layer_type=DiagLayerType.BASE_VARIANT,
# this variant does not do backflips
not_inherited_diag_comms=[
somersault_requests["backward_flips"].short_name,
Expand Down Expand Up @@ -2011,7 +2010,6 @@ def extract_constant_bytes(params):
parent_refs=[
ParentRef(
parent_layer_ref=OdxLinkRef.from_id(somersault_diaglayer.odx_id),
parent_layer_type=DiagLayerType.BASE_VARIANT,
# this variant does everything which the base variant does
not_inherited_diag_comms=[],
not_inherited_dops=[],
Expand Down
16 changes: 4 additions & 12 deletions odxtools/parentref.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@dataclass
class ParentRef:
parent_layer_ref: OdxLinkRef
parent_layer_type: DiagLayerType
not_inherited_diag_comms: List[str] # short_name references
not_inherited_variables: List[str] # short_name references
not_inherited_dops: List[str] # short_name references
Expand All @@ -27,6 +26,10 @@ class ParentRef:
def parent_layer(self) -> "DiagLayer":
return self._parent_layer

@property
def parent_layer_type(self) -> DiagLayerType:
return self._parent_layer.variant_type

@staticmethod
def from_et(et_element, doc_frags: List[OdxDocFragment]) -> "ParentRef":

Expand Down Expand Up @@ -60,16 +63,8 @@ def from_et(et_element, doc_frags: List[OdxDocFragment]) -> "ParentRef":
"GLOBAL-NEG-RESPONSE-SNREF")
]

# determine the type of the referenced diag layer. for
# this, we need to strip the '-REF' suffix of the
# element's {xsi}type attribute
parent_layer_type_str = et_element.get(f"{xsi}type")
assert parent_layer_type_str is not None and parent_layer_type_str.endswith("-REF")
parent_layer_type = DiagLayerType(parent_layer_type_str[:-4])

return ParentRef(
parent_layer_ref=parent_layer_ref,
parent_layer_type=DiagLayerType(parent_layer_type),
not_inherited_diag_comms=not_inherited_diag_comms,
not_inherited_variables=not_inherited_variables,
not_inherited_dops=not_inherited_dops,
Expand All @@ -83,9 +78,6 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
def _resolve_references(self, odxlinks: OdxLinkDatabase) -> None:
self._parent_layer = odxlinks.resolve(self.parent_layer_ref)

assert self._parent_layer.variant_type == self.parent_layer_type, \
"Incorrect PARENT-REF"

def get_inherited_services(self) -> List[Union[DiagService, SingleEcuJob]]:
if self.parent_layer is None:
return []
Expand Down

0 comments on commit 1a204e3

Please sign in to comment.