Skip to content

Commit 6990587

Browse files
committed
Implement ClientServerInterface
1 parent a47a09e commit 6990587

14 files changed

+1082
-32
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ Non-collectable elements are various sub-elements to collectable elements.
1111

1212
#### XML Port interface elements
1313

14+
* ClientServerInterface | CLIENT-SERVER-INTERFACE | `collectable`
1415
* NvDataInterface | NV-DATA-INTERFACE | `collectable`
1516
* ParameterInterface | PARAMETER-INTERFACE | `collectable`
1617
* SenderReceiverInterface | SENDER-RECEIVER-INTERFACE | `collectable`
18+
* ApplicationError | APPLICATION-ERROR
19+
* ClientServerOperation | CLIENT-SERVER-OPERATION
1720
* InvalidationPolicy | INVALIDATION-POLICY
1821

1922
#### XML - Data type elements
2023

24+
* ArgumentDataPrototype | ARGUMENT-DATA-PROTOTYPE
2125
* ParameterDataPrototype | PARAMETER-DATA-PROTOTYPE
2226
* VariableDataPrototype | VARIABLE-DATA-PROTOTYPE
2327

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
Sender-receiver port interface examples
3+
"""
4+
import os
5+
import autosar
6+
import autosar.xml.element as ar_element
7+
import autosar.xml.enumeration as ar_enum
8+
9+
10+
def create_platform_types(packages: dict[str, ar_element.Package]):
11+
"""
12+
Creates necessary platform types
13+
"""
14+
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
15+
packages["PlatformBaseTypes"].append(uint8_base_type)
16+
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
17+
packages["PlatformBaseTypes"].append(uint32_base_type)
18+
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
19+
uint8_impl_type = ar_element.ImplementationDataType("uint8",
20+
category="VALUE",
21+
sw_data_def_props=sw_data_def_props)
22+
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)
23+
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
24+
uint32_impl_type = ar_element.ImplementationDataType("uint32",
25+
category="VALUE",
26+
sw_data_def_props=sw_data_def_props)
27+
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)
28+
29+
30+
def create_port_interfaces(packages: dict[str, ar_element.Package]):
31+
"""
32+
Creates interface with one element
33+
"""
34+
uint32_impl_type = packages["PlatformImplementationDataTypes"].find("uint32")
35+
interface = ar_element.ClientServerInterface("FreeRunningTimer_I", is_service=True)
36+
operation = interface.make_operation("GetTimeStamp")
37+
operation.make_out_argument("value",
38+
ar_enum.ServerArgImplPolicy.USE_ARGUMENT_TYPE,
39+
type_ref=uint32_impl_type.ref())
40+
packages["PortInterfaces"].append(interface)
41+
42+
43+
def save_xml_files(workspace: autosar.xml.Workspace):
44+
"""
45+
Saves workspace as XML documents
46+
"""
47+
interface_document_path = os.path.abspath(os.path.join(os.path.dirname(
48+
__file__), 'data', 'client_server_interface.arxml'))
49+
platform_document_path = os.path.abspath(os.path.join(os.path.dirname(
50+
__file__), 'data', 'platform.arxml'))
51+
workspace.create_document(interface_document_path, packages="/PortInterfaces")
52+
workspace.create_document(platform_document_path, packages="/AUTOSAR_Platform")
53+
workspace.write_documents()
54+
55+
56+
def main():
57+
"""
58+
Main
59+
"""
60+
workspace = autosar.xml.Workspace()
61+
packages = dict(zip(["PlatformBaseTypes",
62+
"PlatformImplementationDataTypes",
63+
"PortInterfaces"],
64+
workspace.make_packages("AUTOSAR_Platform/BaseTypes",
65+
"AUTOSAR_Platform/ImplementationDataTypes",
66+
"PortInterfaces")))
67+
create_platform_types(packages)
68+
create_port_interfaces(packages)
69+
save_xml_files(workspace)
70+
71+
72+
if __name__ == "__main__":
73+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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">
3+
<AR-PACKAGES>
4+
<AR-PACKAGE>
5+
<SHORT-NAME>PortInterfaces</SHORT-NAME>
6+
<ELEMENTS>
7+
<CLIENT-SERVER-INTERFACE>
8+
<SHORT-NAME>FreeRunningTimer_I</SHORT-NAME>
9+
<IS-SERVICE>true</IS-SERVICE>
10+
<OPERATIONS>
11+
<CLIENT-SERVER-OPERATION>
12+
<SHORT-NAME>GetTimeStamp</SHORT-NAME>
13+
<ARGUMENTS>
14+
<ARGUMENT-DATA-PROTOTYPE>
15+
<SHORT-NAME>value</SHORT-NAME>
16+
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint32</TYPE-TREF>
17+
<DIRECTION>OUT</DIRECTION>
18+
<SERVER-ARGUMENT-IMPL-POLICY>USE-ARGUMENT-TYPE</SERVER-ARGUMENT-IMPL-POLICY>
19+
</ARGUMENT-DATA-PROTOTYPE>
20+
</ARGUMENTS>
21+
</CLIENT-SERVER-OPERATION>
22+
</OPERATIONS>
23+
</CLIENT-SERVER-INTERFACE>
24+
</ELEMENTS>
25+
</AR-PACKAGE>
26+
</AR-PACKAGES>
27+
</AUTOSAR>

examples/xml/port_interface/data/platform.arxml

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<SHORT-NAME>uint8</SHORT-NAME>
1212
<BASE-TYPE-SIZE>8</BASE-TYPE-SIZE>
1313
</SW-BASE-TYPE>
14+
<SW-BASE-TYPE>
15+
<SHORT-NAME>uint32</SHORT-NAME>
16+
<BASE-TYPE-SIZE>32</BASE-TYPE-SIZE>
17+
</SW-BASE-TYPE>
1418
</ELEMENTS>
1519
</AR-PACKAGE>
1620
<AR-PACKAGE>
@@ -27,6 +31,17 @@
2731
</SW-DATA-DEF-PROPS-VARIANTS>
2832
</SW-DATA-DEF-PROPS>
2933
</IMPLEMENTATION-DATA-TYPE>
34+
<IMPLEMENTATION-DATA-TYPE>
35+
<SHORT-NAME>uint32</SHORT-NAME>
36+
<CATEGORY>VALUE</CATEGORY>
37+
<SW-DATA-DEF-PROPS>
38+
<SW-DATA-DEF-PROPS-VARIANTS>
39+
<SW-DATA-DEF-PROPS-CONDITIONAL>
40+
<BASE-TYPE-REF DEST="SW-BASE-TYPE">/AUTOSAR_Platform/BaseTypes/uint32</BASE-TYPE-REF>
41+
</SW-DATA-DEF-PROPS-CONDITIONAL>
42+
</SW-DATA-DEF-PROPS-VARIANTS>
43+
</SW-DATA-DEF-PROPS>
44+
</IMPLEMENTATION-DATA-TYPE>
3045
</ELEMENTS>
3146
</AR-PACKAGE>
3247
</AR-PACKAGES>

examples/xml/port_interface/nv_data_interface.py

+7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
1212
"""
1313
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
1414
packages["PlatformBaseTypes"].append(uint8_base_type)
15+
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
16+
packages["PlatformBaseTypes"].append(uint32_base_type)
1517
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
1618
uint8_impl_type = ar_element.ImplementationDataType("uint8",
1719
category="VALUE",
1820
sw_data_def_props=sw_data_def_props)
1921
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)
22+
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
23+
uint32_impl_type = ar_element.ImplementationDataType("uint32",
24+
category="VALUE",
25+
sw_data_def_props=sw_data_def_props)
26+
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)
2027

