Class SCWarrant

All Implemented Interfaces:
PropertyChangeListener, Comparable<NamedBean>, EventListener, PropertyChangeProvider, NamedBean, ThrottleListener

public class SCWarrant extends Warrant
An SCWarrant is a warrant that is controlled by the signals on a layout. It will not run unless you have your layout fully covered with sensors and signals.
  • Field Details

  • Constructor Details

    • SCWarrant

      public SCWarrant(String sName, String uName, long TTP)
      Create an object with no route defined.

      The list of BlockOrders is the route from an Origin to a Destination.

      Parameters:
      sName - system name.
      uName - username.
      TTP - time to platform.
  • Method Details

    • getTimeToPlatform

      public long getTimeToPlatform()
    • setTimeToPlatform

      public void setTimeToPlatform(long TTP)
    • setForward

      public void setForward(boolean set)
    • getForward

      public boolean getForward()
    • setSpeedFactor

      public void setSpeedFactor(float factor)
    • getSpeedFactor

      public float getSpeedFactor()
    • getMaxBlockLength

    • setMaxBlockLength

    • setRoute

      public String setRoute(boolean delay, List<BlockOrder> orders)
      This method has been overridden in order to avoid allocation of occupied blocks.
      Overrides:
      setRoute in class Warrant
      Parameters:
      delay - If true allocateRoute returns messages for display.
      orders - BlockOrder list of route. If null, use permanent warrant copy.
      Returns:
      message if the first block fails allocation, otherwise null
    • allTurnoutsSet

      boolean allTurnoutsSet()
    • isRouteFree

      public boolean isRouteFree()
    • isRouteAllocated

      boolean isRouteAllocated()
    • notifyThrottleFound

      public void notifyThrottleFound(DccThrottle throttle)
      Callback from acquireThrottle() when the throttle has become available.sync
      Specified by:
      notifyThrottleFound in interface ThrottleListener
      Overrides:
      notifyThrottleFound in class Warrant
      Parameters:
      throttle - the throttle with the requested address
    • getRunningMessage

      Generate status message to show in warrant table.
      Overrides:
      getRunningMessage in class Warrant
    • runSignalControlledTrain

      protected void runSignalControlledTrain()
      Use _throttle to control the train. Get notified of signals, block occupancy and take care of block allocation status to determine speed. We have three speeds: Stop == SPEED_STOP Normal == SPEED_NORMAL Anything else == SPEED_MID (Limited, Medium, Slow, Restricted) If you have blocks large enough to ramp speed nicely up and down and to have further control of speed settings: Use a normal warrant and not a signal controlled one. This is "the main loop" for running a Signal Controlled Warrant
    • isStartBlockOccupied

      protected boolean isStartBlockOccupied()
      Wait until there is a train in the start block.
      Returns:
      true if block not UNOCCUPIED
    • waitForStartblockToGetOccupied

    • setTrainDirection

      public void setTrainDirection()
      Set this train to run backwards or forwards as specified in the command list.
    • isNextBlockFreeAndAllocated

      public boolean isNextBlockFreeAndAllocated()
      Is the next block free or occupied, i.e do we risk to crash into an other train, if we proceed? And is it allocated to us?
      Returns:
      true if allocated to us and unoccupied, else false.
    • getAndGetNotifiedFromNextSignal

      Find the next signal along our route and setup subscription for status changes on that signal.
    • inStartBlock

      boolean inStartBlock()
      Are we still in the start block?
      Returns:
      true if still in start block
    • approchingDestination

      Are we close to the destination block?
      Returns:
      true if close
    • setSpeedFromNextSignal

      public void setSpeedFromNextSignal()
    • allocateBlocksAndSetTurnouts

      protected void allocateBlocksAndSetTurnouts(int startIndex)
      Do what the title says. But make sure not to set the turnouts if already done, since that would just cause all signals to go to Stop aspects and thus cause a jerky train movement.
      Parameters:
      startIndex - Allocate starting with this index
    • setRunMode

      public String setRunMode(int mode, DccLocoAddress address, LearnThrottleFrame student, List<ThrottleSetting> commands, boolean runBlind)
      Description copied from class: Warrant
      Sets up recording and playing back throttle commands - also cleans up afterwards. MODE_LEARN and MODE_RUN sessions must end by calling again with MODE_NONE. It is important that the route be deAllocated (remove listeners).

      Rule for (auto) MODE_RUN: 1. At least the Origin block must be owned (allocated) by this warrant. (block._warrant == this) and path set for Run Mode Rule for (auto) LEARN_RUN: 2. Entire Route must be allocated and Route Set for Learn Mode. i.e. this warrant has listeners on all block sensors in the route. Rule for MODE_MANUAL The Origin block must be allocated to this warrant and path set for the route

      Overrides:
      setRunMode in class Warrant
      Parameters:
      mode - run mode
      address - DCC loco address
      student - throttle frame for learn mode parameters
      commands - list of throttle commands
      runBlind - true if occupancy should be ignored
      Returns:
      error message, if any
    • goingActive

      protected void goingActive(OBlock block)
      Block in the route going active. Make sure to allocate the rest of the route, update our present location and then tell the main loop to find a new throttle setting.
      Overrides:
      goingActive in class Warrant
      Parameters:
      block - Block in the route is going active.
    • goingInactive

      protected void goingInactive(OBlock block)
      Block in the route is going Inactive. Release the blocks that we have left. Check if current block has been left (i.e. we have left our route) and stop the train in that case.
      Overrides:
      goingInactive in class Warrant
      Parameters:
      block - Block in the route is going Inactive
    • deallocateUpToBlock

      protected void deallocateUpToBlock(int idx)
      Deallocate all blocks up to and including idx, but only on these conditions in order to ensure that only a consecutive list of blocks are allocated at any time: 1. Only if our train has left not only this block, but also all previous blocks. 2. Only if the block shall not be re-used ahead and all block up until the block are allocated.
      Parameters:
      idx - Index of final block
    • propertyChange

      Something has fired a property change event. React if: - it is a warrant that we need to synchronize with. And then again: Why? - it is _nextSignal Do not worry about sensors and blocks. They are handled by goingActive and goingInactive.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Overrides:
      propertyChange in class Warrant
    • stopWarrant

      public void stopWarrant(boolean abort, boolean turnOffFunctions)
      Make sure to free up additional resources for a running SCWarrant.
      Overrides:
      stopWarrant in class Warrant
    • equals

      public boolean equals(Object obj)
      Description copied from class: Warrant

      This implementation tests that NamedBean.getSystemName() is equal for this and obj.

      This implementation tests that NamedBean.getSystemName() is equal for this and obj. To allow a warrant to run with sections, DccLocoAddress is included to test equality

      Overrides:
      equals in class Warrant
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Description copied from class: Warrant
      Overrides:
      hashCode in class Warrant
      Returns:
      hash code value is based on the system name and DccLocoAddress.