Przeglądaj źródła

fixed functional issues with the traffic light example.
fixed issues #569 #562 #561 #551

Axel Terfloth 9 lat temu
rodzic
commit
f2011e42db

+ 2 - 2
examples/traffic_light/.project

@@ -21,12 +21,12 @@
 			</arguments>
 		</buildCommand>
 		<buildCommand>
-			<name>org.yakindu.sct.builder.SCTBuilder</name>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
 			<arguments>
 			</arguments>
 		</buildCommand>
 		<buildCommand>
-			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<name>org.yakindu.sct.builder.SCTBuilder</name>
 			<arguments>
 			</arguments>
 		</buildCommand>

Plik diff jest za duży
+ 192 - 163
examples/traffic_light/model/TrafficLightCtrl.sct


+ 5 - 0
examples/traffic_light/model/TrafficLightCtrl.sgen

@@ -17,6 +17,11 @@ GeneratorModel for yakindu::java {
 			TimerService = true
 		}
 		
+		feature RunnableWrapper {
+			namePrefix =  "" 
+			nameSuffix =  "Runnable" 
+		}
+		
 		feature LicenseHeader {
 			licenseText = "
 Copyright (c) 2012-2015 committers of YAKINDU and others.

+ 279 - 0
examples/traffic_light/src-gen/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.java

@@ -0,0 +1,279 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+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:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light.trafficlightctrl;
+import traffic.light.ITimer;
+import traffic.light.ITimerCallback;
+import traffic.light.trafficlightctrl.TrafficLightCtrlStatemachine.State;
+
+/**
+ * Runnable wrapper of TrafficLightCtrlStatemachine. This wrapper provides a thread-safe
+ * instance of the state machine.
+ * 
+ * Please report bugs and issues...
+ */
+
+public class SynchronizedTrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine {
+	
+	/**
+	 * The core state machine is simply wrapped and the event processing will be
+	 * delegated to that state machine instance. This instance will be created
+	 * implicitly.
+	 */
+	protected TrafficLightCtrlStatemachine statemachine = new TrafficLightCtrlStatemachine();
+	
+	/**
+	 * Interface object for SCITrafficLight
+	 */		
+	protected class SynchronizedSCITrafficLight implements SCITrafficLight {
+		
+		public boolean getRed() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getRed();
+			}
+		}
+		
+		public void setRed(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setRed(value);
+			}
+		}
+		
+		public boolean getYellow() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getYellow();
+			}
+		}
+		
+		public void setYellow(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setYellow(value);
+			}
+		}
+		
+		public boolean getGreen() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getGreen();
+			}
+		}
+		
+		public void setGreen(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setGreen(value);
+			}
+		}
+		
+	};
+	
+	protected SCITrafficLight sCITrafficLight;
+	
+	/**
+	 * Interface object for SCIPedestrian
+	 */		
+	protected class SynchronizedSCIPedestrian implements SCIPedestrian {
+		
+		public boolean getRequest() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getRequest();
+			}
+		}
+		
+		public void setRequest(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setRequest(value);
+			}
+		}
+		
+		public boolean getRed() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getRed();
+			}
+		}
+		
+		public void setRed(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setRed(value);
+			}
+		}
+		
+		public boolean getGreen() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getGreen();
+			}
+		}
+		
+		public void setGreen(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setGreen(value);
+			}
+		}
+		
+	};
+	
+	protected SCIPedestrian sCIPedestrian;
+	
+	/**
+	 * Interface object for SCInterface
+	 */		
+	protected class SynchronizedSCInterface implements SCInterface {
+		
+		public void setSCInterfaceOperationCallback(SCInterfaceOperationCallback operationCallback) {
+			synchronized(statemachine) {
+				statemachine.getSCInterface().setSCInterfaceOperationCallback(operationCallback);
+			}
+		}
+		
+		public void raisePedestrianRequest() {
+			
+			synchronized (statemachine) {
+				statemachine.getSCInterface().raisePedestrianRequest();
+				statemachine.runCycle();
+			}
+		}
+		
+		public void raiseOnOff() {
+			
+			synchronized (statemachine) {
+				statemachine.getSCInterface().raiseOnOff();
+				statemachine.runCycle();
+			}
+		}
+		
+	};
+	
+	protected SCInterface sCInterface;
+	
+	public SynchronizedTrafficLightCtrlStatemachine() {
+		sCITrafficLight = new SynchronizedSCITrafficLight();
+		sCIPedestrian = new SynchronizedSCIPedestrian();
+		sCInterface = new SynchronizedSCInterface();
+	}
+	
+	public synchronized SCITrafficLight getSCITrafficLight() {
+		return sCITrafficLight;
+	}
+	public synchronized SCIPedestrian getSCIPedestrian() {
+		return sCIPedestrian;
+	}
+	public synchronized SCInterface getSCInterface() {
+		return sCInterface;
+	}
+	/*================ TIME EVENT HANDLING ================
+	
+	/** An external timer instance is required. */
+	protected ITimer externalTimer;
+	
+	/** Internally we use a timer proxy that queues time events together with other input events. */
+	protected ITimer timerProxy = new ITimer() {
+		/** Simply delegate to external timer with a modified callback. */
+		@Override
+		public void setTimer(ITimerCallback callback, int eventID, long time,
+				boolean isPeriodic) {
+			externalTimer.setTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID, time, isPeriodic);
+		}
+		
+		@Override
+		public void unsetTimer(ITimerCallback callback, int eventID) {
+			externalTimer.unsetTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID);
+		}
+	};
+	
+	/**
+	 * Set the {@link ITimer} for the state machine. It must be set externally
+	 * on a timed state machine before a run cycle can be correct executed.
+	 * 
+	 * @param timer
+	 */
+	public void setTimer(ITimer timer) {
+		synchronized(statemachine) {
+			this.externalTimer = timer;
+			/* the wrapped state machine uses timer proxy as timer */
+			statemachine.setTimer(timerProxy);
+		}
+	}
+	
+	/**
+	* Returns the currently used timer.
+	* 
+	* @return {@link ITimer}
+	*/
+	public ITimer getTimer() {
+		return externalTimer;
+	}
+	
+	public void timeElapsed(int eventID) {
+		synchronized (statemachine) {
+			statemachine.timeElapsed(eventID);
+		}
+	}
+	
+	/**
+	 * init() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void init() {
+		synchronized(statemachine) {
+			statemachine.init();
+		}
+	}
+	
+	/**
+	 * enter() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void enter() {
+		synchronized(statemachine) {
+			statemachine.enter();
+		}
+	}
+	
+	/**
+	 * exit() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void exit() {
+		synchronized(statemachine) {
+			statemachine.exit();
+		}
+	}
+	
+	/**
+	 * isActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isActive() {
+		synchronized(statemachine) {
+			return statemachine.isActive();
+		}
+	}
+	
+	/**
+	 * isFinal() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isFinal() {
+		synchronized(statemachine) {
+			return statemachine.isFinal();
+		}
+	}
+	
+	/**
+	 * isStateActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isStateActive(State state) {
+		synchronized(statemachine) {
+			return statemachine.isStateActive(state);
+		}
+	}
+	
+	/**
+	 * runCycle() will be delegated thread-safely to the wrapped state machine.
+	 */ 
+	@Override
+	public void runCycle() {
+		synchronized (statemachine) {
+			statemachine.runCycle();
+		}
+	}
+}

+ 134 - 22
examples/traffic_light/src-gen/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.java

@@ -116,7 +116,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 	private boolean initialized = false;
 
 	public enum State {
-		main_region_on, main_region_on_r1_StreetGreen, main_region_on_r1_PedWaiting, main_region_on_r1_PedWaiting_r1_waitOn, main_region_on_r1_PedWaiting_r1_waitOff, main_region_on_r1_StreetAttention, main_region_on_r1_StreetRed, main_region_on_r1_PedestrianGreen, main_region_on_r1_PedestrianRed, main_region_on_r1_StreetPrepare, main_region_off, main_region_off_r1_YellowOn, main_region_off_r1_YellowOff, $NullState$
+		main_region_on, main_region_on_r1_StreetGreen, main_region_on_r1_PedWaiting, main_region_on_r1_PedWaiting_r1_waitOn, main_region_on_r1_PedWaiting_r1_waitOff, main_region_on_r1_StreetAttention, main_region_on_r1_StreetRed, main_region_on_r1_PedestrianGreen, main_region_on_r1_PedestrianRed, main_region_on_r1_StreetPrepare, main_region_on_r1_Safe, main_region_off, main_region_off_r1_YellowOn, main_region_off_r1_YellowOff, $NullState$
 	};
 
 	private final State[] stateVector = new State[1];
@@ -125,7 +125,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	private ITimer timer;
 
-	private final boolean[] timeEvents = new boolean[10];
+	private final boolean[] timeEvents = new boolean[12];
 
 	public TrafficLightCtrlStatemachine() {
 
@@ -167,11 +167,15 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		if (timer == null) {
 			throw new IllegalStateException("timer not set.");
 		}
+		entryAction();
+
 		enterSequence_main_region_default();
 	}
 
 	public void exit() {
 		exitSequence_main_region();
+
+		exitAction();
 	}
 
 	/**
@@ -215,7 +219,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		switch (state) {
 			case main_region_on :
 				return stateVector[0].ordinal() >= State.main_region_on.ordinal()
-						&& stateVector[0].ordinal() <= State.main_region_on_r1_StreetPrepare.ordinal();
+						&& stateVector[0].ordinal() <= State.main_region_on_r1_Safe.ordinal();
 			case main_region_on_r1_StreetGreen :
 				return stateVector[0] == State.main_region_on_r1_StreetGreen;
 			case main_region_on_r1_PedWaiting :
@@ -235,6 +239,8 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 				return stateVector[0] == State.main_region_on_r1_PedestrianRed;
 			case main_region_on_r1_StreetPrepare :
 				return stateVector[0] == State.main_region_on_r1_StreetPrepare;
+			case main_region_on_r1_Safe :
+				return stateVector[0] == State.main_region_on_r1_Safe;
 			case main_region_off :
 				return stateVector[0].ordinal() >= State.main_region_off.ordinal()
 						&& stateVector[0].ordinal() <= State.main_region_off_r1_YellowOff.ordinal();
@@ -289,7 +295,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 	}
 
 	private boolean check__lr0() {
-		return true;
+		return timeEvents[11];
 	}
 
 	private boolean check_main_region_on_tr0_tr0() {
@@ -332,16 +338,20 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		return timeEvents[7];
 	}
 
+	private boolean check_main_region_on_r1_Safe_tr0_tr0() {
+		return timeEvents[8];
+	}
+
 	private boolean check_main_region_off_tr0_tr0() {
 		return sCInterface.onOff;
 	}
 
 	private boolean check_main_region_off_r1_YellowOn_tr0_tr0() {
-		return timeEvents[8];
+		return timeEvents[9];
 	}
 
 	private boolean check_main_region_off_r1_YellowOff_tr0_tr0() {
-		return timeEvents[9];
+		return timeEvents[10];
 	}
 
 	private void effect__lr0() {
@@ -408,6 +418,12 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		enterSequence_main_region_on_r1_StreetGreen_default();
 	}
 
+	private void effect_main_region_on_r1_Safe_tr0() {
+		exitSequence_main_region_on_r1_Safe();
+
+		enterSequence_main_region_on_r1_StreetPrepare_default();
+	}
+
 	private void effect_main_region_off_tr0() {
 		exitSequence_main_region_off();
 
@@ -426,6 +442,12 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		enterSequence_main_region_off_r1_YellowOn_default();
 	}
 
+	/* Entry action for statechart 'TrafficLightCtrl'. */
+	private void entryAction() {
+
+		timer.setTimer(this, 11, 200, true);
+	}
+
 	/* Entry action for state 'StreetGreen'. */
 	private void entryAction_main_region_on_r1_StreetGreen() {
 		sCITrafficLight.setRed(false);
@@ -519,6 +541,24 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		sCITrafficLight.setGreen(false);
 	}
 
