Skip to content

Commit

Permalink
Implement NvDataInterface and ParameterInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
cogu committed Jan 30, 2024
1 parent 54316e0 commit 4b0fd0d
Show file tree
Hide file tree
Showing 14 changed files with 1,032 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ Non-collectable elements are various sub-elements to collectable elements.

#### XML Port interface elements

* NvDataInterface | NV-DATA-INTERFACE | `collectable`
* ParameterInterface | PARAMETER-INTERFACE | `collectable`
* SenderReceiverInterface | SENDER-RECEIVER-INTERFACE | `collectable`
* InvalidationPolicy | INVALIDATION-POLICY

#### XML - Data type elements

* ParameterDataPrototype | PARAMETER-DATA-PROTOTYPE
* VariableDataPrototype | VARIABLE-DATA-PROTOTYPE

## [v0.5.1] - 2023-11-09
Expand Down
26 changes: 26 additions & 0 deletions examples/xml/port_interface/data/datatypes.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>DataTypes</SHORT-NAME>
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>ImplementationDataTypes</SHORT-NAME>
<ELEMENTS>
<IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>InactiveActive_T</SHORT-NAME>
<CATEGORY>VALUE</CATEGORY>
<SW-DATA-DEF-PROPS>
<SW-DATA-DEF-PROPS-VARIANTS>
<SW-DATA-DEF-PROPS-CONDITIONAL>
<BASE-TYPE-REF DEST="SW-BASE-TYPE">AUTOSAR_Platform/BaseTypes/uint8</BASE-TYPE-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
32 changes: 32 additions & 0 deletions examples/xml/port_interface/data/nv_data_interface.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>PortInterfaces</SHORT-NAME>
<ELEMENTS>
<NV-DATA-INTERFACE>
<SHORT-NAME>DataInterface1</SHORT-NAME>
<NV-DATAS>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>Data1</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
</NV-DATAS>
</NV-DATA-INTERFACE>
<NV-DATA-INTERFACE>
<SHORT-NAME>DataInterface2</SHORT-NAME>
<NV-DATAS>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>Data1</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>Data2</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
</NV-DATAS>
</NV-DATA-INTERFACE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
32 changes: 32 additions & 0 deletions examples/xml/port_interface/data/parameter_interface.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>PortInterfaces</SHORT-NAME>
<ELEMENTS>
<PARAMETER-INTERFACE>
<SHORT-NAME>ParameterInterface1</SHORT-NAME>
<PARAMETERS>
<PARAMETER-DATA-PROTOTYPE>
<SHORT-NAME>Param1</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</PARAMETER-DATA-PROTOTYPE>
</PARAMETERS>
</PARAMETER-INTERFACE>
<PARAMETER-INTERFACE>
<SHORT-NAME>ParameterInterface2</SHORT-NAME>
<PARAMETERS>
<PARAMETER-DATA-PROTOTYPE>
<SHORT-NAME>Param1</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</PARAMETER-DATA-PROTOTYPE>
<PARAMETER-DATA-PROTOTYPE>
<SHORT-NAME>Param2</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint8</TYPE-TREF>
</PARAMETER-DATA-PROTOTYPE>
</PARAMETERS>
</PARAMETER-INTERFACE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
35 changes: 35 additions & 0 deletions examples/xml/port_interface/data/platform.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>AUTOSAR_Platform</SHORT-NAME>
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>BaseTypes</SHORT-NAME>
<ELEMENTS>
<SW-BASE-TYPE>
<SHORT-NAME>uint8</SHORT-NAME>
<BASE-TYPE-SIZE>8</BASE-TYPE-SIZE>
</SW-BASE-TYPE>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>ImplementationDataTypes</SHORT-NAME>
<ELEMENTS>
<IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>uint8</SHORT-NAME>
<CATEGORY>VALUE</CATEGORY>
<SW-DATA-DEF-PROPS>
<SW-DATA-DEF-PROPS-VARIANTS>
<SW-DATA-DEF-PROPS-CONDITIONAL>
<BASE-TYPE-REF DEST="SW-BASE-TYPE">/AUTOSAR_Platform/BaseTypes/uint8</BASE-TYPE-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
13 changes: 13 additions & 0 deletions examples/xml/port_interface/data/sender_receiver_interface.arxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
</VARIABLE-DATA-PROTOTYPE>
</DATA-ELEMENTS>
</SENDER-RECEIVER-INTERFACE>
<SENDER-RECEIVER-INTERFACE>
<SHORT-NAME>InterfaceName</SHORT-NAME>
<DATA-ELEMENTS>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>Element1</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/DataTypes/ImplementationDataTypes/InactiveActive_T</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>Element2</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/DataTypes/ImplementationDataTypes/InactiveActive_T</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
</DATA-ELEMENTS>
</SENDER-RECEIVER-INTERFACE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
Expand Down
74 changes: 74 additions & 0 deletions examples/xml/port_interface/nv_data_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Sender-receiver port interface examples
"""
import os
import autosar
import autosar.xml.element as ar_element


def create_platform_types(packages: dict[str, ar_element.Package]):
"""
Creates necessary platform types
"""
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
packages["PlatformBaseTypes"].append(uint8_base_type)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
uint8_impl_type = ar_element.ImplementationDataType("uint8",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)


def create_nv_data_interface_with_one_element(packages: dict[str, ar_element.Package]):
"""
Creates interface with one element
"""
uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8")
portinterface = ar_element.NvDataInterface("DataInterface1")
portinterface.make_data_element("Data1", type_ref=uint8_type.ref())
packages["PortInterfaces"].append(portinterface)


def create_nv_data_interface_with_two_elements(packages: dict[str, ar_element.Package]):
"""
Creates interface with two elements
"""
uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8")
portinterface = ar_element.NvDataInterface("DataInterface2")
portinterface.make_data_element("Data1", type_ref=uint8_type.ref())
portinterface.make_data_element("Data2", type_ref=uint8_type.ref())
packages["PortInterfaces"].append(portinterface)


def save_xml_files(workspace: autosar.xml.Workspace):
"""
Saves workspace as XML documents
"""
interface_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'nv_data_interface.arxml'))
platform_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'platform.arxml'))
workspace.create_document(interface_document_path, packages="/PortInterfaces")
workspace.create_document(platform_document_path, packages="/AUTOSAR_Platform")
workspace.write_documents()


def main():
"""
Main
"""
workspace = autosar.xml.Workspace()
packages = dict(zip(["PlatformBaseTypes",
"PlatformImplementationDataTypes",
"PortInterfaces"],
workspace.make_packages("AUTOSAR_Platform/BaseTypes",
"AUTOSAR_Platform/ImplementationDataTypes",
"PortInterfaces")))
create_platform_types(packages)
create_nv_data_interface_with_one_element(packages)
create_nv_data_interface_with_two_elements(packages)
save_xml_files(workspace)


if __name__ == "__main__":
main()
74 changes: 74 additions & 0 deletions examples/xml/port_interface/parameter_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Sender-receiver port interface examples
"""
import os
import autosar
import autosar.xml.element as ar_element


