Class SCWarrant

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.lang.Comparable<NamedBean>, java.util.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.
    • Constructor Detail

      • SCWarrant

        public SCWarrant​(java.lang.String sName,
                         java.lang.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 Detail

      • setForward

        public void setForward​(boolean set)
      • setRoute

        public java.lang.String setRoute​(boolean delay,
                                         java.util.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
      • 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
      • 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

        public void 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

        boolean approchingDestination()
        Are we close to the destination block?
        Returns:
        true if close
      • 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
      • 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

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        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 java.beans.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​(java.lang.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.