+	/* Entry action for state 'Safe'. */
+	private void entryAction_main_region_on_r1_Safe() {
+
+		timer.setTimer(this, 8, 10 * 1000, false);
+
+		sCITrafficLight.setRed(true);
+
+		sCITrafficLight.setYellow(false);
+
+		sCITrafficLight.setGreen(false);
+
+		sCIPedestrian.setRed(true);
+
+		sCIPedestrian.setGreen(false);
+
+		sCIPedestrian.setRequest(false);
+	}
+
 	/* Entry action for state 'off'. */
 	private void entryAction_main_region_off() {
 		sCITrafficLight.setRed(false);
@@ -535,7 +575,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 	/* Entry action for state 'YellowOn'. */
 	private void entryAction_main_region_off_r1_YellowOn() {
 
-		timer.setTimer(this, 8, 500, false);
+		timer.setTimer(this, 9, 500, false);
 
 		sCITrafficLight.setYellow(true);
 
@@ -545,13 +585,18 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 	/* Entry action for state 'YellowOff'. */
 	private void entryAction_main_region_off_r1_YellowOff() {
 
-		timer.setTimer(this, 9, 500, false);
+		timer.setTimer(this, 10, 500, false);
 
 		sCITrafficLight.setYellow(false);
 
 		sCIPedestrian.setRequest(false);
 	}
 
+	/* Exit action for state 'TrafficLightCtrl'. */
+	private void exitAction() {
+		timer.unsetTimer(this, 11);
+	}
+
 	/* Exit action for state 'PedWaiting'. */
 	private void exitAction_main_region_on_r1_PedWaiting() {
 		timer.unsetTimer(this, 0);
@@ -594,14 +639,19 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		timer.unsetTimer(this, 7);
 	}
 
+	/* Exit action for state 'Safe'. */
+	private void exitAction_main_region_on_r1_Safe() {
+		timer.unsetTimer(this, 8);
+	}
+
 	/* Exit action for state 'YellowOn'. */
 	private void exitAction_main_region_off_r1_YellowOn() {
-		timer.unsetTimer(this, 8);
+		timer.unsetTimer(this, 9);
 	}
 
 	/* Exit action for state 'YellowOff'. */
 	private void exitAction_main_region_off_r1_YellowOff() {
-		timer.unsetTimer(this, 9);
+		timer.unsetTimer(this, 10);
 	}
 
 	/* 'default' enter sequence for state on */
@@ -680,6 +730,14 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		stateVector[0] = State.main_region_on_r1_StreetPrepare;
 	}
 
+	/* 'default' enter sequence for state Safe */
+	private void enterSequence_main_region_on_r1_Safe_default() {
+		entryAction_main_region_on_r1_Safe();
+
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_on_r1_Safe;
+	}
+
 	/* 'default' enter sequence for state off */
 	private void enterSequence_main_region_off_default() {
 		entryAction_main_region_off();
@@ -797,6 +855,14 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		exitAction_main_region_on_r1_StreetPrepare();
 	}
 
+	/* Default exit sequence for state Safe */
+	private void exitSequence_main_region_on_r1_Safe() {
+		nextStateIndex = 0;
+		stateVector[0] = State.$NullState$;
+
+		exitAction_main_region_on_r1_Safe();
+	}
+
 	/* Default exit sequence for state off */
 	private void exitSequence_main_region_off() {
 		exitSequence_main_region_off_r1();
@@ -857,6 +923,10 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 				exitSequence_main_region_on_r1_StreetPrepare();
 				break;
 
+			case main_region_on_r1_Safe :
+				exitSequence_main_region_on_r1_Safe();
+				break;
+
 			case main_region_off_r1_YellowOn :
 				exitSequence_main_region_off_r1_YellowOn();
 				break;
@@ -909,6 +979,10 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 				exitSequence_main_region_on_r1_StreetPrepare();
 				break;
 
+			case main_region_on_r1_Safe :
+				exitSequence_main_region_on_r1_Safe();
+				break;
+
 			default :
 				break;
 		}
@@ -948,7 +1022,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state StreetGreen. */
 	private void react_main_region_on_r1_StreetGreen() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -961,7 +1037,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state waitOn. */
 	private void react_main_region_on_r1_PedWaiting_r1_waitOn() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -978,7 +1056,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state waitOff. */
 	private void react_main_region_on_r1_PedWaiting_r1_waitOff() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -995,7 +1075,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state StreetAttention. */
 	private void react_main_region_on_r1_StreetAttention() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -1008,7 +1090,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state StreetRed. */
 	private void react_main_region_on_r1_StreetRed() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -1021,7 +1105,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state PedestrianGreen. */
 	private void react_main_region_on_r1_PedestrianGreen() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -1034,7 +1120,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state PedestrianRed. */
 	private void react_main_region_on_r1_PedestrianRed() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -1047,7 +1135,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state StreetPrepare. */
 	private void react_main_region_on_r1_StreetPrepare() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
@@ -1058,9 +1148,26 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 		}
 	}
 
