Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7aea043171d6fe1b596dbd55d70ccb48233ae24d (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
RoomModel TrafficlightModel {
	
	import room.basic.types.* from "../../../org.eclipse.etrice.modellib.java/model/Types.room"
	import room.basic.service.timing.* from "../../../org.eclipse.etrice.modellib.java/model/TimingService.room"
	import room.basic.service.tcp.* from "../../../org.eclipse.etrice.modellib.java/model/TcpService.room"
	
	LogicalSystem TrafficlightLogSys {
		SubSystemRef subsystem:SubSys 
	}
	SubSystemClass SubSys {
		ActorRef application:Application
		ActorRef timingService: ATimingService
		LayerConnection ref application satisfied_by timingService.timer
		LogicalThread defaultThread
	}
	ActorClass Application {
		Structure {
			ActorRef controller: TrafficLightController
			ActorRef coordinator: TrafficLightCoordinator
			ActorRef tsCommands: TrafficLightCommands
			Binding coordinator.controller and controller.fct
			Binding controller.tlCommands and tsCommands.fct
		}
		Behavior { }
	}
	
	ActorClass TrafficLightCoordinator {
		Interface {
			conjugated Port controller [*]: PTrafficLightController
		}
		Structure {
			external Port controller
			SAP timeout: PTimer
			
		}
		Behavior {
			StateMachine {
				Transition init: initial -> Idle { }
				Transition tr0: Idle -> Running {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr1: Running -> Off {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr2: Off -> Running {
					triggers {
						<timeout: timeout>
					}
				}
				State Idle {
					entry {
						"timeout.startTimeout(3000);"
					}
				}
				State Running {
					entry {
						"timeout.startTimeout(20000);"
						"controller.setOn();"
					}
				}
				State Off {
					entry {
						"timeout.startTimeout(20000);"
						"controller.setOff();"
					}
				}
			}
		}
	}

	ActorClass TrafficLightController {
		Interface {
			Port fct: PTrafficLightController
			conjugated Port tlCommands: PTrafficLightCommands
		}
		Structure {
			external Port fct
			external Port tlCommands
			SAP timeout: PTimer
		}
		Behavior {
			StateMachine {
				Transition init: initial -> InitCommands { }
				Transition tr0: InitCommands -> tp0 of Blinking {
					triggers {
						<doneInit: tlCommands>
					}
				}
				Transition tr1: Blinking -> tp0 of Working {
					triggers {
						<setOn: fct>
					}
				}
				Transition tr2: Working -> tp0 of Blinking {
					triggers {
						<setOff: fct>
					}
				}
				State InitCommands {
					entry {
						"tlCommands.startInit();"
					}
				}
				State Blinking {
					entry {
						"tlCommands.carYellow();"
					}
					exit {
						"timeout.kill();"
					}
					subgraph {
						Transition tr0: my tp0 -> On
						Transition tr1: On -> Off {
							triggers {
								<timeout: timeout>
							}
						}
						Transition tr2: Off -> On {
							triggers {
								<timeout: timeout>
							}
						}
						EntryPoint tp0
						State On {
							entry {
								"tlCommands.carYellow();"
								"tlCommands.pedRed();"
								"timeout.startTimeout(500);"
							}
							exit {
								"tlCommands.carOff();"
								"tlCommands.pedOff();"
							}
						}
						State Off {
							entry {
								"timeout.startTimeout(500);"
							}
						}
					}
				}
				State Working {
					subgraph {
						Transition tr0: my tp0 -> AllRed
						Transition tr1: AllRed -> CarGreen {
							triggers {
								<timeout: timeout>
							}
						}
						Transition tr2: PedGreen -> AllRed {
							triggers {
								<timeout: timeout>
							}
						}
						Transition tr3: CarGreen -> CarYellow {
							triggers {
								<timeout: timeout>
							}
						}
						Transition tr4: CarYellow -> CarRed {
							triggers {
								<timeout: timeout>
							}
						}
						Transition tr5: CarRed -> PedGreen {
							triggers {
								<timeout: timeout>
							}
						}
						EntryPoint tp0
						State AllRed {
							entry {
								"tlCommands.carRed();"
								"tlCommands.pedRed();"
								"timeout.startTimeout(1000);"
							}
						}
						State CarGreen {
							entry {
								"tlCommands.carGreen();"
								"timeout.startTimeout(3000);"
							}
						}
						State CarYellow {
							entry {
								"tlCommands.carYellow();"
								"timeout.startTimeout(1000);"
							}
						}
						State CarRed {
							entry {
								"tlCommands.carRed();"
								"timeout.startTimeout(1000);"
							}
						}
						State PedGreen {
							entry {
								"tlCommands.pedGreen();"
								"timeout.startTimeout(3000);"
							}
						}
					}
				}
			}
		}
	}
	
	ActorClass TrafficLightCommands {
		Interface {
			Port fct: PTrafficLightCommands
		}
		Structure {
			external Port fct
			conjugated Port socketControl: PTcpControl
			conjugated Port socketPayload: PTcpPayload
			ActorRef socket: ATcpClient
			Binding socketPayload and socket.PayloadPort
			Binding socketControl and socket.ControlPort
			Attribute socketConfig: DTcpControl
			
		}
		Behavior {
			StateMachine {
				Transition init: initial -> NotInitialized {
					action {
						"socketConfig = new DTcpControl(\"localhost\", 4441);"
					}
				}
				Transition tr0: ConfigSocket -> SocketOpen {
					triggers {
						<established: socketControl>
					}
					action {
						"fct.doneInit();"
					}
				}
				Transition tr1: SocketOpen -> SocketOpen {
					triggers {
						<carRed: fct>
					}
					action {
						"String payload = new String(\"carLights=red\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr2: SocketOpen -> SocketOpen {
					triggers {
						<carYellow: fct>
					}
					action {
						"String payload = new String(\"carLights=yellow\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr3: SocketOpen -> SocketOpen {
					triggers {
						<carGreen: fct>
					}
					action {
						"String payload = new String(\"carLights=green\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr4: SocketOpen -> SocketOpen {
					triggers {
						<carOff: fct>
					}
					action {
						"String payload = new String(\"carLights=off\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr5: SocketOpen -> SocketOpen {
					triggers {
						<pedRed: fct>
					}
					action {
						"String payload = new String(\"pedLights=red\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr6: SocketOpen -> SocketOpen {
					triggers {
						<pedGreen: fct>
					}
					action {
						"String payload = new String(\"pedLights=green\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr7: SocketOpen -> SocketOpen {
					triggers {
						<pedOff: fct>
					}
					action {
						"String payload = new String(\"pedLights=off\\n\");"
						"socketPayload.send(new DTcpPayload(0, payload.length(), payload.getBytes() ));"
					}
				}
				Transition tr8: SocketOpen -> SocketOpen {
					triggers {
						<receive: socketPayload>
					}
					action {
						"fct.pressedButton();"
					}
				}
				Transition tr9: NotInitialized -> ConfigSocket {
					triggers {
						<startInit: fct>
					}
				}
				State ConfigSocket {
					entry {
						"socketControl.open(socketConfig);"
						""
						"System.out.println(\"ConfigSocket: open\");"
					}
				}
				State SocketOpen
				State NotInitialized
			}
		}
	}

	ProtocolClass PTrafficLightController {
		incoming {
			Message setOn()
			Message setOff()
		}
	}

	ProtocolClass PTrafficLightCommands {
		incoming {
			Message startInit()
			
			Message carRed()
			Message carYellow()
			Message carYellowRed()
			Message carGreen()
			Message carOff()
			
			Message pedRed()
			Message pedGreen()
			Message pedOff()
			
		}
		outgoing {
			Message doneInit()

			Message pressedButton()
		}
	}
}

Back to the top