Skip to content

Commit

Permalink
Implement ClientServerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
cogu committed Feb 2, 2024
1 parent 4b0fd0d commit 950d36c
Show file tree
Hide file tree
Showing 14 changed files with 1,082 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ Non-collectable elements are various sub-elements to collectable elements.

#### XML Port interface elements

* ClientServerInterface | CLIENT-SERVER-INTERFACE | `collectable`
* NvDataInterface | NV-DATA-INTERFACE | `collectable`
* ParameterInterface | PARAMETER-INTERFACE | `collectable`
* SenderReceiverInterface | SENDER-RECEIVER-INTERFACE | `collectable`
* ApplicationError | APPLICATION-ERROR
* ClientServerOperation | CLIENT-SERVER-OPERATION
* InvalidationPolicy | INVALIDATION-POLICY

#### XML - Data type elements

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

Expand Down
73 changes: 73 additions & 0 deletions examples/xml/port_interface/client_server_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Sender-receiver port interface examples
"""
import os
import autosar
import autosar.xml.element as ar_element
import autosar.xml.enumeration as ar_enum


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)
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
packages["PlatformBaseTypes"].append(uint32_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)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
uint32_impl_type = ar_element.ImplementationDataType("uint32",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)


def create_port_interfaces(packages: dict[str, ar_element.Package]):
"""
Creates interface with one element
"""
uint32_impl_type = packages["PlatformImplementationDataTypes"].find("uint32")
interface = ar_element.ClientServerInterface("FreeRunningTimer_I", is_service=True)
operation = interface.make_operation("GetTimeStamp")
operation.make_out_argument("value",
ar_enum.ServerArgImplPolicy.USE_ARGUMENT_TYPE,
type_ref=uint32_impl_type.ref())
packages["PortInterfaces"].append(interface)


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', 'client_server_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_port_interfaces(packages)
save_xml_files(workspace)


if __name__ == "__main__":
main()
27 changes: 27 additions & 0 deletions examples/xml/port_interface/data/client_server_interface.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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>
<CLIENT-SERVER-INTERFACE>
<SHORT-NAME>FreeRunningTimer_I</SHORT-NAME>
<IS-SERVICE>true</IS-SERVICE>
<OPERATIONS>
<CLIENT-SERVER-OPERATION>
<SHORT-NAME>GetTimeStamp</SHORT-NAME>
<ARGUMENTS>
<ARGUMENT-DATA-PROTOTYPE>
<SHORT-NAME>value</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint32</TYPE-TREF>
<DIRECTION>OUT</DIRECTION>
<SERVER-ARGUMENT-IMPL-POLICY>USE-ARGUMENT-TYPE</SERVER-ARGUMENT-IMPL-POLICY>
</ARGUMENT-DATA-PROTOTYPE>
</ARGUMENTS>
</CLIENT-SERVER-OPERATION>
</OPERATIONS>
</CLIENT-SERVER-INTERFACE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
15 changes: 15 additions & 0 deletions examples/xml/port_interface/data/platform.arxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<SHORT-NAME>uint8</SHORT-NAME>
<BASE-TYPE-SIZE>8</BASE-TYPE-SIZE>
</SW-BASE-TYPE>
<SW-BASE-TYPE>
<SHORT-NAME>uint32</SHORT-NAME>
<BASE-TYPE-SIZE>32</BASE-TYPE-SIZE>
</SW-BASE-TYPE>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
Expand All @@ -27,6 +31,17 @@
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE>
<IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>uint32</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/uint32</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>
Expand Down
7 changes: 7 additions & 0 deletions examples/xml/port_interface/nv_data_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
"""
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
packages["PlatformBaseTypes"].append(uint8_base_type)
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
packages["PlatformBaseTypes"].append(uint32_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)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
uint32_impl_type = ar_element.ImplementationDataType("uint32",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)


def create_nv_data_interface_with_one_element(packages: dict[str, ar_element.Package]):
Expand Down
7 changes: 7 additions & 0 deletions examples/xml/port_interface/parameter_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
"""
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
packages["PlatformBaseTypes"].append(uint8_base_type)
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
packages["PlatformBaseTypes"].append(uint32_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)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
uint32_impl_type = ar_element.ImplementationDataType("uint32",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)


def create_parameter_interface_with_one_parameter(packages: dict[str, ar_element.Package]):
Expand Down
7 changes: 7 additions & 0 deletions examples/xml/port_interface/sender_receiver_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
"""
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
packages["PlatformBaseTypes"].append(uint8_base_type)
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
packages["PlatformBaseTypes"].append(uint32_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)
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
uint32_impl_type = ar_element.ImplementationDataType("uint32",
category="VALUE",
sw_data_def_props=sw_data_def_props)
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)


def create_implementation_data_types(packages: dict[str, ar_element.Package]):
Expand Down
1 change: 1 addition & 0 deletions run_examples.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python examples\xml\unit\unit.py
python examples\xml\port_interface\nv_data_interface.py
python examples\xml\port_interface\parameter_interface.py
python examples\xml\port_interface\sender_receiver_interface.py
python examples\xml\port_interface\client_server_interface.py
python examples\generator\data_types\gen_type_defs_scalar.py
python examples\generator\data_types\gen_type_defs_array.py
python examples\generator\data_types\gen_type_defs_record.py
Expand Down
Loading

0 comments on commit 950d36c

Please sign in to comment.