Class Warrant
- All Implemented Interfaces:
PropertyChangeListener,Comparable<NamedBean>,EventListener,PropertyChangeProvider,NamedBean,ThrottleListener
- Direct Known Subclasses:
SCWarrant
MODE_LEARN - Warrant is created or edited in WarrantFrame and then launched from WarrantFrame who records throttle commands from "_student" throttle. Warrant fires PropertyChanges for WarrantFrame to record when blocks are entered. "_engineer" thread is null.
MODE_RUN - Warrant may be launched from several places. An array of BlockOrders, _savedOrders, and corresponding _throttleCommands allow an "_engineer" thread to execute the throttle commands. The blockOrders establish the route for the Warrant to acquire and reserve OBlocks. The Warrant monitors block activity (entrances and exits, signals, rogue occupancy etc) and modifies speed as needed.
MODE_MANUAL - Warrant may be launched from several places. The Warrant to acquires and reserves the route from the array of BlockOrders. Throttle commands are done by a human operator. "_engineer" and "_throttleCommands" are not used. Warrant monitors block activity but does not set _stoppingBlock or _protectSignal since it cannot control speed. It does attempt to realign the route as needed, but can be thwarted.
Version 1.11 - remove setting of SignalHeads
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameExceptionNested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected intprotected OBlockprotected static booleanprotected Stringstatic final int(package private) static final int(package private) static final float(package private) static final String[]static final intstatic final Stringstatic final intstatic final intprotected static final intstatic final intstatic final intstatic final intstatic final intstatic final int(package private) static final String[]static final Stringstatic final StringString constant for property abort learn.static final StringString constant for property block change.static final StringString constant for property cannot run.static final StringString constant for property control change.static final StringString constant for property control failed.static final StringString constant for property warrant start.static final StringString constant for property ready to run.static final StringString constant for property signal overrun.static final StringString constant for property stop warrant.static final StringString constant for property throttle fail.static final StringString constant for property warrant overrun.static final StringString constant for property warrant start.(package private) static final intprotected static final int(package private) static final intstatic final intstatic final intstatic final int(package private) static final String[]protected static final intprotected static final intstatic final intstatic final Stringstatic final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intFields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, registerFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidabortWarrant(String msg) protected StringvoidaddBlockOrder(BlockOrder order) Add permanently saved BlockOrder.voidallocateRoute(boolean show, List<BlockOrder> orders) Allocate as many blocks as possible from the start of the warrant.protected StringReport any occupied blocks in the routeCheck start block for occupied for start of runbooleancontrolRunTrain(int idx) Pause and resume auto-running train or abort any allocation state User issued overriding commands during run time of warrant _engineer.abort() calls setRunMode(MODE_NONE,...) which calls deallocate all.voidDeallocates blocks from the current BlockOrder listprotected booleanvoiddispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.protected voiddownRampBegun(int endBlockIdx) protected voiddownRampDone(boolean stop, boolean halted, String speedType, int endBlockIdx) booleanprotected voidfireRunStatus(String property, Object old, Object status) booleanFor instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.protected OBlockgetBlockAt(int idx) Call is only valid when in MODE_LEARN and MODE_RUN.protected Warrantprotected BlockOrdergetBlockOrderAt(int index) Call is only valid when in MODE_LEARN and MODE_RUN.Return BlockOrders.Call is only valid when in MODE_LEARN and MODE_RUN.final BlockOrderfinal intReturn permanently saved Origin.booleanprotected intgetIndexOfBlockAfter(OBlock block, int idx) Find index of a block AFTER BlockOrder index.protected intgetIndexOfBlockBefore(int idx, OBlock block) Find index of block BEFORE BlockOrder index.Return permanently saved Destination.booleanprotected intbooleanintprotected Stringprotected StringbooleanintgetState()Provide generic access to internal state.getUsageReport(NamedBean bean) Get a list of references for the specified bean.Return permanently saved BlockOrder that must be included in the route.Get the warrant speed message for the current throttle speed setting.protected voidgoingActive(OBlock block) Check if this is the next block of the train moving under the warrant Learn mode assumes route is set and clear.protected voidgoingInactive(OBlock block) inthashCode()booleanTurnouts are set for the routeprotected voidbooleanprotected booleanbooleanprotected booleanprotected booleanprotected booleanvoidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question) No steal or share decisions made locallyvoidnotifyFailedThrottleRequest(LocoAddress address, String reason) Get notification that an attempt to request a throttle has failed.voidnotifyThrottleFound(DccThrottle throttle) Get notification that a throttle has been found as requested.voidprotected voidreleaseThrottle(DccThrottle throttle) booleanTest if the permanent saved blocks of this warrant are free (unoccupied and unallocated)booleanTest if the permanent saved blocks of this warrant are occupiedvoidrunWarrant(int mode) Convenience routine to use from Python to start a warrant.voidsetAddTracker(boolean set) voidsetAvoidOrder(BlockOrder order) voidsetBlockOrders(List<BlockOrder> orders) voidsetHaltStart(boolean set) voidsetNoRamp(boolean set) protected voidsetNXWarrant(boolean set) setRoute(boolean show, List<BlockOrder> orders) Set the route paths and turnouts for the warrant.voidsetRunBlind(boolean runBlind) setRunMode(int mode, DccLocoAddress address, LearnThrottleFrame student, List<ThrottleSetting> commands, boolean runBlind) Sets up recording and playing back throttle commands - also cleans up afterwards.voidsetShareRoute(boolean set) voidvoidsetState(int state) Provide generic access to internal state.voidvoidvoidsetTrainName(String name) voidsetViaOrder(BlockOrder order) protected voidvoidstopWarrant(boolean abort, boolean turnOffFunctions) 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, vetoableChangeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.NamedBean
compareTo, getRecommendedToolTip
-
Field Details
-
Stop
-
EStop
-
Normal
- See Also:
-
PROPERTY_WARRANT_START
String constant for property warrant start.- See Also:
-
PROPERTY_STOP_WARRANT
String constant for property stop warrant.- See Also:
-
PROPERTY_THROTTLE_FAIL
String constant for property throttle fail.- See Also:
-
PROPERTY_ABORT_LEARN
String constant for property abort learn.- See Also:
-
PROPERTY_CONTROL_CHANGE
String constant for property control change.- See Also:
-
PROPERTY_CONTROL_FAILED
String constant for property control failed.- See Also:
-
PROPERTY_READY_TO_RUN
String constant for property ready to run.- See Also:
-
PROPERTY_CANNOT_RUN
String constant for property cannot run.- See Also:
-
PROPERTY_BLOCK_CHANGE
String constant for property block change.- See Also:
-
PROPERTY_SIGNAL_OVERRUN
String constant for property signal overrun.- See Also:
-
PROPERTY_WARRANT_OVERRUN
String constant for property warrant overrun.- See Also:
-
PROPERTY_OCCUPY_OVERRUN
String constant for property warrant start.- See Also:
-
_trainName
-
_runMode
-
_stoppingBlock
-
_message
-
MODE_NONE
- See Also:
-
MODE_LEARN
- See Also:
-
MODE_RUN
- See Also:
-
MODE_MANUAL
- See Also:
-
MODES
-
MODE_ABORT
- See Also:
-
STOP
- See Also:
-
HALT
- See Also:
-
RESUME
- See Also:
-
ABORT
- See Also:
-
RETRY_FWD
- See Also:
-
ESTOP
- See Also:
-
RAMP_HALT
- See Also:
-
SPEED_UP
- See Also:
-
RETRY_BKWD
- See Also:
-
DEBUG
- See Also:
-
CNTRL_CMDS
-
RUNNING
- See Also:
-
SPEED_RESTRICTED
- See Also:
-
WAIT_FOR_CLEAR
- See Also:
-
WAIT_FOR_SENSOR
- See Also:
-
WAIT_FOR_TRAIN
- See Also:
-
WAIT_FOR_DELAYED_START
- See Also:
-
LEARNING
- See Also:
-
STOP_PENDING
- See Also:
-
RUN_STATE
-
BUFFER_DISTANCE
-
_trace
-
AT_SPEED
- See Also:
-
RAMP_DOWN
- See Also:
-
RAMP_UP
- See Also:
-
-
Constructor Details
-
Warrant
Create an object with no route defined. The list of BlockOrders is the route from an Origin to a Destination- Parameters:
sName- system nameuName- user name
-
-
Method Details
-
setNXWarrant
-
isNXWarrant
-
getState
Description copied from interface:NamedBeanProvide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.
-
setState
Description copied from interface:NamedBeanProvide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.
-
getSpeedUtil
-
setSpeedUtil
-
getBlockOrders
Return BlockOrders.- Returns:
- list of block orders
-
addBlockOrder
Add permanently saved BlockOrder.- Parameters:
order- block order
-
setBlockOrders
-
getfirstOrder
Return permanently saved Origin.- Returns:
- origin block order
-
getLastOrder
Return permanently saved Destination.- Returns:
- destination block order
-
getViaOrder
Return permanently saved BlockOrder that must be included in the route.- Returns:
- via block order
-
setViaOrder
-
getAvoidOrder
-
setAvoidOrder
-
getCurrentBlockOrder
- Returns:
- block order currently at the train position
-
getCurrentOrderIndex
- Returns:
- index of block order currently at the train position
-
getNumOrders
-
incrementCurrentOrderIndex
-
getIndexOfBlockAfter
Find index of a block AFTER BlockOrder index.- Parameters:
block- used by the warrantidx- start index of search- Returns:
- index of block after of block order index, -1 if not found
-
getIndexOfBlockBefore
Find index of block BEFORE BlockOrder index.- Parameters:
idx- start index of searchblock- used by the warrant- Returns:
- index of block before of block order index, -1 if not found
-
getBlockOrderAt
Call is only valid when in MODE_LEARN and MODE_RUN.- Parameters:
index- index of block order- Returns:
- block order or null if not found
-
getBlockAt
Call is only valid when in MODE_LEARN and MODE_RUN.- Parameters:
idx- index of block order- Returns:
- block of the block order
-
getCurrentBlockName
Call is only valid when in MODE_LEARN and MODE_RUN.- Returns:
- Name of OBlock currently occupied
-
getThrottleCommands
- Returns:
- throttle commands
-
setThrottleCommands
-
addThrottleCommand
-
setTrackSpeeds
-
setNoRamp
-
setAddTracker
-
setHaltStart
-
getNoRamp
-
getAddTracker
-
getHaltStart
-
getTrainName
-
setTrainName
-
getRunBlind
-
setRunBlind
-
fireRunStatus
-
isAllocated
- Returns:
- true if listeners are installed enough to run
-
isTotalAllocated
- Returns:
- true if listeners are installed for entire route
-
hasRouteSet
Turnouts are set for the route- Returns:
- true if turnouts are set
-
routeIsFree
Test if the permanent saved blocks of this warrant are free (unoccupied and unallocated)- Returns:
- true if route is free
-
routeIsOccupied
Test if the permanent saved blocks of this warrant are occupied- Returns:
- true if any block is occupied
-
getMessage
-
isWaitingForSignal
-
isWaitingForBlock
-
isWaitingForWarrant
-
getBlockingWarrant
-
getRunMode
- Returns:
- ID of run mode
-
getRunModeMessage
-
getWarrantSpeedMessage
Get the warrant speed message for the current throttle speed setting. This is public to provide access for scripts and LogixNG formulas.- Returns:
- the current speed message or "Not available".
-
getRunningMessage
-
stopWarrant
-
setRunMode
public String setRunMode(int mode, DccLocoAddress address, LearnThrottleFrame student, List<ThrottleSetting> commands, boolean runBlind) 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
- 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
-
acquireThrottle
- Returns:
- error message if any
-
notifyThrottleFound
Description copied from interface:ThrottleListenerGet notification that a throttle has been found as requested.- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
throttle- the throttle with the requested address
-
notifyFailedThrottleRequest
Description copied from interface:ThrottleListenerGet notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- address of the failed requestreason- failure cause
-
notifyDecisionRequired
No steal or share decisions made locallyGet notification that a throttle request is in use by another device, and a "steal", "share", or "steal/share" decision may be required.
- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- The LocoAddress that needs the decision.question- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
releaseThrottle
-
abortWarrant
-
controlRunTrain
Pause and resume auto-running train or abort any allocation state User issued overriding commands during run time of warrant _engineer.abort() calls setRunMode(MODE_NONE,...) which calls deallocate all.- Parameters:
idx- index of control command- Returns:
- false if command cannot be given
-
debugInfo
-
startupWarrant
-
allocateRoute
Allocate as many blocks as possible from the start of the warrant. The first block must be allocated and all blocks of the route must be in service. Otherwise partial success is OK. Installs listeners for the entire route. If occupation by another train is detected, a message will be posted to the Warrant List Window. Note that warrants sharing their clearance only allocate and set paths one block in advance.- Parameters:
orders- list of block ordersshow- _message for use ONLY to display a temporary route) continues to allocate skipping over blocks occupied or owned by another warrant.- Returns:
- error message, if unable to allocate first block or if any block is OUT_OF_SERVICE
-
deAllocate
Deallocates blocks from the current BlockOrder list -
runWarrant
Convenience routine to use from Python to start a warrant.- Parameters:
mode- run mode
-
setRoute
Set the route paths and turnouts for the warrant. Only the first block must be allocated and have its path set. Partial success is OK. A message of the first subsequent block that fails allocation or path setting is written to a field that is displayed in the Warrant List window. When running with block detection, occupation by another train or block 'not in use' or Signals denying movement are reasons for such a message, otherwise only allocation to another warrant prevents total success. Note that warrants sharing their clearance only allocate and set paths one block in advance.- Parameters:
show- 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
-
checkStartBlock
Check start block for occupied for start of run- Returns:
- error message, if any
-
checkforTrackers
-
checkRoute
Report any occupied blocks in the route- Returns:
- String
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
goingActive
Check if this is the next block of the train moving under the warrant Learn mode assumes route is set and clear. Run mode update conditions.Must be called on Layout thread.
- Parameters:
block- Block in the route is going active.
-
goingInactive
- Parameters:
block- Block in the route is going Inactive
-
dispose
Description copied from class:AbstractNamedBeanDeactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
- Specified by:
disposein interfaceNamedBean- Overrides:
disposein classAbstractNamedBean
-
getBeanType
Description copied from interface:NamedBeanFor instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.- Specified by:
getBeanTypein interfaceNamedBean- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
downRampBegun
-
downRampDone
-
equals
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:
equalsin classAbstractNamedBean- Parameters:
obj- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.
-
hashCode
- Overrides:
hashCodein classAbstractNamedBean- Returns:
- hash code value is based on the system name and DccLocoAddress.
-
getUsageReport
Description copied from interface:NamedBeanGet a list of references for the specified bean.- Specified by:
getUsageReportin interfaceNamedBean- Parameters:
bean- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-