Skip to content

Commit

Permalink
DiagLayer: always provide .diag_data_dictionary_spec in non-raw dia…
Browse files Browse the repository at this point in the history
…g layers

If the underlying raw layer does not provide a DDDS, and inheritance
does not apply either, an empty object is created. This should help to
avoid having to handle a few special cases in user code.

Thanks to [at]kayoub for the catch!

Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
Signed-off-by: Florian Jost <florian.jost@mbition.io>
  • Loading branch information
andlaus committed Aug 5, 2024
1 parent 0f9e950 commit d15213b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions odxtools/diaglayers/diaglayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) ->
# Create DiagLayer
return DiagLayer(diag_layer_raw=diag_layer_raw)

def __post_init__(self) -> None:
if self.diag_layer_raw.diag_data_dictionary_spec is None:
# create an empry DiagDataDictionarySpec object if the raw
# layer does not define a DDDS...
self._diag_data_dictionary_spec = DiagDataDictionarySpec(
admin_data=None,
data_object_props=NamedItemList(),
dtc_dops=NamedItemList(),
structures=NamedItemList(),
static_fields=NamedItemList(),
end_of_pdu_fields=NamedItemList(),
dynamic_endmarker_fields=NamedItemList(),
dynamic_length_fields=NamedItemList(),
tables=NamedItemList(),
env_data_descs=NamedItemList(),
env_datas=NamedItemList(),
muxs=NamedItemList(),
unit_spec=None,
sdgs=[])
else:
self._diag_data_dictionary_spec = self.diag_layer_raw.diag_data_dictionary_spec

def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
"""Construct a mapping from IDs to all objects that are contained in this diagnostic layer."""
result = self.diag_layer_raw._build_odxlinks()
Expand Down Expand Up @@ -242,9 +264,9 @@ def sdgs(self) -> List[SpecialDataGroup]:
return self.diag_layer_raw.sdgs

@property
def diag_data_dictionary_spec(self) -> Optional[DiagDataDictionarySpec]:
def diag_data_dictionary_spec(self) -> DiagDataDictionarySpec:
"""The DiagDataDictionarySpec applicable to this DiagLayer"""
return self.diag_layer_raw.diag_data_dictionary_spec
return self._diag_data_dictionary_spec

#####
# </properties forwarded to the "raw" diag layer>
Expand Down
2 changes: 1 addition & 1 deletion odxtools/diaglayers/hierarchyelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def not_inherited_fn(parent_ref: ParentRef) -> List[str]:
# <properties subject to value inheritance>
#######
@property
def diag_data_dictionary_spec(self) -> Optional[DiagDataDictionarySpec]:
def diag_data_dictionary_spec(self) -> DiagDataDictionarySpec:
return self._diag_data_dictionary_spec

@property
Expand Down

0 comments on commit d15213b

Please sign in to comment.