Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d3b1a8bafab6c3fb3db02b5a97e9d44962a07581 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
RoomModel trafficlight.connector {

	import room.basic.service.tcp.* from "../../../org.eclipse.etrice.modellib.java/model/TcpService.room"

	import room.basic.types.* from "../../../org.eclipse.etrice.modellib.java/model/Types.room"

	ActorClass TrafficLightInterface {
		Interface {
			conjugated Port payload: PTcpPayload
			conjugated Port control: PTcpControl
			Port fct: PTrafficLightInterface
		}
		Structure {
			external Port payload
			external Port control
			external Port fct
			Attribute tcpConfig : DTcpControl
		}
		Behavior {
			Operation sendString(data: string) {
				"payload.send(new DTcpPayload(1, data.length(), data.getBytes()));"
			}
			
			StateMachine {
				Transition init: initial -> Uninitialized { }
				Transition tr0: Uninitialized -> Initializing {
					triggers {
						<initialize: fct>
					}
					action {
						"control.open(tcpConfig);"
					}
				}
				Transition tr1: Initializing -> Running {
					triggers {
						<established: control>
					}
					action {
						"fct.initialized();"
					}
				}
				Transition tr2: Running -> Running {
					triggers {
						<pedRed: fct>
					}
					action {
						"sendString(new String(\"pedLights=red\\n\"));"
					}
				}
				Transition tr3: Running -> Running {
					triggers {
						<pedOff: fct>
					}
					action {
						"sendString(new String(\"pedLights=off\\n\"));"
					}
				}
				Transition tr4: Running -> Running {
					triggers {
						<pedGreen: fct>
					}
					action {
						"sendString(new String(\"pedLights=green\\n\"));"
					}
				}
				Transition tr5: Running -> Running {
					triggers {
						<carRed: fct>
					}
					action {
						"sendString(new String(\"carLights=red\\n\"));"
					}
				}
				Transition tr6: Running -> Running {
					triggers {
						<carYellow: fct>
					}
					action {
						"sendString(new String(\"carLights=yellow\\n\"));"
					}
				}
				Transition tr7: Running -> Running {
					triggers {
						<carGreen: fct>
					}
					action {
						"sendString(new String(\"carLights=green\\n\"));"
					}
				}
				Transition tr8: Running -> Running {
					triggers {
						<carOff: fct>
					}
					action {
						"sendString(new String(\"carLights=off\\n\"));"
					}
				}
				Transition tr9: Running -> Running {
					triggers {
						<receive: payload>
					}
					action {
						"fct.request();"
					}
				}
				State Uninitialized
				State Initializing
				State Running
			}
		}
	}

	ActorClass MqttWrapperActor {
		Interface {
			Port fct: PMqtt
		}
		Structure {
			
			usercode1 {"import de.protos.etrice.automation.m2m.mqtt.*;"}
			external Port fct
			Attribute connectionMQTT : MqttWrapper
			Attribute open : boolean
		}
		Behavior {
			Operation ~MqttWrapperActor(){
				"connectionMQTT.disconnect();"
			}
			
			StateMachine {
				Transition init: initial -> NotInitialized { }
				Transition tr0: NotInitialized -> cp cp0 {
					triggers {
						<connect: fct>
					}
					action {
						"open=false;"
						"connectionMQTT.connect(config.url, config.id);"
						"//connectionMQTT.connect(new DMqttConfig(\"tcp://m2m.eclipse.org:1883\", \"eTrice-Paho-Tester\"));"
						"open=true;"
					}
				}
				Transition tr1: cp cp0 -> NotInitialized
				Transition tr2: cp cp0 -> Connected {
					cond {
						"open==true"
					}
					action {
						"fct.connected();"
					}
				}
				Transition tr3: Connected -> Connected {
					triggers {
						<publish: fct>
					}
					action {
						"connectionMQTT.publishString(message.topic, message.payload, message.retained, message.qos);"
					}
				}
				ChoicePoint cp0
				State NotInitialized
				State Connected
			}
		}
	}

	ProtocolClass PTrafficLightInterface {
		incoming {
			Message initialize()
			Message pedRed()
			Message pedGreen()
			Message pedOff()
			Message carRed()
			Message carYellow()
			Message carGreen()
			Message carOff()
		}
		outgoing {
			Message initialized()
			Message request()
		}
	}

	ProtocolClass PMqtt {
		incoming {
			Message connect(config: DMqttConfig)
			Message publish(message: DMqttMessage)
		}
		outgoing  {
			Message connected ()
		}
	}

	DataClass DMqttConfig {
			Attribute url : string
			Attribute id : string
	}
	
	DataClass DMqttMessage {
		Attribute topic : string
		Attribute payload : string
		Attribute retained : boolean
		Attribute qos : int32
	}

	ExternalType MqttWrapper -> MqttWrapper
}

Back to the top