jmri.jmrit.logix
Class Warrant

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.jmrit.logix.Warrant
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, NamedBean, ThrottleListener

public class Warrant
extends AbstractNamedBean
implements ThrottleListener, PropertyChangeListener

An Warrant contains the operating permissions and directives needed for a train to proceed from an Origin to a Destination

Version 1.11 - remove setting of SignalHeads

Author:
Pete Cressman Copyright (C) 2009, 2010
See Also:
Serialized Form

Field Summary
protected  List<ThrottleSetting> _commands
           
protected  int _idxCurrentOrder
           
protected  boolean _tempRunBlind
           
protected  float _throttleFactor
           
static int ABORT
           
static int HALT
           
static int MODE_LEARN
           
static int MODE_MANUAL
           
static int MODE_NONE
           
static int MODE_RUN
           
static int RESUME
           
static int RUNNING
           
static int SPEED_RESTRICTED
           
static int WAIT_FOR_CLEAR
           
static int WAIT_FOR_TRAIN
           
 
Fields inherited from class jmri.implementation.AbstractNamedBean
mSystemName, mUserName
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT, UNKNOWN
 
Constructor Summary
Warrant(String sName, String uName)
          Create an object with no route defined.
 
Method Summary
 void addBlockOrder(BlockOrder order)
          Add permanently saved BlockOrder
 void addThrottleCommand(ThrottleSetting ts)
           
 String allocateRoute()
          Allocate the current saved blocks of this warrant.
 void clearAll()
           
 boolean controlRunTrain(int idx)
          Pause and resume auto-running train or abort any allocation state _engineer.abort() calls setRunMode(MODE_NONE,...) which calls deallocate all.
 void deAllocate()
          Deallocates blocks from the current BlockOrder list
protected  void fireRunStatus(String property, Object old, Object status)
          Engineer reports its status
 BlockOrder getAvoidOrder()
           
protected  OBlock getBlockAt(int idx)
          Call is only valid when in MODE_LEARN and MODE_RUN
protected  BlockOrder getBlockOrderAt(int index)
          Call is only valid when in MODE_LEARN and MODE_RUN
 BlockOrder getCurrentBlockOrder()
          Call is only valid when in MODE_LEARN and MODE_RUN
 int getCurrentCommandIndex()
           
 int getCurrentOrderIndex()
           
 DccLocoAddress getDccAddress()
           
 BlockOrder getfirstOrder()
          Return permanently saved Origin
protected  int getIndexOfBlock(OBlock block)
          Call is only valid when in MODE_LEARN and MODE_RUN
protected  int getIndexOfBlock(String name)
          Call is only valid when in MODE_LEARN and MODE_RUN
 BlockOrder getLastOrder()
          Return permanently saved Destination
 List<BlockOrder> getOrders()
          Return permanently saved BlockOrders
protected  String getRoutePathInBlock(OBlock block)
           
 boolean getRunBlind()
           
 int getRunMode()
          Methods for running trains
 String getRunningMessage()
           
static SignalSpeedMap getSpeedMap()
           
 int getState()
          Provide generic access to internal state.
 List<ThrottleSetting> getThrottleCommands()
           
 String getTrainId()
           
 String getTrainName()
           
 BlockOrder getViaOrder()
          Return permanently saved BlockOrder that must be included in the route
protected  void goingActive(OBlock block)
          Block in the route is going active.
protected  void goingInactive(OBlock block)
          Block in the route is going Inactive
 boolean hasRouteSet()
          Turnouts and signals are set for the route
 boolean isAllocated()
          Listeners are installed for the route
 void notifyFailedThrottleRequest(DccLocoAddress address, String reason)
          Get notification that an attempt to request a throttle has failed
 void notifyThrottleFound(DccThrottle throttle)
          Get notification that a throttle has been found as you requested.
 void propertyChange(PropertyChangeEvent evt)
           
 boolean routeIsFree()
          Test if the permanent saved blocks of this warrant are free (unoccupied and unallocated)
 boolean routeIsOccupied()
          Test if the permanent saved blocks of this warrant are occupied
 String runAutoTrain(boolean run)
          Starts or ends an automated train run.
 void setAvoidOrder(BlockOrder order)
           
 void setDccAddress(DccLocoAddress address)
           
 String setRoute(int delay, List<BlockOrder> orders)
          Set the route paths and turnouts for the warrant.
 void setRunBlind(boolean runBlind)
           
protected  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.
 void setState(int state)
          Provide generic access to internal state.
 String setThrottleFactor(String sFactor)
           
 boolean setTrainId(String id)
           
 void setTrainName(String name)
           
 void setViaOrder(BlockOrder order)
           
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, dispose, firePropertyChange, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, removePropertyChangeListener, setComment, setProperty, setUserName, updateListenerRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tempRunBlind

protected boolean _tempRunBlind

_throttleFactor

protected float _throttleFactor

_commands

protected List<ThrottleSetting> _commands

_idxCurrentOrder

protected int _idxCurrentOrder

MODE_NONE

public static final int MODE_NONE
See Also:
Constant Field Values

MODE_LEARN

public static final int MODE_LEARN
See Also:
Constant Field Values

MODE_RUN

public static final int MODE_RUN
See Also:
Constant Field Values

MODE_MANUAL

public static final int MODE_MANUAL
See Also:
Constant Field Values

HALT

public static final int HALT
See Also:
Constant Field Values

RESUME

public static final int RESUME
See Also:
Constant Field Values

ABORT

public static final int ABORT
See Also:
Constant Field Values

WAIT_FOR_TRAIN

public static final int WAIT_FOR_TRAIN
See Also:
Constant Field Values

RUNNING

public static final int RUNNING
See Also:
Constant Field Values

SPEED_RESTRICTED

