Package jmri.jmrit.logix
Class SCWarrant
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.jmrit.logix.Warrant
-
- jmri.jmrit.logix.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrit.logix.Warrant
Warrant.SpeedState
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description (package private) float
_maxBlockLength
(package private) SignalSpeedMap
_speedMap
Move the train if _nextSignal permits.static float
SPEED_STOP
static float
SPEED_TO_PLATFORM
static float
SPEED_UNSIGNALLED
(package private) static java.util.concurrent.LinkedBlockingQueue<SCWarrant>
waitToRunQ
The waiting for event must happen in a separate thread.-
Fields inherited from class jmri.jmrit.logix.Warrant
_message, _runMode, _stoppingBlock, _trace, _trainName, ABORT, AT_SPEED, BUFFER_DISTANCE, CNTRL_CMDS, DEBUG, EStop, ESTOP, HALT, LEARNING, MODE_ABORT, MODE_LEARN, MODE_MANUAL, MODE_NONE, MODE_RUN, MODES, Normal, RAMP_DOWN, RAMP_HALT, RAMP_UP, RESUME, RETRY_BKWD, RETRY_FWD, RUN_STATE, RUNNING, SPEED_RESTRICTED, SPEED_UP, Stop, STOP, STOP_PENDING, WAIT_FOR_CLEAR, WAIT_FOR_DELAYED_START, WAIT_FOR_SENSOR, WAIT_FOR_TRAIN
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description SCWarrant(java.lang.String sName, java.lang.String uName, long TTP)
Create an object with no route defined.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
allocateBlocksAndSetTurnouts(int startIndex)
Do what the title says.(package private) boolean
allTurnoutsSet()
(package private) boolean
approchingDestination()
Are we close to the destination block?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.boolean
equals(java.lang.Object obj)
void
getAndGetNotifiedFromNextSignal()
Find the next signal along our route and setup subscription for status changes on that signal.boolean
getForward()
(package private) float
getMaxBlockLength()
protected java.lang.String
getRunningMessage()
Generate status message to show in warrant table.float
getSpeedFactor()
long
getTimeToPlatform()
protected void
goingActive(OBlock block)
Block in the route going active.protected void
goingInactive(OBlock block)
Block in the route is going Inactive.int
hashCode()
(package private) boolean
inStartBlock()
Are we still in the start block?boolean
isNextBlockFreeAndAllocated()
Is the next block free or occupied, i.e do we risk to crash into an other train, if we proceed?(package private) boolean
isRouteAllocated()
boolean
isRouteFree()
protected boolean
isStartBlockOccupied()
Wait until there is a train in the start block.void
notifyThrottleFound(DccThrottle throttle)
Callback from acquireThrottle() when the throttle has become available.syncvoid
propertyChange(java.beans.PropertyChangeEvent evt)
Something has fired a property change event.protected void
runSignalControlledTrain()
Use _throttle to control the train.void
setForward(boolean set)
(package private) void
setMaxBlockLength()
java.lang.String
setRoute(boolean delay, java.util.List<BlockOrder> orders)
This method has been overridden in order to avoid allocation of occupied blocks.void
setSpeedFactor(float factor)
void
setSpeedFromNextSignal()
void
setTimeToPlatform(long TTP)
void
setTrainDirection()
Set this train to run backwards or forwards as specified in the command list.void
stopWarrant(boolean abort, boolean turnOffFunctions)
Make sure to free up additional resources for a running SCWarrant.protected void
waitForStartblockToGetOccupied()
-
Methods inherited from class jmri.jmrit.logix.Warrant
abortWarrant, acquireThrottle, addBlockOrder, addThrottleCommand, allocateRoute, checkforTrackers, checkRoute, checkStartBlock, controlRunTrain, deAllocate, debugInfo, dispose, downRampBegun, downRampDone, fireRunStatus, getAddTracker, getAvoidOrder, getBeanType, getBlockAt, getBlockingWarrant, getBlockOrderAt, getBlockOrders, getCurrentBlockName, getCurrentBlockOrder, getCurrentOrderIndex, getfirstOrder, getHaltStart, getIndexOfBlockAfter, getIndexOfBlockBefore, getLastOrder, getMessage, getNoRamp, getNumOrders, getRunBlind, getRunMode, getRunModeMessage, getShareRoute, getSpeedUtil, getState, getThrottleCommands, getTrainName, getUsageReport, getViaOrder, hasRouteSet, incrementCurrentOrderIndex, isAllocated, isNXWarrant, isTotalAllocated, isWaitingForBlock, isWaitingForSignal, isWaitingForWarrant, notifyDecisionRequired, notifyFailedThrottleRequest, releaseThrottle, routeIsFree, routeIsOccupied, runWarrant, setAddTracker, setAvoidOrder, setBlockOrders, setHaltStart, setNoRamp, setNXWarrant, setRunBlind, setRunMode, setShareRoute, setSpeedUtil, setState, setThrottleCommands, setTrackSpeeds, setTrainName, setViaOrder, startupWarrant
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChange
-
-
-
-
Field Detail
-
SPEED_STOP
public static final float SPEED_STOP
- See Also:
- Constant Field Values
-
SPEED_TO_PLATFORM
public static final float SPEED_TO_PLATFORM
- See Also:
- Constant Field Values
-
SPEED_UNSIGNALLED
public static final float SPEED_UNSIGNALLED
- See Also:
- Constant Field Values
-
_maxBlockLength
float _maxBlockLength
-
_speedMap
SignalSpeedMap _speedMap
Move the train if _nextSignal permits. If there is no next signal, we will move forward with half speed.
-
waitToRunQ
static java.util.concurrent.LinkedBlockingQueue<SCWarrant> waitToRunQ
The waiting for event must happen in a separate thread. Therefore the main code of runSignalControlledTrain is put in this class.
-
-
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
-
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
float getMaxBlockLength()
-
setMaxBlockLength
void setMaxBlockLength()
-
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.
-
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 interfaceThrottleListener
- Overrides:
notifyThrottleFound
in classWarrant
- Parameters:
throttle
- the throttle with the requested address
-
getRunningMessage
protected java.lang.String getRunningMessage()
Generate status message to show in warrant table.- Overrides:
getRunningMessage
in classWarrant
-
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
protected void 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
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
-
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
-
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 classWarrant
- 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 classWarrant
- 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 interfacejava.beans.PropertyChangeListener
- Overrides:
propertyChange
in classWarrant
-
stopWarrant
public void stopWarrant(boolean abort, boolean turnOffFunctions)
Make sure to free up additional resources for a running SCWarrant.- Overrides:
stopWarrant
in classWarrant
-
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
-
-