Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 025dad81d81372b4db2bb6bbf162236ad10bc726 (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
/*******************************************************************************
 * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Thomas Schuetz (initial contribution)
 * 
 *******************************************************************************/


RoomModel trafficlight.example {

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

	import room.basic.service.timing.* from "../../org.eclipse.etrice.modellib.java/models/TimingService.room"

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

	LogicalSystem LSTraffic {
		SubSystemRef main: SSTraffic
	}
	
	SubSystemClass SSTraffic ["Subsystem of Trafficlight Example Application. The Subsystem contains all Actors of the application."] {
		ActorRef application: TrafficlightExampleApplication ["reference to application"]
		ActorRef TimingService: ATimingService ["reference to timing service"]
		LayerConnection ref application satisfied_by TimingService.timer 
	
		LogicalThread dflt_thread
	}

	ActorClass TrafficlightExampleApplication ["Toplevel Actor of the Trafficlight Example Application."]{
		Structure {
			
			ActorRef light1: TrafficLight ["first traffic light"]
			ActorRef light2: TrafficLight ["second traffic light"]
			ActorRef controller: TrafficController ["controller for coordination of the traffic lights"]
			Binding controller.light1 and light1.controller 
			Binding controller.light2 and light2.controller
		}
		Behavior { }
	}

	ActorClass TrafficController ["The TrafficController coordinates two traffic lights (directions)."] {
		Interface {
			conjugated Port light1: PTrafficLight ["port to control traffic light 1"]
			conjugated Port light2: PTrafficLight ["port to control traffic light 2"]
		}
		Structure {
			external Port light1 
			external Port light2 
			SAP timeout: PTimer
		}
		Behavior {
			StateMachine {
				Transition init: initial -> Idle { }
				Transition tr0: Idle -> SwitchToLight1GreenForCars {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr1: SwitchToLight1GreenForCars -> state0 {
					triggers {
						<greenForCarDone: light1>
					}
				}
				Transition tr2: SwitchToLight1GreenForCars -> state1 {
					triggers {
						<greenForPedDone: light2>
					}
				}
				Transition tr3: state1 -> Light1GreenForCars {
					triggers {
						<greenForCarDone: light1>
					}
				}
				Transition tr4: state0 -> Light1GreenForCars {
					triggers {
						<greenForPedDone: light2>
					}
				}
				Transition tr5: Light1GreenForCars -> SwitchToLight2GreenForCars {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr6: SwitchToLight2GreenForCars -> state2 {
					triggers {
						<greenForPedDone: light1>
					}
				}
				Transition tr7: SwitchToLight2GreenForCars -> state3 {
					triggers {
						<greenForCarDone: light2>
					}
				}
				Transition tr8: state2 -> Light2GreenForCars {
					triggers {
						<greenForCarDone: light2>
					}
				}
				Transition tr9: state3 -> Light2GreenForCars {
					triggers {
						<greenForPedDone: light1>
					}
				}
				Transition tr10: Light2GreenForCars -> SwitchToLight1GreenForCars {
					triggers {
						<timeout: timeout>
					}
				}
				State Idle {
					entry {
						"timeout.startTimeout(3000);"
					}
				}
				State Light1GreenForCars {
					entry {
						"timeout.startTimeout(10000);"
					}
				}
				State SwitchToLight1GreenForCars {
					entry {
						"light1.greenForCar();"
						"light2.greenForPed();"
					}
				}
				State state0
				State state1
				State SwitchToLight2GreenForCars {
					entry {
						"light1.greenForPed();"
						"light2.greenForCar();"
					}
				}
				State state2
				State state3
				State Light2GreenForCars {
					entry {
						"timeout.startTimeout(10000);"
					}
				}
			}
		}
	}

	ActorClass TrafficLight ["This Actor is responsible for controlling a single traffic light via socket. It uses a socket client for communication."] {
		Interface {
			Port controller: PTrafficLight
		}
		Structure {
			external Port controller
			conjugated Port tcpCtrl: PTcpControl
			conjugated Port tcpPayload: PTcpPayload
			SAP timeout: PTimer
			SAP blinkerTimeout: PTimer 
			Attribute ipConfig: DTcpControl ["configuration of the IP-port for the communication with the Traffic Light GUI"]
			ActorRef trafficLightSocket: ATcpClient
			Binding trafficLightSocket.ControlPort and tcpCtrl
			Binding trafficLightSocket.PayloadPort and tcpPayload
		}
		Behavior {
			Operation sendString(text: string)["convenience function for sending a string over the socket"] {
			"
				DTcpPayload pl = new DTcpPayload();
				pl.setData(text.getBytes());
				tcpPayload.send(new DTcpPayload(1, text.length(), text.getBytes()));
			"
			}
			StateMachine  {
				Transition init: initial -> OpenSocket { }
				Transition tr0: OpenSocket -> tp0 of Off_Blinking {
					triggers {
						<established: tcpCtrl>
					}
				}
				Transition tr2: Off_Blinking -> PedRed {
					triggers {
						<greenForCar: controller>
					}
				}
				Transition tr3: PedRed -> CarYellow {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr1: CarYellow -> CarGreen {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr4: Off_Blinking -> CarYellow2 {
					triggers {
						<greenForPed: controller>
					}
				}
				Transition tr5: CarYellow2 -> CarRed {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr6: CarRed -> PedGreen {
					triggers {
						<timeout: timeout>
					}
				}
				Transition tr7: PedGreen -> PedRed {
					triggers {
						<greenForCar: controller>
					}
				}
				Transition tr8: CarGreen -> CarYellow2 {
					triggers {
						<greenForPed: controller>
					}
				}
				State OpenSocket {
					entry {
						"tcpCtrl.open(ipConfig);"
					}
				}
				State CarYellow {
					entry {
						"sendString(\"carLights=yellow\\n\");"
						"timeout.startTimeout(1000);"
					}
				}
				State PedRed {
					entry {
						"sendString(\"pedLights=red\\n\");"
						"sendString(\"carLights=red\\n\");"
						"timeout.startTimeout(1000);"
					}
				}
				State CarGreen {
					entry {
						"sendString(\"carLights=green\\n\");"
						"controller.greenForCarDone();"
					}
				}
				State Off_Blinking {
					subgraph {
						Transition tr0: my tp0 -> On
						Transition tr1: On -> Off {
							triggers {
								<timeout: blinkerTimeout>
							}
						}
						Transition tr2: Off -> On {
							triggers {
								<timeout: blinkerTimeout>
							}
						}
						EntryPoint tp0
						State On {
							entry {
								"sendString(\"carLights=red\\n\");"
								"sendString(\"pedLights=red\\n\");"
								"blinkerTimeout.startTimeout(500);"
							}
							exit {
								"sendString(\"carLights=off\\n\");"
								"sendString(\"pedLights=off\\n\");"
							}
						}
						State Off {
							entry {
								"blinkerTimeout.startTimeout(500);"
							}
						}
					}
				}
				State CarYellow2 {
					entry {
						"sendString(\"carLights=yellow\\n\");"
						"timeout.startTimeout(1000);"
					}
				}
				State CarRed {
					entry {
						"sendString(\"carLights=red\\n\");"
						"timeout.startTimeout(1000);"
					}
				}
				State PedGreen {
					entry {
						"sendString(\"pedLights=green\\n\");"
						"controller.greenForPedDone();"
					}
				}
			}
		}
	}

	ProtocolClass PTrafficLight {
		incoming {
			Message greenForCar() ["trigger green for car"]
			Message greenForPed() ["trigger green for pedestrians"]
		}
		outgoing {
			Message greenForCarDone() ["positive response for greenForCar - is sent when switch is over"]
			Message greenForPedDone() ["positive response for greenForPed - is sent when switch is over"]
		}
	}

}

Back to the top