Skip to content

Commit

Permalink
Add port creation helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cogu committed Mar 10, 2024
1 parent 92c674c commit 334a0df
Show file tree
Hide file tree
Showing 10 changed files with 624 additions and 67 deletions.
46 changes: 26 additions & 20 deletions examples/xml/component/application_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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]):
Expand Down Expand Up @@ -50,17 +49,6 @@ def create_platform_types(packages: dict[str, ar_element.Package]):
packages["PlatformImplementationDataTypes"].append(uint32_impl_type)


# def create_implementation_data_types(packages: dict[str, ar_element.Package]):
# """
# Creates non-platform implementation data types
# """
# sw_data_def_props = ar_element.SwDataDefPropsConditional(base_type_ref="AUTOSAR_Platform/BaseTypes/uint8")
# inactive_active_t = ar_element.ImplementationDataType("InactiveActive_T",
# category="VALUE",
# sw_data_def_props=sw_data_def_props)
# packages["ImplementationDataTypes"].append(inactive_active_t)


def create_sender_receiver_port_interfaces(packages: dict[str, ar_element.Package]):
"""
Create sender-receiver port interfaces used in example
Expand All @@ -69,9 +57,6 @@ def create_sender_receiver_port_interfaces(packages: dict[str, ar_element.Packag
port_interface = ar_element.SenderReceiverInterface("VehicleSpeed_I")
port_interface.create_data_element("VehicleSpeed", type_ref=uint16_impl_t.ref())
packages["PortInterfaces"].append(port_interface)
port_interface = ar_element.SenderReceiverInterface("EngineSpeed_I")
port_interface.create_data_element("EngineSpeed", type_ref=uint16_impl_t.ref())
packages["PortInterfaces"].append(port_interface)


def create_client_server_interfaces(packages: dict[str, ar_element.Package]):
Expand All @@ -90,19 +75,37 @@ def create_client_server_interfaces(packages: dict[str, ar_element.Package]):
packages["PortInterfaces"].append(interface)


def create_application_component(packages: dict[str, ar_element.Package]):
"""
Creates application component with one sender-receiver port and one
client-server port
"""
timer_interface = packages["PortInterfaces"].find("FreeRunningTimer_I")
vehicle_speed_interface = packages["PortInterfaces"].find("VehicleSpeed_I")
swc = ar_element.ApplicationSoftwareComponentType("MyApplication")
swc.create_require_port("VehicleSpeed", vehicle_speed_interface, com_spec={"init_value": 65535,
'alive_timeout': 0,
'enable_update': False,
'uses_end_to_end_protection': False,
'handle_never_received': False
})
swc.create_require_port("FreeRunningTimer", timer_interface)
packages["ComponentTypes"].append(swc)


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', 'portinterfaces.arxml'))
datatype_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'datatypes.arxml'))
platform_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'platform.arxml'))
component_document_path = os.path.abspath(os.path.join(os.path.dirname(
__file__), 'data', 'MyApplication.arxml'))
workspace.create_document(interface_document_path, packages="/PortInterfaces")
workspace.create_document(datatype_document_path, packages="/DataTypes")
workspace.create_document(platform_document_path, packages="/AUTOSAR_Platform")
workspace.create_document(component_document_path, packages="/ComponentTypes")
workspace.write_documents()


Expand All @@ -116,16 +119,19 @@ def main():
"PlatformDataConstraints",
"PlatformCompuMethods",
"ImplementationDataTypes",
"PortInterfaces"],
"PortInterfaces",
"ComponentTypes"],
workspace.make_packages("AUTOSAR_Platform/BaseTypes",
"AUTOSAR_Platform/ImplementationDataTypes",
"AUTOSAR_Platform/DataConstraints",
"AUTOSAR_Platform/CompuMethods",
"DataTypes/ImplementationDataTypes",
"PortInterfaces")))
"PortInterfaces",
"ComponentTypes")))
create_platform_types(packages)
create_sender_receiver_port_interfaces(packages)
create_client_server_interfaces(packages)
create_application_component(packages)
save_xml_files(workspace)


Expand Down
37 changes: 37 additions & 0 deletions examples/xml/component/data/MyApplication.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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>ComponentTypes</SHORT-NAME>
<ELEMENTS>
<APPLICATION-SW-COMPONENT-TYPE>
<SHORT-NAME>MyApplication</SHORT-NAME>
<PORTS>
<R-PORT-PROTOTYPE>
<SHORT-NAME>VehicleSpeed</SHORT-NAME>
<REQUIRED-COM-SPECS>
<NONQUEUED-RECEIVER-COM-SPEC>
<DATA-ELEMENT-REF DEST="VARIABLE-DATA-PROTOTYPE">/PortInterfaces/VehicleSpeed_I/VehicleSpeed</DATA-ELEMENT-REF>
<USES-END-TO-END-PROTECTION>false</USES-END-TO-END-PROTECTION>
<ALIVE-TIMEOUT>0</ALIVE-TIMEOUT>
<ENABLE-UPDATE>false</ENABLE-UPDATE>
<HANDLE-NEVER-RECEIVED>false</HANDLE-NEVER-RECEIVED>
<INIT-VALUE>
<NUMERICAL-VALUE-SPECIFICATION>
<VALUE>65535</VALUE>
</NUMERICAL-VALUE-SPECIFICATION>
</INIT-VALUE>
</NONQUEUED-RECEIVER-COM-SPEC>
</REQUIRED-COM-SPECS>
<REQUIRED-INTERFACE-TREF DEST="SENDER-RECEIVER-INTERFACE">/PortInterfaces/VehicleSpeed_I</REQUIRED-INTERFACE-TREF>
</R-PORT-PROTOTYPE>
<R-PORT-PROTOTYPE>
<SHORT-NAME>FreeRunningTimer</SHORT-NAME>
<REQUIRED-INTERFACE-TREF DEST="CLIENT-SERVER-INTERFACE">/PortInterfaces/FreeRunningTimer_I</REQUIRED-INTERFACE-TREF>
</R-PORT-PROTOTYPE>
</PORTS>
</APPLICATION-SW-COMPONENT-TYPE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
128 changes: 128 additions & 0 deletions examples/xml/component/data/platform.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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>boolean</SHORT-NAME>
<BASE-TYPE-SIZE>8</BASE-TYPE-SIZE>
<BASE-TYPE-ENCODING>BOOLEAN</BASE-TYPE-ENCODING>
</SW-BASE-TYPE>
<SW-BASE-TYPE>
<SHORT-NAME>uint8</SHORT-NAME>
<BASE-TYPE-SIZE>8</BASE-TYPE-SIZE>
</SW-BASE-TYPE>
<SW-BASE-TYPE>
<SHORT-NAME>uint16</SHORT-NAME>
<BASE-TYPE-SIZE>16</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>
<SHORT-NAME>ImplementationDataTypes</SHORT-NAME>
<ELEMENTS>
<IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>boolean</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>
<COMPU-METHOD-REF DEST="COMPU-METHOD">/AUTOSAR_Platform/CompuMethods/boolean_CompuMethod</COMPU-METHOD-REF>
<DATA-CONSTR-REF DEST="DATA-CONSTR">/AUTOSAR_Platform/DataConstraints/boolean_DataConstr</DATA-CONSTR-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE>
<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>
<IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>uint16</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/uint16</BASE-TYPE-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</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-PACKAGE>
<SHORT-NAME>DataConstraints</SHORT-NAME>
<ELEMENTS>
<DATA-CONSTR>
<SHORT-NAME>boolean_DataConstr</SHORT-NAME>
<DATA-CONSTR-RULES>
<DATA-CONSTR-RULE>
<INTERNAL-CONSTRS>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">1</UPPER-LIMIT>
</INTERNAL-CONSTRS>
</DATA-CONSTR-RULE>
</DATA-CONSTR-RULES>
</DATA-CONSTR>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>CompuMethods</SHORT-NAME>
<ELEMENTS>
<COMPU-METHOD>
<SHORT-NAME>boolean_CompuMethod</SHORT-NAME>
<CATEGORY>TEXTTABLE</CATEGORY>
<COMPU-INTERNAL-TO-PHYS>
<COMPU-SCALES>
<COMPU-SCALE>
<SHORT-LABEL>FALSE</SHORT-LABEL>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
<COMPU-CONST>
<VT>FALSE</VT>
</COMPU-CONST>
</COMPU-SCALE>
<COMPU-SCALE>
<SHORT-LABEL>TRUE</SHORT-LABEL>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">1</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">1</UPPER-LIMIT>
<COMPU-CONST>
<VT>TRUE</VT>
</COMPU-CONST>
</COMPU-SCALE>
</COMPU-SCALES>
</COMPU-INTERNAL-TO-PHYS>
</COMPU-METHOD>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
54 changes: 54 additions & 0 deletions examples/xml/component/data/portinterfaces.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>
<SENDER-RECEIVER-INTERFACE>
<SHORT-NAME>VehicleSpeed_I</SHORT-NAME>
<DATA-ELEMENTS>
<VARIABLE-DATA-PROTOTYPE>
<SHORT-NAME>VehicleSpeed</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint16</TYPE-TREF>
</VARIABLE-DATA-PROTOTYPE>
</DATA-ELEMENTS>
</SENDER-RECEIVER-INTERFACE>
<CLIENT-SERVER-INTERFACE>
<SHORT-NAME>FreeRunningTimer_I</SHORT-NAME>
<OPERATIONS>
<CLIENT-SERVER-OPERATION>
<SHORT-NAME>GetTime</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>
</ARGUMENT-DATA-PROTOTYPE>
</ARGUMENTS>
</CLIENT-SERVER-OPERATION>
<CLIENT-SERVER-OPERATION>
<SHORT-NAME>IsTimerElapsed</SHORT-NAME>
<ARGUMENTS>
<ARGUMENT-DATA-PROTOTYPE>
<SHORT-NAME>startTime</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint32</TYPE-TREF>
<DIRECTION>IN</DIRECTION>
</ARGUMENT-DATA-PROTOTYPE>
<ARGUMENT-DATA-PROTOTYPE>
<SHORT-NAME>duration</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/uint32</TYPE-TREF>
<DIRECTION>IN</DIRECTION>
</ARGUMENT-DATA-PROTOTYPE>
<ARGUMENT-DATA-PROTOTYPE>
<SHORT-NAME>result</SHORT-NAME>
<TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_Platform/ImplementationDataTypes/boolean</TYPE-TREF>
<DIRECTION>OUT</DIRECTION>
</ARGUMENT-DATA-PROTOTYPE>
</ARGUMENTS>
</CLIENT-SERVER-OPERATION>
</OPERATIONS>
</CLIENT-SERVER-INTERFACE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
2 changes: 1 addition & 1 deletion examples/xml/port_interface/client_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_platform_types(packages: dict[str, ar_element.Package]):

def create_port_interfaces(packages: dict[str, ar_element.Package]):
"""
Creates interface with one element
Creates client-server interface with one operation
"""
uint32_impl_type = packages["PlatformImplementationDataTypes"].find("uint32")
interface = ar_element.ClientServerInterface("FreeRunningTimer_I", is_service=True)
Expand Down
Loading

0 comments on commit 334a0df

Please sign in to comment.