+	/* The reactions of state Safe. */
+	private void react_main_region_on_r1_Safe() {
+		if (check__lr0()) {
+			effect__lr0();
+		}
+
+		if (check_main_region_on_tr0_tr0()) {
+			effect_main_region_on_tr0();
+		} else {
+			if (check_main_region_on_r1_Safe_tr0_tr0()) {
+				effect_main_region_on_r1_Safe_tr0();
+			}
+		}
+	}
+
 	/* The reactions of state YellowOn. */
 	private void react_main_region_off_r1_YellowOn() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_off_tr0_tr0()) {
 			effect_main_region_off_tr0();
@@ -1073,7 +1180,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* The reactions of state YellowOff. */
 	private void react_main_region_off_r1_YellowOff() {
-		effect__lr0();
+		if (check__lr0()) {
+			effect__lr0();
+		}
 
 		if (check_main_region_off_tr0_tr0()) {
 			effect_main_region_off_tr0();
@@ -1086,7 +1195,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* Default react sequence for initial entry  */
 	private void react_main_region__entry_Default() {
-		enterSequence_main_region_on_default();
+		enterSequence_main_region_off_default();
 	}
 
 	/* Default react sequence for initial entry  */
@@ -1096,7 +1205,7 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 
 	/* Default react sequence for initial entry  */
 	private void react_main_region_on_r1__entry_Default() {
-		enterSequence_main_region_on_r1_StreetGreen_default();
+		enterSequence_main_region_on_r1_Safe_default();
 	}
 
 	/* Default react sequence for initial entry  */
@@ -1138,6 +1247,9 @@ public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachi
 				case main_region_on_r1_StreetPrepare :
 					react_main_region_on_r1_StreetPrepare();
 					break;
+				case main_region_on_r1_Safe :
+					react_main_region_on_r1_Safe();
+					break;
 				case main_region_off_r1_YellowOn :
 					react_main_region_off_r1_YellowOn();
 					break;

+ 96 - 0
examples/traffic_light/src/traffic/light/CrossWalkPanel.java

@@ -0,0 +1,96 @@
+package traffic.light;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Point;
+
+import javax.swing.JPanel;
+
+import traffic.light.TrafficLight.Alignment;
+
+public class CrossWalkPanel extends JPanel {
+
+	private static final long serialVersionUID = -7137708533029709629L;
+	protected TrafficLight trafficLight;
+	protected PedestrianLight pedLight;
+
+	
+	public CrossWalkPanel() {
+		super();
+		trafficLight = new TrafficLight(Alignment.HORIZONTAL);
+		pedLight = new PedestrianLight(PedestrianLight.Alignment.VERTICAL);
+	}
+	
+	public TrafficLight getTrafficLight() {
+		return trafficLight;
+	}
+
+	public PedestrianLight getPedLight() {
+		return pedLight;
+	}
+
+	public void paint(Graphics g) {
+		paintCrossing(g);
+		paintTrafficLights(g);
+		paintPedestrainLights(g);
+		g.dispose();
+	}
+
+	protected void paintPedestrainLights(Graphics g) {
+		pedLight.updatePosition(new Point(210, 80));
+		pedLight.paint(g);
+	}
+
+	protected void paintTrafficLights(Graphics g) {
+		trafficLight.updatePosition(new Point(170, 280));
+		trafficLight.paint(g);
+	}
+
+	protected void paintCrossing(Graphics g) {
+	
+		int width = getSize().width;
+
+		int streetYOffset = 150;
+		int streetWidth = 100;
+		
+		Dimension streetEastWest = new Dimension(width, streetWidth);
+		g.setColor(Color.darkGray);
+		paint(streetEastWest, 0, streetYOffset, true, g);
+
+		
+		g.setColor(Color.white);
+
+		Dimension laneSeparator = new Dimension(20, 4);
+		for (int i=0; i<4; i++) {
+			paint(laneSeparator, i * 2 * laneSeparator.width , streetYOffset -2 + streetWidth / 2, true, g);			
+		}
+
+		Dimension stopLine = new Dimension(10, streetWidth/2 +2);
+		paint(stopLine, 7 * laneSeparator.width , streetYOffset -2 + streetWidth / 2, true, g);			
+		
+		Dimension zebraStripe = new Dimension(80, 10);
+		
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 5, true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 25 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 45 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 65 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 85 , true, g);		
+		
+		
+		paint(stopLine, 11 * laneSeparator.width + zebraStripe.width - stopLine.width, streetYOffset, true, g);			
+
+		for (int i=0; i<4; i++) {
+			paint(laneSeparator, (i * 2 + 11) * laneSeparator.width + zebraStripe.width, streetYOffset -2 + streetWidth / 2, true, g);			
+		}	
+	
+	}
+
+	
+	protected void paint(Dimension area, int x, int y, boolean horizontally, Graphics g) {
+		g.fillRect(x, y, 
+				horizontally ? area.width : area.height, 
+				horizontally ? area.height : area.width);
+
+	}
+}

+ 52 - 70
examples/traffic_light/src/traffic/light/CrossingPanel.java

@@ -14,10 +14,6 @@ import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Point;
 
-import javax.swing.JPanel;
-
-import traffic.light.PedestrianLight;
-import traffic.light.TrafficLight;
 import traffic.light.TrafficLight.Alignment;
 
 /**
@@ -26,118 +22,104 @@ import traffic.light.TrafficLight.Alignment;
  *
  */
 
-public class CrossingPanel extends JPanel {
+public class CrossingPanel extends CrossWalkPanel {
 
 	private static final long serialVersionUID = 2709756259645789247L;
-	private TrafficLight light1;
-	private TrafficLight light2;
-	private TrafficLight light3;
-	private TrafficLight light4;
-	private PedestrianLight light5;
-	private PedestrianLight light6;
-
+	
+	protected TrafficLight trafficLightWest;
+	protected TrafficLight trafficLightNorth;
+	protected TrafficLight trafficLightSouth;
+	protected PedestrianLight pedlightNorth;
+	
 	public CrossingPanel() {
-		light1 = new TrafficLight(Alignment.HORIZONTAL);
-		light2 = new TrafficLight(Alignment.VERTICAL);
-		light3 = new TrafficLight(Alignment.HORIZONTAL);
-		light4 = new TrafficLight(Alignment.VERTICAL);
-		light5 = new PedestrianLight(PedestrianLight.Alignment.HORIZONTAL);
-		light6 = new PedestrianLight(PedestrianLight.Alignment.VERTICAL);
-	}
-
-	public void paint(Graphics g) {
-		paintCrossing(g);
-		paintTrafficLights(g);
-		paintPedestrainLights(g);
-		g.dispose();
+		super();
+		
+		trafficLightWest = new TrafficLight(Alignment.HORIZONTAL);
+		trafficLightNorth = new TrafficLight(Alignment.VERTICAL);
+		trafficLightSouth = new TrafficLight(Alignment.VERTICAL);
+		pedlightNorth = new PedestrianLight(PedestrianLight.Alignment.HORIZONTAL);
 	}
 
-	private void paintTrafficLights(Graphics g) {
-		light1.updatePosition(new Point(25, 150));
-		light1.paint(g);
-
-		light2.updatePosition(new Point(350, 25));
-		light2.paint(g);
+	@Override
+	protected void paintTrafficLights(Graphics g) {
+		super.paintTrafficLights(g);
+		
+		trafficLightWest.updatePosition(new Point(25, 150));
+		trafficLightWest.paint(g);
 
-		light3.updatePosition(new Point(425, 350));
-		light3.paint(g);
+		trafficLightNorth.updatePosition(new Point(350, 25));
+		trafficLightNorth.paint(g);
 
-		light4.updatePosition(new Point(150, 425));
-		light4.paint(g);
+		trafficLightSouth.updatePosition(new Point(150, 425));
+		trafficLightSouth.paint(g);
 	}
 
-	private void paintPedestrainLights(Graphics g) {
-		light5.updatePosition(new Point(175, 25));
-		light5.paint(g);
-
-		light6.updatePosition(new Point(475, 175));
-		light6.paint(g);
+	@Override
+	protected void paintPedestrainLights(Graphics g) {
+		super.paintPedestrainLights(g);
+		
+		pedlightNorth.updatePosition(new Point(175, 25));
+		pedlightNorth.paint(g);
 	}
-
-	private void paintCrossing(Graphics g) {
-
+	
+	@Override
+	protected void paintCrossing(Graphics g) {
+		
 		int breite = getSize().width;
 		int hoehe = getSize().height;
-
+	
 		g.setColor(Color.darkGray);
 		g.fillRect(225, 0, 100, hoehe);
-
+	
 		g.setColor(Color.darkGray);
 		g.fillRect(0, 225, breite, 100);
-
+	
 		g.setColor(Color.white);
 		g.fillRect(270, 0, 10, hoehe);
-
+	
 		g.setColor(Color.white);
 		g.fillRect(0, 270, breite, 10);
-
+	
 		g.setColor(Color.darkGray);
 		g.fillRect(225, 225, 100, 100);
-
+	
 		g.setColor(Color.white);
 		g.fillRect(225, 225, 100, 100);
-
+	
 		g.setColor(Color.darkGray);
 		g.fillRect(235, 235, 80, 80);
-
+	
 		g.setColor(Color.white);
-
+	
 		g.fillRect(230, 30, 10, 50);
 		g.fillRect(230 + 20, 30, 10, 50);
 		g.fillRect(230 + 40, 30, 10, 50);
 		g.fillRect(230 + 60, 30, 10, 50);
 		g.fillRect(230 + 80, 30, 10, 50);
-
+	
 		g.setColor(Color.white);
 		g.fillRect(475, 230, 50, 10);
 		g.fillRect(475, 230 + 20, 50, 10);
 		g.fillRect(475, 230 + 40, 50, 10);
 		g.fillRect(475, 230 + 60, 50, 10);
 		g.fillRect(475, 230 + 80, 50, 10);
-
+	
 	}
 
-	public TrafficLight getLight1() {
-		return light1;
-	}
-
-	public TrafficLight getLight2() {
-		return light2;
-	}
 
-	public TrafficLight getLight3() {
-		return light3;
+	public TrafficLight getTrafficLightWest() {
+		return trafficLightWest;
 	}
 
-	public TrafficLight getLight4() {
-		return light4;
+	public TrafficLight getTrafficLightNorth() {
+		return trafficLightNorth;
 	}
 
-	public PedestrianLight getLight5() {
-		return light5;
+	public TrafficLight getTrafficLightSouth() {
+		return trafficLightSouth;
 	}
 
-	public PedestrianLight getLight6() {
-		return light6;
+	public PedestrianLight getPedLightNorth() {
+		return pedlightNorth;
 	}
 }

+ 3 - 3
examples/traffic_light/src/traffic/light/PedestrianLight.java

@@ -33,7 +33,7 @@ public class PedestrianLight extends JPanel {
 	private Alignment alignment;
 
 	public enum Alignment {
-		HORIZONTAL(25, 50), VERTICAL(50, 25);
+		HORIZONTAL(50, 25), VERTICAL(25, 50);
 
 		private int width;
 		private int height;
@@ -91,7 +91,7 @@ public class PedestrianLight extends JPanel {
 		graphics.setColor(Color.black);
 		graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
 
-		if (alignment == Alignment.VERTICAL) {
+		if (alignment == Alignment.HORIZONTAL) {
 
 			graphics.setColor(white ? Color.white : Color.black);
 			graphics.fillRect(bounds.x + ((bounds.width - (3 * (bounds.height / 3))) / 4),
@@ -106,7 +106,7 @@ public class PedestrianLight extends JPanel {
 					bounds.x + (3 * ((bounds.width - (3 * (bounds.height / 3))) / 4)) + (2 * (bounds.height / 3)),
 					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 4, bounds.width / 4);
 
-		} else if (alignment == Alignment.HORIZONTAL) {
+		} else if (alignment == Alignment.VERTICAL) {
 
 			graphics.setColor(white ? Color.white : Color.black);
 			graphics.fillRect(bounds.x + 7, bounds.y + 2, bounds.height / 4, bounds.height / 4);

+ 13 - 28
examples/traffic_light/src/traffic/light/TrafficlightDemo.java

@@ -16,7 +16,7 @@ import java.awt.Graphics;
 import javax.swing.JFrame;
 
 import traffic.light.trafficlightctrl.ITrafficLightCtrlStatemachine;
-import traffic.light.trafficlightctrl.TrafficLightCtrlStatemachine;
+import traffic.light.trafficlightctrl.SynchronizedTrafficLightCtrlStatemachine;
 
 /**
  * 
@@ -28,11 +28,11 @@ public class TrafficlightDemo extends JFrame {
 
 	private static final long serialVersionUID = -8909693541678814631L;
 
-	protected TrafficLightCtrlStatemachine statemachine;
+	protected SynchronizedTrafficLightCtrlStatemachine statemachine;
 
 	protected TimerService timer;
 
-	private CrossingPanel crossing;
+	private CrossWalkPanel crossing;
 
 	private ButtonPanel buttonPanel;
 
@@ -50,12 +50,12 @@ public class TrafficlightDemo extends JFrame {
 
 	protected void createContents() {
 		setLayout(new BorderLayout());
-		setTitle("Traffic Light Crossing");
-		crossing = new CrossingPanel();
+		setTitle("Crosswalk traffic light");
+		crossing = new CrossWalkPanel();
 		add(BorderLayout.CENTER, crossing);
 		buttonPanel = new ButtonPanel();
 		add(BorderLayout.SOUTH, buttonPanel);
-		setSize(600, 600);
+		setSize(440, 440);
 		setVisible(true);
 	}
 
@@ -65,7 +65,7 @@ public class TrafficlightDemo extends JFrame {
 	}
 
 	protected void setupStatemachine() {
-		statemachine = new TrafficLightCtrlStatemachine();
+		statemachine = new SynchronizedTrafficLightCtrlStatemachine();
 		timer = new TimerService();
 		statemachine.setTimer(timer);
 		statemachine.getSCInterface().setSCInterfaceOperationCallback(new ITrafficLightCtrlStatemachine.SCInterfaceOperationCallback() {
@@ -85,28 +85,13 @@ public class TrafficlightDemo extends JFrame {
 
 	
 	protected void checkTrafficLightStates() {
-		crossing.getLight1().setRed(statemachine.getSCITrafficLight().getRed());
-		crossing.getLight1().setYellow(statemachine.getSCITrafficLight().getYellow());
-		crossing.getLight1().setGreen(statemachine.getSCITrafficLight().getGreen());
 
-		crossing.getLight3().setRed(statemachine.getSCITrafficLight().getRed());
-		crossing.getLight3().setYellow(statemachine.getSCITrafficLight().getYellow());
-		crossing.getLight3().setGreen(statemachine.getSCITrafficLight().getGreen());
+		crossing.getTrafficLight().setRed(statemachine.getSCITrafficLight().getRed());
+		crossing.getTrafficLight().setYellow(statemachine.getSCITrafficLight().getYellow());
+		crossing.getTrafficLight().setGreen(statemachine.getSCITrafficLight().getGreen());
 
-		crossing.getLight2().setGreen(statemachine.getSCITrafficLight().getRed());
-		crossing.getLight2().setYellow(statemachine.getSCITrafficLight().getYellow());
-		crossing.getLight2().setRed(statemachine.getSCITrafficLight().getGreen());
-
-		crossing.getLight4().setGreen(statemachine.getSCITrafficLight().getRed());
-		crossing.getLight4().setYellow(statemachine.getSCITrafficLight().getYellow());
-		crossing.getLight4().setRed(statemachine.getSCITrafficLight().getGreen());
-
-		crossing.getLight5().setGreen(statemachine.getSCIPedestrian().getRed());
-		crossing.getLight5().setRed(statemachine.getSCIPedestrian().getGreen());
-		crossing.getLight5().setWhite(statemachine.getSCIPedestrian().getRequest());
-
-		crossing.getLight6().setRed(statemachine.getSCIPedestrian().getRed());
-		crossing.getLight6().setGreen(statemachine.getSCIPedestrian().getGreen());
-		crossing.getLight6().setWhite(statemachine.getSCIPedestrian().getRequest());
+		crossing.getPedLight().setRed(statemachine.getSCIPedestrian().getRed());
+		crossing.getPedLight().setGreen(statemachine.getSCIPedestrian().getGreen());
+		crossing.getPedLight().setWhite(statemachine.getSCIPedestrian().getRequest());
 	}
 }