Class Engineer

java.lang.Object
java.lang.Thread
jmri.jmrit.logix.Engineer
All Implemented Interfaces:
PropertyChangeListener, Runnable, EventListener

class Engineer extends Thread implements 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.

  • Field Details

  • Constructor Details

    • 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 Details

    • run

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

      protected int getCurrentCommandIndex()
    • 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
    • getRunOnET

      protected boolean getRunOnET()
    • getSynchBlock

      protected OBlock getSynchBlock()
    • 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 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 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(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

      Generate Debug Info for Warrant progression state.
      Returns:
      String for use in debug output.
    • 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 ).
    • getWaitSensor

      protected Sensor getWaitSensor()
    • propertyChange

      Specified by:
      propertyChange in interface PropertyChangeListener