protected void updatePermitOpposingHold() { switch (bulbcolor) { case GREEN: // iff I am about to go off and there is no transition time permitopposinghold = forceoff_requested && actualyellowtime == 0 && redcleartime == 0; break; case YELLOW: // iff near end yellow time and there is no red clear time permitopposinghold = SiriusMath.greaterorequalthan(bulbtimer.getT(), actualyellowtime - bulbtimer.dt) && redcleartime == 0; break; case RED: // iff near end of red clear time and not starting again. permitopposinghold = SiriusMath.greaterorequalthan(bulbtimer.getT(), redcleartime - bulbtimer.dt) && !hold_requested; break; } }
protected void update(boolean hold_approved, boolean forceoff_approved) { double bulbt = bulbtimer.getT(); if (!protectd) { if (permissive) return; else { setPhaseColor(Signal.BulbColor.RED); return; } } // execute this state machine until "done". May be more than once if // some state has zero holding time (eg yellowtime=0) boolean done = false; while (!done) { switch (bulbcolor) { // ............................................................................................. case GREEN: setPhaseColor(Signal.BulbColor.GREEN); // permitopposinghold = false; // Force off if (forceoff_approved) { setPhaseColor(Signal.BulbColor.YELLOW); mySignal.completedPhases.add( mySignal .new PhaseData( myNEMA, mySignal.myScenario.clock.getT() - bulbtimer.getT(), bulbtimer.getT())); bulbtimer.reset(); // FlushAllStationCallsAndConflicts(); done = actualyellowtime > 0; } else done = true; break; // ............................................................................................. case YELLOW: setPhaseColor(Signal.BulbColor.YELLOW); // set permitopposinghold one step ahead of time so that other phases update correctly // next time. // permitopposinghold = false; // if( SiriusMath.greaterorequalthan(bulbt,actualyellowtime-bulbtimer.dt) && // redcleartime==0) // permitopposinghold = true; // yellow time over, go immediately to red if redcleartime==0 if (SiriusMath.greaterorequalthan(bulbt, actualyellowtime)) { setPhaseColor(Signal.BulbColor.RED); bulbtimer.reset(); done = redcleartime > 0; } else done = true; break; // ............................................................................................. case RED: setPhaseColor(Signal.BulbColor.RED); // if( // SiriusMath.greaterorequalthan(bulbt,redcleartime-myNode.getMyNetwork().getTP()*3600f // && !goG ) // if( SiriusMath.greaterorequalthan(bulbt,redcleartime-bulbtimer.dt) && !hold_approved // ) // permitopposinghold = true; // else // permitopposinghold = false; // if hold, set to green, go to green, etc. if (hold_approved) { setPhaseColor(Signal.BulbColor.GREEN); bulbtimer.reset(); // Unregister calls (for reading conflicting calls) // FlushAllStationCallsAndConflicts(); // GCG ????? done = !forceoff_approved; } else done = true; break; } } }