-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,082 additions
and
32 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,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
27
examples/xml/port_interface/data/client_server_interface.arxml
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,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> |
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
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.