def create_platform_types(packages: dict[str, ar_element.Package]):
"""
Creates necessary platform types
"""
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
packages["PlatformBaseTypes"].append(uint8_base_type)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
uint8_impl_type = ar_element.ImplementationDataType("uint8",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)


def create_parameter_interface_with_one_parameter(packages: dict[str, ar_element.Package]):
"""
Creates interface with one parameter
"""
uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8")
portinterface = ar_element.ParameterInterface("ParameterInterface1")
portinterface.make_parameter("Param1", type_ref=uint8_type.ref())
packages["PortInterfaces"].append(portinterface)


def create_parameter_interface_with_two_parameters(packages: dict[str, ar_element.Package]):
"""
Creates interface with two parameters
"""
uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8")
portinterface = ar_element.ParameterInterface("ParameterInterface2")
portinterface.make_parameter("Param1", type_ref=uint8_type.ref())
portinterface.make_parameter("Param2", type_ref=uint8_type.ref())
packages["PortInterfaces"].append(portinterface)


def save_xml_files(workspace: autosar.xml.Workspace):
"""
Saves workspace as XML documents
"""
interface_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'parameter_interface.arxml'))
platform_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'platform.arxml'))
workspace.create_document(interface_document_path, packages="/PortInterfaces")
workspace.create_document(platform_document_path, packages="/AUTOSAR_Platform")
workspace.write_documents()


def main():
"""
Main
"""
workspace = autosar.xml.Workspace()
packages = dict(zip(["PlatformBaseTypes",
"PlatformImplementationDataTypes",
"PortInterfaces"],
workspace.make_packages("AUTOSAR_Platform/BaseTypes",
"AUTOSAR_Platform/ImplementationDataTypes",
"PortInterfaces")))
create_platform_types(packages)
create_parameter_interface_with_one_parameter(packages)
create_parameter_interface_with_two_parameters(packages)
save_xml_files(workspace)


if __name__ == "__main__":
main()
Loading

0 comments on commit 4b0fd0d

Please sign in to comment.