2128

2229
def create_nv_data_interface_with_one_element(packages: dict[str, ar_element.Package]):

examples/xml/port_interface/parameter_interface.py

+7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
1212
"""
1313
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
1414
packages["PlatformBaseTypes"].append(uint8_base_type)
15+
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
16+
packages["PlatformBaseTypes"].append(uint32_base_type)
1517
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
1618
uint8_impl_type = ar_element.ImplementationDataType("uint8",
1719
category="VALUE",
1820
sw_data_def_props=sw_data_def_props)
1921
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)
22+
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
23+
uint32_impl_type = ar_element.ImplementationDataType("uint32",
24+
category="VALUE",
25+
sw_data_def_props=sw_data_def_props)
26+
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)
2027

2128

2229
def create_parameter_interface_with_one_parameter(packages: dict[str, ar_element.Package]):

examples/xml/port_interface/sender_receiver_interface.py

+7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
1212
"""
1313
uint8_base_type = ar_element.SwBaseType('uint8', size=8)
1414
packages["PlatformBaseTypes"].append(uint8_base_type)
15+
uint32_base_type = ar_element.SwBaseType('uint32', size=32)
16+
packages["PlatformBaseTypes"].append(uint32_base_type)
1517
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref())
1618
uint8_impl_type = ar_element.ImplementationDataType("uint8",
1719
category="VALUE",
1820
sw_data_def_props=sw_data_def_props)
1921
packages["PlatformImplementationDataTypes"].append(uint8_impl_type)
22+
sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint32_base_type.ref())
23+
uint32_impl_type = ar_element.ImplementationDataType("uint32",
24+
category="VALUE",
25+
sw_data_def_props=sw_data_def_props)
26+
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)
2027

2128

2229
def create_implementation_data_types(packages: dict[str, ar_element.Package]):

run_examples.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ python examples\xml\unit\unit.py
1111
python examples\xml\port_interface\nv_data_interface.py
1212
python examples\xml\port_interface\parameter_interface.py
1313
python examples\xml\port_interface\sender_receiver_interface.py
14+
python examples\xml\port_interface\client_server_interface.py
1415
python examples\generator\data_types\gen_type_defs_scalar.py
1516
python examples\generator\data_types\gen_type_defs_array.py
1617
python examples\generator\data_types\gen_type_defs_record.py

0 commit comments

Comments
 (0)