public static final int SPEED_RESTRICTED
See Also:
Constant Field Values

WAIT_FOR_CLEAR

public static final int WAIT_FOR_CLEAR
See Also:
Constant Field Values
Constructor Detail

Warrant

public Warrant(String sName,
               String uName)
Create an object with no route defined. The list of BlockOrders is the route from an Origin to a Destination

Method Detail

getSpeedMap

public static final SignalSpeedMap getSpeedMap()

getState

public int getState()
Description copied from interface: NamedBean
Provide 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 provided to make Jython script access easier to read.

Specified by:
getState in interface NamedBean

setState

public void setState(int state)
Description copied from interface: NamedBean
Provide 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 provided to make Jython script access easier to read.

Specified by:
setState in interface NamedBean

clearAll

public void clearAll()

getOrders

public List<BlockOrder> getOrders()
Return permanently saved BlockOrders


addBlockOrder

public void addBlockOrder(BlockOrder order)
Add permanently saved BlockOrder


getfirstOrder

public BlockOrder getfirstOrder()
Return permanently saved Origin


getLastOrder

public BlockOrder getLastOrder()
Return permanently saved Destination


getViaOrder

public BlockOrder getViaOrder()
Return permanently saved BlockOrder that must be included in the route


setViaOrder

public void setViaOrder(BlockOrder order)

getAvoidOrder

public BlockOrder getAvoidOrder()

setAvoidOrder

public void setAvoidOrder(BlockOrder order)

getRoutePathInBlock

protected String getRoutePathInBlock(OBlock block)

getCurrentBlockOrder

public BlockOrder getCurrentBlockOrder()
Call is only valid when in MODE_LEARN and MODE_RUN


getCurrentOrderIndex

public int getCurrentOrderIndex()

getIndexOfBlock

protected int getIndexOfBlock(OBlock block)
Call is only valid when in MODE_LEARN and MODE_RUN


getIndexOfBlock

protected int getIndexOfBlock(String name)
Call is only valid when in MODE_LEARN and MODE_RUN


getBlockOrderAt

protected BlockOrder getBlockOrderAt(int index)
Call is only valid when in MODE_LEARN and MODE_RUN


getBlockAt

protected OBlock getBlockAt(int idx)
Call is only valid when in MODE_LEARN and MODE_RUN


getThrottleCommands

public List<ThrottleSetting> getThrottleCommands()

addThrottleCommand

public void addThrottleCommand(ThrottleSetting ts)

getTrainName

public String getTrainName()

setTrainName

public void setTrainName(String name)

getTrainId

public String getTrainId()

setTrainId

public boolean setTrainId(String id)
Parameters:
id - may be either Roster entry or DCC address
Returns:
id is valid

getDccAddress

public DccLocoAddress getDccAddress()

setDccAddress

public void setDccAddress(DccLocoAddress address)

getRunBlind

public boolean getRunBlind()

setRunBlind

public void setRunBlind(boolean runBlind)

setThrottleFactor

public String setThrottleFactor(String sFactor)

fireRunStatus

protected void fireRunStatus(String property,
                             Object old,
                             Object status)
Engineer reports its status


isAllocated

public boolean isAllocated()
Listeners are installed for the route


hasRouteSet

public boolean hasRouteSet()
Turnouts and signals are set for the route


routeIsFree

public boolean routeIsFree()
Test if the permanent saved blocks of this warrant are free (unoccupied and unallocated)


routeIsOccupied

public boolean routeIsOccupied()
Test if the permanent saved blocks of this warrant are occupied


getRunMode

public int getRunMode()
Methods for running trains


runAutoTrain

public String runAutoTrain(boolean run)
Starts or ends an automated train run. setRoute nust be called before calling this method.

Parameters:
run - set Run throttle command or Stop
Returns:
returns an error message (or null on success)

getRunningMessage

public String getRunningMessage()

getCurrentCommandIndex

public int getCurrentCommandIndex()

setRunMode

protected 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


controlRunTrain

public boolean controlRunTrain(int idx)
Pause and resume auto-running train or abort any allocation state _engineer.abort() calls setRunMode(MODE_NONE,...) which calls deallocate all.


notifyThrottleFound

public void notifyThrottleFound(DccThrottle throttle)
Description copied from interface: ThrottleListener
Get notification that a throttle has been found as you requested.

Specified by:
notifyThrottleFound in interface ThrottleListener
Parameters:
throttle - An instantiation of the DccThrottle with the address requested.

notifyFailedThrottleRequest

public void notifyFailedThrottleRequest(DccLocoAddress address,
                                        String reason)
Description copied from interface: ThrottleListener
Get notification that an attempt to request a throttle has failed

Specified by:
notifyFailedThrottleRequest in interface ThrottleListener
Parameters:
address - DccLocoAddress of the failed loco request.
reason - The reason why the throttle request failed.

allocateRoute

public String allocateRoute()
Allocate the current saved blocks of this warrant. Installs listeners for the entire route. Sets this warrant into

Returns:
error messge, if any

deAllocate

public void deAllocate()
Deallocates blocks from the current BlockOrder list


setRoute

public String setRoute(int delay,
                       List<BlockOrder> orders)
Set the route paths and turnouts for the warrant. Returns the name of the first block that failed allocation to this warrant. When running with block detection, only the first block must be allocated and have its path set.

Parameters:
delay - - delay in seconds, between setting signals and throwing turnouts
orders - - BlockOrder list of route. If null, use permanent warrant copy.
Returns:
message of block that failed allocation to this warrant or null

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

goingActive

protected void goingActive(OBlock block)
Block in the route is going active. check if this is the next block of the train moving under the warrant Learn mode assumes route is set and clear


goingInactive

protected void goingInactive(OBlock block)
Block in the route is going Inactive



Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads