Skip to content

Commit 4f16712

Browse files
committed
Add event creation examples
- Examples using event creation API - Add logic for adding numeric suffix to event names
1 parent 330367c commit 4f16712

18 files changed

+427
-52
lines changed

examples/template/config.toml

+10
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@
3333
element_types = "SwComponentType"
3434
suffix_filters = ["_Implementation"]
3535

36+
[behavior]
37+
background_event_prefix = "BT_"
38+
data_receive_error_event_prefix = "DRET_"
39+
data_receive_event_prefix = "DRT_"
40+
init_event_prefix = "IT_"
41+
operation_invoked_event_prefix = "OIT_"
42+
swc_mode_manager_error_event_prefix = "MMET_"
43+
swc_mode_switch_event_prefix = "MST_"
44+
timing_event_prefix = "TMT_"
45+

examples/template/demo_system/component.py

+40-13
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,35 @@
55

66

77
import autosar.xml.element as ar_element
8+
import autosar.xml.enumeration as ar_enum
89
import autosar.xml.workspace as ar_workspace
910
from . import factory, portinterface, constants
1011

1112
NAMESPACE = "Default"
1213

1314

14-
def create_ReceiverComponent(_0: ar_element.Package,
15+
def create_ReceiverComponent(package: ar_element.Package,
1516
workspace: ar_workspace.Workspace,
1617
deps: dict[str, ar_element.ARElement] | None,
1718
**_1) -> ar_element.ApplicationSoftwareComponentType:
1819
"""
19-
Create Receiver component type
20+
Receiver ports:
21+
- EngineSpeed
22+
- VehicleSpeed
23+
Client ports:
24+
- FreeRunningTimer
2025
"""
2126
timer_interface = deps[portinterface.FreeRunningTimer_I.ref(workspace)]
2227
vehicle_speed_interface = deps[portinterface.VehicleSpeed_I.ref(workspace)]
2328
engine_speed_interface = deps[portinterface.EngineSpeed_I.ref(workspace)]
29+
ecu_mode_interface = deps[portinterface.EcuM_CurrentMode_I.ref(workspace)]
2430
engine_speed_init = deps[constants.EngineSpeed_IV.ref(workspace)]
2531
vehicle_speed_init = deps[constants.VehicleSpeed_IV.ref(workspace)]
26-
swc = ar_element.ApplicationSoftwareComponentType("ReceiverComponent")
32+
swc_name = "ReceiverComponent"
33+
swc = ar_element.ApplicationSoftwareComponentType(swc_name)
34+
package.append(swc)
35+
swc.create_require_port("EcuM_CurrentMode", ecu_mode_interface, com_spec={"enhanced_mode_api": False,
36+
"supports_async": False})
2737
swc.create_require_port("EngineSpeed", engine_speed_interface, com_spec={"init_value": engine_speed_init.ref(),
2838
"alive_timeout": 0,
2939
"enable_update": False,
@@ -37,30 +47,48 @@ def create_ReceiverComponent(_0: ar_element.Package,
3747
"handle_never_received": False
3848
})
3949
swc.create_require_port("FreeRunningTimer", timer_interface)
40-
swc.create_internal_behavior()
50+
init_runnable_name = swc_name + '_Init'
51+
periodic_runnable_name = swc_name + '_Run'
52+
behavior = swc.create_internal_behavior()
53+
behavior.create_runnable(init_runnable_name)
54+
behavior.create_runnable(periodic_runnable_name)
55+
behavior.create_swc_mode_mode_switch_event(init_runnable_name,
56+
"EcuM_CurrentMode/RUN",
57+
ar_enum.ModeActivationKind.ON_ENTRY)
58+
behavior.create_timing_event(periodic_runnable_name, 20.0 / 1000)
4159
return swc
4260

4361

44-
def create_TimerComponent(_0: ar_element.Package,
62+
def create_TimerComponent(package: ar_element.Package,
4563
workspace: ar_workspace.Workspace,
4664
deps: dict[str, ar_element.ARElement] | None,
47-
**_1) -> ar_element.ApplicationSoftwareComponentType:
65+
**_0) -> ar_element.ApplicationSoftwareComponentType:
4866
"""
4967
Create TimerComponent component type
5068
"""
5169
timer_interface = deps[portinterface.FreeRunningTimer_I.ref(workspace)]
5270
swc = ar_element.ApplicationSoftwareComponentType("TimerComponent")
71+
package.append(swc)
5372
swc.create_provide_port("FreeRunningTimer", timer_interface, com_spec={"GetTime": {"queue_length": 1},
5473
"IsTimerElapsed": {"queue_length": 1}
5574
})
56-
swc.create_internal_behavior()
75+
behavior = swc.create_internal_behavior()
76+
init_runnable_name = swc.name + "_Init"
77+
get_time_runnable_name = swc.name + "_GetTime"
78+
timer_elapsed_runnable_name = swc.name + "_IsTimerElapsed"
79+
behavior.create_runnable(init_runnable_name)
80+
behavior.create_runnable(get_time_runnable_name, reentrancy_level=ar_enum.ReentrancyLevel.NON_REENTRANT)
81+
behavior.create_runnable(timer_elapsed_runnable_name, reentrancy_level=ar_enum.ReentrancyLevel.NON_REENTRANT)
82+
behavior.create_init_event(init_runnable_name)
83+
behavior.create_operation_invoked_event(get_time_runnable_name, "FreeRunningTimer/GetTime")
84+
behavior.create_operation_invoked_event(timer_elapsed_runnable_name, "FreeRunningTimer/IsTimerElapsed")
5785
return swc
5886

5987

6088
def create_composition_component(package: ar_element.Package,
6189
workspace: ar_workspace.Workspace,
6290
deps: dict[str, ar_element.ARElement] | None,
63-
**_1) -> ar_element.ApplicationSoftwareComponentType:
91+
**_0) -> ar_element.ApplicationSoftwareComponentType:
6492
"""
6593
Creates a composition component
6694
The created swc must be manually added to the package, otherwise the
@@ -77,15 +105,14 @@ def create_composition_component(package: ar_element.Package,
77105
assert isinstance(receiver_component, ar_element.ApplicationSoftwareComponentType)
78106
assert isinstance(timer_component, ar_element.ApplicationSoftwareComponentType)
79107
swc = ar_element.CompositionSwComponentType("CompositionComponent")
108+
package.append(swc)
80109
swc.create_require_port("EngineSpeed", engine_speed_interface, com_spec={"init_value": engine_speed_init.ref(),
81110
"uses_end_to_end_protection": False})
82111
swc.create_require_port("VehicleSpeed", vehicle_speed_interface, com_spec={"init_value": vehicle_speed_init.ref(),
83112
"uses_end_to_end_protection": False})
84113

85114
swc.create_component_prototype(receiver_component)
86115
swc.create_component_prototype(timer_component)
87-
# Element must be added to workspace before connectors can be created
88-
package.append(swc)
89116
swc.create_connector("TimerComponent/FreeRunningTimer", "ReceiverComponent/FreeRunningTimer", workspace)
90117
swc.create_connector("VehicleSpeed", "ReceiverComponent/VehicleSpeed", workspace)
91118
swc.create_connector("EngineSpeed", "ReceiverComponent/EngineSpeed", workspace)
@@ -95,7 +122,8 @@ def create_composition_component(package: ar_element.Package,
95122
ReceiverComponent = factory.GenericComponentTypeTemplate("ReceiverComponent",
96123
NAMESPACE,
97124
create_ReceiverComponent,
98-
depends=[portinterface.EngineSpeed_I,
125+
depends=[portinterface.EcuM_CurrentMode_I,
126+
portinterface.EngineSpeed_I,
99127
portinterface.VehicleSpeed_I,
100128
portinterface.FreeRunningTimer_I,
101129
constants.EngineSpeed_IV,
@@ -118,5 +146,4 @@ def create_composition_component(package: ar_element.Package,
118146
constants.EngineSpeed_IV,
119147
constants.VehicleSpeed_IV,
120148
ReceiverComponent_Implementation,
121-
TimerComponent_Implementation],
122-
append_to_package=False)
149+
TimerComponent_Implementation])

examples/template/demo_system/factory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def __init__(self,
362362
namespace_name: str,
363363
create_func: CreateFuncType,
364364
depends: list[TemplateBase] | None = None,
365-
append_to_package: bool = True) -> None:
365+
append_to_package: bool = False) -> None:
366366
super().__init__(element_name, namespace_name, ar_enum.PackageRole.COMPONENT_TYPE, depends, append_to_package)
367367
self.create_func = create_func
368368

examples/template/demo_system/portinterface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_free_running_timer_interface(_0: str,
4444
operation.create_out_argument("result", type_ref=boolean_impl_type.ref())
4545
return port_interface
4646

47-
EcuM_CurrentMode = factory.ModeSwitchInterfaceTemplate("EcuM_CurrentMode", NAMESPACE, mode.EcuM_Mode, "currentMode", is_service=True)
47+
EcuM_CurrentMode_I = factory.ModeSwitchInterfaceTemplate("EcuM_CurrentMode_I", NAMESPACE, mode.EcuM_Mode, "currentMode", is_service=True)
4848
NvMService_I = factory.GenericPortInterfaceTemplate("NvMService_I", NAMESPACE, create_NvMService_interface)
4949
FreeRunningTimer_I = factory.GenericPortInterfaceTemplate("FreeRunningTimer_I",
5050
NAMESPACE,

examples/template/generate_xml_without_config.py

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ def create_namespaces(workspace: ar_workspace.Workspace):
3232
base_ref="/")
3333

3434

35+
def create_behavior_settings(workspace: ar_workspace.Workspace):
36+
"""
37+
Define default event name prefixess
38+
"""
39+
workspace.behavior_settings.update({
40+
"background_event_prefix": "BT_",
41+
"data_receive_error_event_prefix": "DRET_",
42+
"data_receive_event_prefix": "DRT_",
43+
"init_event_prefix": "IT_",
44+
"operation_invoked_event_prefix": "OIT_",
45+
"swc_mode_manager_error_event_prefix": "MMET_",
46+
"swc_mode_switch_event_prefix": "MST_",
47+
"timing_event_prefix": "TMT_"})
48+
49+
3550
def create_documents(workspace: ar_workspace.Workspace) -> None:
3651
"""
3752
Creates documents
@@ -67,6 +82,7 @@ def main():
6782
"""Main"""
6883
workspace = ar_workspace.Workspace(document_root="generated")
6984
create_namespaces(workspace)
85+
create_behavior_settings(workspace)
7086
create_documents(workspace)
7187
apply_platform_types(workspace)
7288
apply_component_types(workspace)

examples/template/generated/PortInterfaces.arxml

+37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
33
<AR-PACKAGES>
4+
<AR-PACKAGE>
5+
<SHORT-NAME>ModeDclrGroups</SHORT-NAME>
6+
<ELEMENTS>
7+
<MODE-DECLARATION-GROUP>
8+
<SHORT-NAME>EcuM_Mode</SHORT-NAME>
9+
<INITIAL-MODE-REF DEST="MODE-DECLARATION">/ModeDclrGroups/EcuM_Mode/STARTUP</INITIAL-MODE-REF>
10+
<MODE-DECLARATIONS>
11+
<MODE-DECLARATION>
12+
<SHORT-NAME>STARTUP</SHORT-NAME>
13+
</MODE-DECLARATION>
14+
<MODE-DECLARATION>
15+
<SHORT-NAME>RUN</SHORT-NAME>
16+
</MODE-DECLARATION>
17+
<MODE-DECLARATION>
18+
<SHORT-NAME>POST_RUN</SHORT-NAME>
19+
</MODE-DECLARATION>
20+
<MODE-DECLARATION>
21+
<SHORT-NAME>SLEEP</SHORT-NAME>
22+
</MODE-DECLARATION>
23+
<MODE-DECLARATION>
24+
<SHORT-NAME>WAKEUP</SHORT-NAME>
25+
</MODE-DECLARATION>
26+
<MODE-DECLARATION>
27+
<SHORT-NAME>SHUTDOWN</SHORT-NAME>
28+
</MODE-DECLARATION>
29+
</MODE-DECLARATIONS>
30+
</MODE-DECLARATION-GROUP>
31+
</ELEMENTS>
32+
</AR-PACKAGE>
433
<AR-PACKAGE>
534
<SHORT-NAME>PortInterfaces</SHORT-NAME>
635
<ELEMENTS>
@@ -22,6 +51,14 @@
2251
</VARIABLE-DATA-PROTOTYPE>
2352
</DATA-ELEMENTS>
2453
</SENDER-RECEIVER-INTERFACE>
54+
<MODE-SWITCH-INTERFACE>
55+
<SHORT-NAME>EcuM_CurrentMode_I</SHORT-NAME>
56+
<IS-SERVICE>true</IS-SERVICE>
57+
<MODE-GROUP>
58+
<SHORT-NAME>currentMode</SHORT-NAME>
59+
<TYPE-TREF DEST="MODE-DECLARATION-GROUP">/ModeDclrGroups/EcuM_Mode</TYPE-TREF>
60+
</MODE-GROUP>
61+
</MODE-SWITCH-INTERFACE>
2562
<CLIENT-SERVER-INTERFACE>
2663
<SHORT-NAME>FreeRunningTimer_I</SHORT-NAME>
2764
<OPERATIONS>

examples/template/generated/ReceiverComponent.arxml

+38
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
<APPLICATION-SW-COMPONENT-TYPE>
88
<SHORT-NAME>ReceiverComponent</SHORT-NAME>
99
<PORTS>
10+
<R-PORT-PROTOTYPE>
11+
<SHORT-NAME>EcuM_CurrentMode</SHORT-NAME>
12+
<REQUIRED-COM-SPECS>
13+
<MODE-SWITCH-RECEIVER-COM-SPEC>
14+
<ENHANCED-MODE-API>false</ENHANCED-MODE-API>
15+
<MODE-GROUP-REF DEST="MODE-DECLARATION-GROUP-PROTOTYPE">/PortInterfaces/EcuM_CurrentMode_I/currentMode</MODE-GROUP-REF>
16+
<SUPPORTS-ASYNCHRONOUS-MODE-SWITCH>false</SUPPORTS-ASYNCHRONOUS-MODE-SWITCH>
17+
</MODE-SWITCH-RECEIVER-COM-SPEC>
18+
</REQUIRED-COM-SPECS>
19+
<REQUIRED-INTERFACE-TREF DEST="MODE-SWITCH-INTERFACE">/PortInterfaces/EcuM_CurrentMode_I</REQUIRED-INTERFACE-TREF>
20+
</R-PORT-PROTOTYPE>
1021
<R-PORT-PROTOTYPE>
1122
<SHORT-NAME>EngineSpeed</SHORT-NAME>
1223
<REQUIRED-COM-SPECS>
@@ -51,6 +62,33 @@
5162
<INTERNAL-BEHAVIORS>
5263
<SWC-INTERNAL-BEHAVIOR>
5364
<SHORT-NAME>ReceiverComponent_InternalBehavior</SHORT-NAME>
65+
<EVENTS>
66+
<SWC-MODE-SWITCH-EVENT>
67+
<SHORT-NAME>MST_ReceiverComponent_Init</SHORT-NAME>
68+
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/ComponentTypes/ReceiverComponent/ReceiverComponent_InternalBehavior/ReceiverComponent_Init</START-ON-EVENT-REF>
69+
<ACTIVATION>ON-ENTRY</ACTIVATION>
70+
<MODE-IREFS>
71+
<MODE-IREF>
72+
<CONTEXT-PORT-REF DEST="R-PORT-PROTOTYPE">/ComponentTypes/ReceiverComponent/EcuM_CurrentMode</CONTEXT-PORT-REF>
73+
<CONTEXT-MODE-DECLARATION-GROUP-PROTOTYPE-REF DEST="MODE-DECLARATION-GROUP-PROTOTYPE">/PortInterfaces/EcuM_CurrentMode_I/currentMode</CONTEXT-MODE-DECLARATION-GROUP-PROTOTYPE-REF>
74+
<TARGET-MODE-DECLARATION-REF DEST="MODE-DECLARATION">/ModeDclrGroups/EcuM_Mode/RUN</TARGET-MODE-DECLARATION-REF>
75+
</MODE-IREF>
76+
</MODE-IREFS>
77+
</SWC-MODE-SWITCH-EVENT>
78+
<TIMING-EVENT>
79+
<SHORT-NAME>TMT_ReceiverComponent_Run</SHORT-NAME>
80+
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/ComponentTypes/ReceiverComponent/ReceiverComponent_InternalBehavior/ReceiverComponent_Run</START-ON-EVENT-REF>
81+
<PERIOD>0.02</PERIOD>
82+
</TIMING-EVENT>
83+
</EVENTS>
84+
<RUNNABLES>
85+
<RUNNABLE-ENTITY>
86+
<SHORT-NAME>ReceiverComponent_Init</SHORT-NAME>
87+
</RUNNABLE-ENTITY>
88+
<RUNNABLE-ENTITY>
89+
<SHORT-NAME>ReceiverComponent_Run</SHORT-NAME>
90+
</RUNNABLE-ENTITY>
91+
</RUNNABLES>
5492
</SWC-INTERNAL-BEHAVIOR>
5593
</INTERNAL-BEHAVIORS>
5694
</APPLICATION-SW-COMPONENT-TYPE>

examples/template/generated/TimerComponent.arxml

+35
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@
2525
<INTERNAL-BEHAVIORS>
2626
<SWC-INTERNAL-BEHAVIOR>
2727
<SHORT-NAME>TimerComponent_InternalBehavior</SHORT-NAME>
28+
<EVENTS>
29+
<INIT-EVENT>
30+
<SHORT-NAME>IT_TimerComponent_Init</SHORT-NAME>
31+
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/ComponentTypes/TimerComponent/TimerComponent_InternalBehavior/TimerComponent_Init</START-ON-EVENT-REF>
32+
</INIT-EVENT>
33+
<OPERATION-INVOKED-EVENT>
34+
<SHORT-NAME>OIT_TimerComponent_GetTime_FreeRunningTimer_GetTime</SHORT-NAME>
35+
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/ComponentTypes/TimerComponent/TimerComponent_InternalBehavior/TimerComponent_GetTime</START-ON-EVENT-REF>
36+
<OPERATION-IREF>
37+
<CONTEXT-P-PORT-REF DEST="P-PORT-PROTOTYPE">/ComponentTypes/TimerComponent/FreeRunningTimer</CONTEXT-P-PORT-REF>
38+
<TARGET-PROVIDED-OPERATION-REF DEST="CLIENT-SERVER-OPERATION">/PortInterfaces/FreeRunningTimer_I/GetTime</TARGET-PROVIDED-OPERATION-REF>
39+
</OPERATION-IREF>
40+
</OPERATION-INVOKED-EVENT>
41+
<OPERATION-INVOKED-EVENT>
42+
<SHORT-NAME>OIT_TimerComponent_IsTimerElapsed_FreeRunningTimer_IsTimerElapsed</SHORT-NAME>
43+
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/ComponentTypes/TimerComponent/TimerComponent_InternalBehavior/TimerComponent_IsTimerElapsed</START-ON-EVENT-REF>
44+
<OPERATION-IREF>
45+
<CONTEXT-P-PORT-REF DEST="P-PORT-PROTOTYPE">/ComponentTypes/TimerComponent/FreeRunningTimer</CONTEXT-P-PORT-REF>
46+
<TARGET-PROVIDED-OPERATION-REF DEST="CLIENT-SERVER-OPERATION">/PortInterfaces/FreeRunningTimer_I/IsTimerElapsed</TARGET-PROVIDED-OPERATION-REF>
47+
</OPERATION-IREF>
48+
</OPERATION-INVOKED-EVENT>
49+
</EVENTS>
50+
<RUNNABLES>
51+
<RUNNABLE-ENTITY>
52+
<SHORT-NAME>TimerComponent_Init</SHORT-NAME>
53+
</RUNNABLE-ENTITY>
54+
<RUNNABLE-ENTITY>
55+
<SHORT-NAME>TimerComponent_GetTime</SHORT-NAME>
56+
<REENTRANCY-LEVEL>NON-REENTRANT</REENTRANCY-LEVEL>
57+
</RUNNABLE-ENTITY>
58+
<RUNNABLE-ENTITY>
59+
<SHORT-NAME>TimerComponent_IsTimerElapsed</SHORT-NAME>
60+
<REENTRANCY-LEVEL>NON-REENTRANT</REENTRANCY-LEVEL>
61+
</RUNNABLE-ENTITY>
62+
</RUNNABLES>
2863
</SWC-INTERNAL-BEHAVIOR>
2964
</INTERNAL-BEHAVIORS>
3065
</APPLICATION-SW-COMPONENT-TYPE>

0 commit comments

Comments
 (0)