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" SubSystemClass SSTraffic { ActorRef application: Application ActorRef TimingService: ATimingService LayerConnection ref application satisfied_by TimingService.timer } ActorClass Application { Structure { ActorRef light1: TrafficLight ActorRef light2: TrafficLight ActorRef controller: TrafficController Binding controller.light1 and light1.controller Binding controller.light2 and light2.controller } Behavior { } } ActorClass TrafficController { Interface { conjugated Port light1: PTrafficLight conjugated Port light2: PTrafficLight } Structure { external Port light1 external Port light2 SAP timeout: PTimer } Behavior { StateMachine { Transition init: initial -> Idle { } Transition tr0: Idle -> SwitchToLight1GreenForCars { triggers { } } Transition tr1: SwitchToLight1GreenForCars -> state0 { triggers { } } Transition tr2: SwitchToLight1GreenForCars -> state1 { triggers { } } Transition tr3: state1 -> Light1GreenForCars { triggers { } } Transition tr4: state0 -> Light1GreenForCars { triggers { } } Transition tr5: Light1GreenForCars -> SwitchToLight2GreenForCars { triggers { } } Transition tr6: SwitchToLight2GreenForCars -> state2 { triggers { } } Transition tr7: SwitchToLight2GreenForCars -> state3 { triggers { } } Transition tr8: state2 -> Light2GreenForCars { triggers { } } Transition tr9: state3 -> Light2GreenForCars { triggers { } } Transition tr10: Light2GreenForCars -> SwitchToLight1GreenForCars { triggers { } } 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 { 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 ActorRef trafficLightSocket: ATcpClient Binding trafficLightSocket.ControlPort and tcpCtrl Binding trafficLightSocket.PayloadPort and tcpPayload } Behavior { Operation sendString(text: string) { " 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 { } } Transition tr2: Off_Blinking -> PedRed { triggers { } } Transition tr3: PedRed -> CarYellow { triggers { } } Transition tr1: CarYellow -> CarGreen { triggers { } } Transition tr4: Off_Blinking -> CarYellow2 { triggers { } } Transition tr5: CarYellow2 -> CarRed { triggers { } } Transition tr6: CarRed -> PedGreen { triggers { } } Transition tr7: PedGreen -> PedRed { triggers { } } Transition tr8: CarGreen -> CarYellow2 { triggers { } } 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 { } } Transition tr2: Off -> On { triggers { } } 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() Message greenForPed() } outgoing { Message greenForCarDone() Message greenForPedDone() } } }