Class Engineer

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.lang.Runnable, java.util.EventListener

    class Engineer
    extends java.lang.Thread
    implements java.beans.PropertyChangeListener
    Execute a throttle command script for a warrant.

    This generally operates on its own thread, but calls the warrant thread via Warrant.fireRunStatus to show status. fireRunStatus uses ThreadingUtil.runOnGUIEventually to display on the layout thread.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Engineer.ThrottleRamp  
      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Constructor Summary

      Constructors 
      Constructor Description
      Engineer​(Warrant warrant, DccThrottle throttle)
      Create a new Engineer for a given Warrant and Throttle.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean cancelRamp​(boolean die)
      warrant.cancelDelayRamp() called for immediate Stop commands When die==true for ending the warrant run.
      protected void clearWaitForSync​(OBlock block)
      Called by the warrant when a the block ahead of a moving train goes occupied.
      (package private) java.lang.String debugInfo()
      Generate Debug Info for Warrant progression state.
      protected int getCurrentCommandIndex()  
      protected boolean getRunOnET()  
      protected int getRunState()
      Get the Warrant run state.
      protected float getScriptSpeed()
      Get the current commanded speed as set in the Warrant script.
      protected float getSpeedSetting()
      Get the current Throttle speed.
      protected Warrant.SpeedState getSpeedState()
      Get the Warrant SpeedState ENUM.
      protected java.lang.String getSpeedType​(boolean absolute)
      Get the Speed type name.
      protected OBlock getSynchBlock()  
      protected Sensor getWaitSensor()  
      protected boolean isRamping()
      Get if Engineer is ramping up or down the speed.
      void propertyChange​(java.beans.PropertyChangeEvent evt)  
      protected void rampSpeedTo​(java.lang.String endSpeedType, int endBlockIdx)
      Occupancy of blocks, user halts and aspects of Portal signals will modify normal scripted train speeds.
      void run()
      Run the Warrant commands on this Engineer thread.
      protected void setHalt​(boolean halt)
      Command to stop (or resume speed) of train from Warrant.controlRunTrain() of user's override of throttle script.
      protected void setRunOnET​(boolean set)
      Cannot set _runOnET to true until current NOOP command completes so there is the intermediate flag _setRunOnET
      protected void setSpeed​(float speed)
      do throttle setting
      protected void setSpeedToType​(java.lang.String speedType)
      Do immediate speed change.
      protected void setWaitforClear​(boolean wait)
      Command to stop or smoothly resume speed.
      void stopRun​(boolean abort, boolean turnOffFunctions)
      Stop the Engineer run.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Engineer

        Engineer​(Warrant warrant,
                 DccThrottle throttle)
        Create a new Engineer for a given Warrant and Throttle.
        Parameters:
        warrant - The Warrant to execute.
        throttle - The Engine throttle to command.
    • Method Detail

      • run

        public void run()
        Run the Warrant commands on this Engineer thread.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • setRunOnET

        protected void setRunOnET​(boolean set)
        Cannot set _runOnET to true until current NOOP command completes so there is the intermediate flag _setRunOnET
        Parameters:
        set - true to run on elapsed time calculations only, false to consider other inputs
      • clearWaitForSync

        protected void clearWaitForSync​(OBlock block)
        Called by the warrant when a the block ahead of a moving train goes occupied. typically when this thread is on a timed wait. The call will free the wait.
        Parameters:
        block - going active.
      • rampSpeedTo

        protected void rampSpeedTo​(@Nonnull
                                   java.lang.String endSpeedType,
                                   int endBlockIdx)
        Occupancy of blocks, user halts and aspects of Portal signals will modify normal scripted train speeds. Ramp speed change for smooth prototypical look.
        Parameters:
        endSpeedType - signal aspect speed name
        endBlockIdx - BlockOrder index of the block where ramp is to end. -1 if an end block is not specified.
      • isRamping

        protected boolean isRamping()
        Get if Engineer is ramping up or down the speed.
        Returns:
        true if is ramping.
      • getSpeedType

        protected java.lang.String getSpeedType​(boolean absolute)
        Get the Speed type name. _speedType is the type when moving. Used to restore speeds aspects of signals when halts or other conditions have stopped the train. If 'absolute' is true return the absolute speed of the train, i.e. 'Stop' if train is not moving.
        Parameters:
        absolute - which speed type, absolute or allowed movement
        Returns:
        speed type
      • cancelRamp

        protected boolean cancelRamp​(boolean die)
        warrant.cancelDelayRamp() called for immediate Stop commands When die==true for ending the warrant run.
        Parameters:
        die - true for ending the warrant run
        Returns:
        true if _ramp not null and die is false and _isRamping
      • setSpeed

        protected void setSpeed​(float speed)
        do throttle setting
        Parameters:
        speed - throttle setting about to be set. Modified to sType if from script. UnModified if from ThrottleRamp or stop speeds.
      • getSpeedSetting

        protected float getSpeedSetting()
        Get the current Throttle speed. If Speed is negative ( i.e. E-Stop ), sets Throttle speed to 0.
        Returns:
        speed setting reported by Throttle.
      • getScriptSpeed

        protected float getScriptSpeed()
        Get the current commanded speed as set in the Warrant script.
        Returns:
        the most recent commanded speed.
      • setSpeedToType

        protected void setSpeedToType​(java.lang.String speedType)
        Do immediate speed change.
        Parameters:
        speedType - speed type
      • setHalt

        protected void setHalt​(boolean halt)
        Command to stop (or resume speed) of train from Warrant.controlRunTrain() of user's override of throttle script. Also from error conditions such as losing detection of train's location.
        Parameters:
        halt - true if train should halt
      • setWaitforClear

        protected void setWaitforClear​(boolean wait)
        Command to stop or smoothly resume speed. Stop due to signal or occupation stopping condition ahead. Caller follows with call for type of stop to make. Track condition override of throttle script.
        Parameters:
        wait - true if train should stop
      • debugInfo

        java.lang.String debugInfo()
        Generate Debug Info for Warrant progression state.
        Returns:
        String for use in debug output.
      • getSpeedState

        protected Warrant.SpeedState getSpeedState()
        Get the Warrant SpeedState ENUM.
        Returns:
        e.g. Warrant.SpeedState.RAMPING_DOWN or SpeedState.STEADY_SPEED.
      • getRunState

        protected int getRunState()
        Get the Warrant run state.
        Returns:
        e.g. Warrant.WAIT_FOR_SENSOR or Warrant.RUNNING.
      • stopRun

        public void stopRun​(boolean abort,
                            boolean turnOffFunctions)
        Stop the Engineer run.
        Parameters:
        abort - true to abort, else false.
        turnOffFunctions - true to set Functions 0, 1, 2 and 3 to off ( if speed is > 0 ).
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener