-
Notifications
You must be signed in to change notification settings - Fork 81
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 #238 from rivian/protstack-and-comparamspec-support
Add support for ProtStack and ComparamSpec
- Loading branch information
Showing
16 changed files
with
320 additions
and
31 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,94 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional | ||
from xml.etree import ElementTree | ||
|
||
from .admindata import AdminData | ||
from .companydata import CompanyData | ||
from .createcompanydatas import create_company_datas_from_et | ||
from .createsdgs import create_sdgs_from_et | ||
from .element import IdentifiableElement | ||
from .exceptions import odxrequire | ||
from .nameditemlist import NamedItemList | ||
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId | ||
from .protstack import ProtStack | ||
from .specialdatagroup import SpecialDataGroup | ||
from .utils import dataclass_fields_asdict | ||
|
||
if TYPE_CHECKING: | ||
from .diaglayer import DiagLayer | ||
|
||
|
||
@dataclass | ||
class ComparamSpec(IdentifiableElement): | ||
admin_data: Optional[AdminData] | ||
company_datas: NamedItemList[CompanyData] | ||
sdgs: List[SpecialDataGroup] | ||
prot_stacks: NamedItemList[ProtStack] | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) -> "ComparamSpec": | ||
|
||
short_name = odxrequire(et_element.findtext("SHORT-NAME")) | ||
doc_frags = [OdxDocFragment(short_name, str(et_element.tag))] | ||
kwargs = dataclass_fields_asdict(IdentifiableElement.from_et(et_element, doc_frags)) | ||
|
||
admin_data = AdminData.from_et(et_element.find("ADMIN-DATA"), doc_frags) | ||
company_datas = create_company_datas_from_et(et_element.find("COMPANY-DATAS"), doc_frags) | ||
sdgs = create_sdgs_from_et(et_element.find("SDGS"), doc_frags) | ||
prot_stacks = NamedItemList([ | ||
ProtStack.from_et(dl_element, doc_frags) | ||
for dl_element in et_element.iterfind("PROT-STACKS/PROT-STACK") | ||
]) | ||
|
||
return ComparamSpec( | ||
admin_data=admin_data, | ||
company_datas=company_datas, | ||
sdgs=sdgs, | ||
prot_stacks=prot_stacks, | ||
**kwargs) | ||
|
||
def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: | ||
odxlinks: Dict[OdxLinkId, Any] = {} | ||
if self.odx_id is not None: | ||
odxlinks[self.odx_id] = self | ||
|
||
if self.admin_data is not None: | ||
odxlinks.update(self.admin_data._build_odxlinks()) | ||
|
||
for cd in self.company_datas: | ||
odxlinks.update(cd._build_odxlinks()) | ||
|
||
for sdg in self.sdgs: | ||
odxlinks.update(sdg._build_odxlinks()) | ||
|
||
for ps in self.prot_stacks: | ||
odxlinks.update(ps._build_odxlinks()) | ||
|
||
return odxlinks | ||
|
||
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: | ||
if self.admin_data is not None: | ||
self.admin_data._resolve_odxlinks(odxlinks) | ||
|
||
for cd in self.company_datas: | ||
cd._resolve_odxlinks(odxlinks) | ||
|
||
for sdg in self.sdgs: | ||
sdg._resolve_odxlinks(odxlinks) | ||
|
||
for ps in self.prot_stacks: | ||
ps._resolve_odxlinks(odxlinks) | ||
|
||
def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None: | ||
if self.admin_data is not None: | ||
self.admin_data._resolve_snrefs(diag_layer) | ||
|
||
for cd in self.company_datas: | ||
cd._resolve_snrefs(diag_layer) | ||
|
||
for sdg in self.sdgs: | ||
sdg._resolve_snrefs(diag_layer) | ||
|
||
for ps in self.prot_stacks: | ||
ps._resolve_snrefs(diag_layer) |
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 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,51 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Any, Dict, List | ||
from xml.etree import ElementTree | ||
|
||
from .comparamsubset import ComparamSubset | ||
from .element import IdentifiableElement | ||
from .exceptions import odxrequire | ||
from .nameditemlist import NamedItemList | ||
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef | ||
from .utils import dataclass_fields_asdict | ||
|
||
if TYPE_CHECKING: | ||
from .diaglayer import DiagLayer | ||
|
||
|
||
@dataclass | ||
class ProtStack(IdentifiableElement): | ||
# mandatory in ODX 2.2, but non existent in ODX 2.0 | ||
pdu_protocol_type: str | ||
physical_link_type: str | ||
comparam_subset_refs: List[OdxLinkRef] | ||
|
||
@staticmethod | ||
def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) -> "ProtStack": | ||
kwargs = dataclass_fields_asdict(IdentifiableElement.from_et(et_element, doc_frags)) | ||
|
||
pdu_protocol_type = odxrequire(et_element.findtext("PDU-PROTOCOL-TYPE")) | ||
physical_link_type = odxrequire(et_element.findtext("PHYSICAL-LINK-TYPE")) | ||
comparam_subset_refs = [ | ||
OdxLinkRef.from_et(csr_element, doc_frags) | ||
for csr_element in et_element.iterfind("COMPARAM-SUBSET-REFS/" | ||
"COMPARAM-SUBSET-REF") | ||
] | ||
|
||
return ProtStack( | ||
pdu_protocol_type=pdu_protocol_type, | ||
physical_link_type=physical_link_type, | ||
comparam_subset_refs=comparam_subset_refs, | ||
**kwargs) | ||
|
||
def _build_odxlinks(self) -> Dict[OdxLinkId, Any]: | ||
result = {self.odx_id: self} | ||
return result | ||
|
||
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None: | ||
self._comparam_subsets = NamedItemList[ComparamSubset]( | ||
[odxlinks.resolve(x, ComparamSubset) for x in self.comparam_subset_refs]) | ||
|
||
def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None: | ||
pass |
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,45 @@ | ||
{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*- | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# This template writes an .odx-cs file for a communication | ||
# parameter subset. | ||
-#} | ||
{%- import('macros/printAdminData.xml.jinja2') as pad -%} | ||
{%- import('macros/printCompanyData.xml.jinja2') as pcd -%} | ||
{%- import('macros/printProtStack.xml.jinja2') as pps %} | ||
{#- -#} | ||
|
||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
<ODX MODEL-VERSION="2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="odx.xsd"> | ||
<!-- Written using odxtools {{odxtools_version}} --> | ||
<COMPARAM-SPEC ID="{{comparam_spec.odx_id.local_id}}"> | ||
<SHORT-NAME>{{comparam_spec.short_name}}</SHORT-NAME> | ||
{%- if comparam_spec.long_name is not none %} | ||
<LONG-NAME>{{comparam_spec.long_name|e}}</LONG-NAME> | ||
{%- endif %} | ||
{%- if comparam_spec.description and comparam_spec.description.strip() %} | ||
<DESC> | ||
{{comparam_spec.description}} | ||
</DESC> | ||
{%- endif %} | ||
{%- if comparam_spec.admin_data is not none %} | ||
{{- pad.printAdminData(comparam_spec.admin_data) | indent(3) }} | ||
{%- endif %} | ||
{%- if comparam_spec.company_datas %} | ||
<COMPANY-DATAS> | ||
{%- for cd in comparam_spec.company_datas %} | ||
{{- pcd.printCompanyData(cd) | indent(5) -}} | ||
{%- endfor %} | ||
</COMPANY-DATAS> | ||
{%- endif %} | ||
|
||
{%- if comparam_spec.prot_stacks %} | ||
<PROT-STACKS> | ||
{%- for ps in comparam_spec.prot_stacks %} | ||
{{- pps.printProtStack(ps) | indent(5) -}} | ||
{%- endfor %} | ||
</PROT-STACKS> | ||
{%- endif %} | ||
</COMPARAM-SPEC> | ||
</ODX> |
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,22 @@ | ||
{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*- | ||
# | ||
# SPDX-License-Identifier: MIT | ||
-#} | ||
|
||
{%- import('macros/printElementID.xml.jinja2') as peid %} | ||
{%- import('macros/printSpecialData.xml.jinja2') as psd %} | ||
|
||
{%- macro printProtStack(ps) %} | ||
<PROT-STACK ID="{{ps.odx_id.local_id}}"> | ||
{{ peid.printElementID(ps) | indent(1) }} | ||
<PDU-PROTOCOL-TYPE>{{ ps.pdu_protocol_type }}</PDU-PROTOCOL-TYPE> | ||
<PHYSICAL-LINK-TYPE>{{ ps.physical_link_type }}</PHYSICAL-LINK-TYPE> | ||
{%- if ps.comparam_subset_refs %} | ||
<COMPARAM-SUBSET-REFS> | ||
{%- for csr in ps.comparam_subset_refs %} | ||
<COMPARAM-SUBSET-REF ID-REF="{{csr.ref_id}}" DOCREF="{{csr.ref_id}}" DOCTYPE="COMPARAM-SUBSET"/> | ||
{%- endfor %} | ||
</COMPARAM-SUBSET-REFS> | ||
{%- endif %} | ||
</PROT-STACK> | ||
{%- endmacro %} |
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
Oops, something went wrong.