Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a09c80c0ed7e621ccd80949d6ca0bf74601bb3c9 (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
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 commands: TrafficLightCommands
			ActorRef controller: TrafficLightController
			Binding controller.tlCommands and commands.fct
		}
		Behavior { }
	}
	
	ActorClass TrafficLightController {
		Interface {
			conjugated Port tlCommands: PTrafficLightCommands
		}
		Structure {
			external Port tlCommands
			SAP timeout: PTimer
			
		}
		Behavior {
			StateMachine {
				Transition init: initial -> InitCommands { }
				Transition tr0: InitCommands -> tp0 of Blinking {
					triggers {
						<doneInit: tlCommands>
					}
				}
				State InitCommands {
					entry {
						"tlCommands.startInit();"
					}
				}
				State Blinking {
					entry {
						"tlCommands.carYellow();"
					}
					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();"
								"timeout.startTimeout(500);"
							}
							exit {
								"tlCommands.carOff();"
							}
						}
						State Off {
							entry {
								"timeout.startTimeout(500);"
							}
						}
					}
				}
			}
		}
	}
	
	ActorClass TrafficLightCommands {
		Interface {
			Port fct: PTrafficLightCommands
		}
		Structure {
			external Port fct
			conjugated Port socketControl: PTcpControl
			conjugated Port socketPayload: PTcpPayload
			ActorRef socket: ATcpClient
			Binding socketControl and socket.ControlPort
			Binding socketPayload and socket.PayloadPort
			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);"
					}
				}
				State SocketOpen
				State NotInitialized
			}
		}
	}
	
	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