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_speedMapMove the train if _nextSignal permits.static floatSPEED_STOPstatic floatSPEED_TO_PLATFORMstatic floatSPEED_UNSIGNALLED(package private) static java.util.concurrent.LinkedBlockingQueue<SCWarrant>waitToRunQThe 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, PROPERTY_ABORT_LEARN, PROPERTY_BLOCK_CHANGE, PROPERTY_CANNOT_RUN, PROPERTY_CONTROL_CHANGE, PROPERTY_CONTROL_FAILED, PROPERTY_OCCUPY_OVERRUN, PROPERTY_READY_TO_RUN, PROPERTY_SIGNAL_OVERRUN, PROPERTY_STOP_WARRANT, PROPERTY_THROTTLE_FAIL, PROPERTY_WARRANT_OVERRUN, PROPERTY_WARRANT_START, 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_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, 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 voidallocateBlocksAndSetTurnouts(int startIndex)Do what the title says.(package private) booleanallTurnoutsSet()(package private) booleanapprochingDestination()Are we close to the destination block?protected voiddeallocateUpToBlock(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.booleanequals(java.lang.Object obj)voidgetAndGetNotifiedFromNextSignal()Find the next signal along our route and setup subscription for status changes on that signal.booleangetForward()(package private) floatgetMaxBlockLength()protected java.lang.StringgetRunningMessage()Generate status message to show in warrant table.floatgetSpeedFactor()longgetTimeToPlatform()protected voidgoingActive(OBlock block)Block in the route going active.protected voidgoingInactive(OBlock block)Block in the route is going Inactive.inthashCode()(package private) booleaninStartBlock()Are we still in the start block?booleanisNextBlockFreeAndAllocated()Is the next block free or occupied, i.e do we risk to crash into an other train, if we proceed?(package private) booleanisRouteAllocated()booleanisRouteFree()protected booleanisStartBlockOccupied()Wait until there is a train in the start block.voidnotifyThrottleFound(DccThrottle throttle)Callback from acquireThrottle() when the throttle has become available.syncvoidpropertyChange(java.beans.PropertyChangeEvent evt)Something has fired a property change event.protected voidrunSignalControlledTrain()Use _throttle to control the train.voidsetForward(boolean set)(package private) voidsetMaxBlockLength()java.lang.StringsetRoute(boolean delay, java.util.List<BlockOrder> orders)This method has been overridden in order to avoid allocation of occupied blocks.java.lang.StringsetRunMode(int mode, DccLocoAddress address, LearnThrottleFrame student, java.util.List<ThrottleSetting> commands, boolean runBlind)Sets up recording and playing back throttle commands - also cleans up afterwards.voidsetSpeedFactor(float factor)voidsetSpeedFromNextSignal()voidsetTimeToPlatform(long TTP)voidsetTrainDirection()Set this train to run backwards or forwards as specified in the command list.voidstopWarrant(boolean abort, boolean turnOffFunctions)Make sure to free up additional resources for a running SCWarrant.protected voidwaitForStartblockToGetOccupied()-
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, getWarrantSpeedMessage, hasRouteSet, incrementCurrentOrderIndex, isAllocated, isNXWarrant, isTotalAllocated, isWaitingForBlock, isWaitingForSignal, isWaitingForWarrant, notifyDecisionRequired, notifyFailedThrottleRequest, releaseThrottle, routeIsFree, routeIsOccupied, runWarrant, setAddTracker, setAvoidOrder, setBlockOrders, setHaltStart, setNoRamp, setNXWarrant, setRunBlind, 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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.NamedBean
compareTo, getRecommendedToolTip
-
-
-
-
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:
notifyThrottleFoundin interfaceThrottleListener- Overrides:
notifyThrottleFoundin classWarrant- Parameters:
throttle- the throttle with the requested address
-
getRunningMessage
protected java.lang.String getRunningMessage()
Generate status message to show in warrant table.- Overrides:
getRunningMessagein 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
-
setRunMode
public java.lang.String setRunMode(int mode, DccLocoAddress address, LearnThrottleFrame student, java.util.List<ThrottleSetting> commands, boolean runBlind)
Description copied from class:WarrantSets 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:
setRunModein classWarrant- Parameters:
mode- run modeaddress- DCC loco addressstudent- throttle frame for learn mode parameterscommands- list of throttle commandsrunBlind- 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:
goingActivein 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:
goingInactivein 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:
propertyChangein interfacejava.beans.PropertyChangeListener- Overrides:
propertyChangein classWarrant
-
stopWarrant
public void stopWarrant(boolean abort, boolean turnOffFunctions)
Make sure to free up additional resources for a running SCWarrant.- Overrides:
stopWarrantin classWarrant
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:WarrantThis 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
-
-