|
| 1 | +""" |
| 2 | +Sender-receiver port interface examples |
| 3 | +""" |
| 4 | +import os |
| 5 | +import autosar |
| 6 | +import autosar.xml.element as ar_element |
| 7 | + |
| 8 | + |
| 9 | +def create_platform_types(packages: dict[str, ar_element.Package]): |
| 10 | + """ |
| 11 | + Creates necessary platform types |
| 12 | + """ |
| 13 | + uint8_base_type = ar_element.SwBaseType('uint8', size=8) |
| 14 | + packages["PlatformBaseTypes"].append(uint8_base_type) |
| 15 | + sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref=uint8_base_type.ref()) |
| 16 | + uint8_impl_type = ar_element.ImplementationDataType("uint8", |
| 17 | + category="VALUE", |
| 18 | + sw_data_def_props=sw_data_def_props) |
| 19 | + packages["PlatformImplementationDataTypes"].append(uint8_impl_type) |
| 20 | + |
| 21 | + |
| 22 | +def create_parameter_interface_with_one_parameter(packages: dict[str, ar_element.Package]): |
| 23 | + """ |
| 24 | + Creates interface with one parameter |
| 25 | + """ |
| 26 | + uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8") |
| 27 | + portinterface = ar_element.ParameterInterface("ParameterInterface1") |
| 28 | + portinterface.make_parameter("Param1", type_ref=uint8_type.ref()) |
| 29 | + packages["PortInterfaces"].append(portinterface) |
| 30 | + |
| 31 | + |
| 32 | +def create_parameter_interface_with_two_parameters(packages: dict[str, ar_element.Package]): |
| 33 | + """ |
| 34 | + Creates interface with two parameters |
| 35 | + """ |
| 36 | + uint8_type: ar_element.ImplementationDataType = packages["PlatformImplementationDataTypes"].find("uint8") |
| 37 | + portinterface = ar_element.ParameterInterface("ParameterInterface2") |
| 38 | + portinterface.make_parameter("Param1", type_ref=uint8_type.ref()) |
| 39 | + portinterface.make_parameter("Param2", type_ref=uint8_type.ref()) |
| 40 | + packages["PortInterfaces"].append(portinterface) |
| 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', 'parameter_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_parameter_interface_with_one_parameter(packages) |
| 69 | + create_parameter_interface_with_two_parameters(packages) |
| 70 | + save_xml_files(workspace) |
| 71 | + |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + main() |
0 commit comments