Class CbusThrottleManager
- java.lang.Object
-
- jmri.jmrix.AbstractThrottleManager
-
- jmri.jmrix.can.cbus.CbusThrottleManager
-
- All Implemented Interfaces:
java.util.EventListener
,Disposable
,AbstractMRListener
,CanListener
,ThrottleManager
public class CbusThrottleManager extends AbstractThrottleManager implements CanListener, Disposable
CBUS implementation of a ThrottleManager.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractThrottleManager
AbstractThrottleManager.Addresses
-
-
Field Summary
Fields Modifier and Type Field Description protected int
THROTTLE_TIMEOUT
-
Fields inherited from class jmri.jmrix.AbstractThrottleManager
adapterMemo, userName
-
-
Constructor Summary
Constructors Constructor Description CbusThrottleManager(CanSystemConnectionMemo memo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addressTypeUnique()
Short and long address spaces overlap and are not unique.boolean
canBeLongAddress(int address)
Any address is potentially a long address.boolean
canBeShortAddress(int address)
Address 127 and below is a short address.void
cancelThrottleRequest(LocoAddress address, ThrottleListener l)
Cancel a request for a throttle.void
dispose()
Allow to cleanly release the traffic controller in ThrottleManager Tests remove listeners, if any stop timers, is anyboolean
disposeThrottle(DccThrottle t, ThrottleListener l)
Not for general use, seereleaseThrottle
anddispatchThrottle
.boolean
enablePrefSilentShareOption()
Hardware has a sharing implementation.boolean
enablePrefSilentStealOption()
Hardware has a stealing implementation.protected void
forceDisposeThrottle(LocoAddress la)
Throttle can no longer be relied upon, potentially from an external forced steal or hardware error.boolean
hasDispatchFunction()
CBUS has a dynamic Dispatch function, defaulting to false Check to see if the Dispatch Button should be enabled or not Default to true, override if necessary(package private) static boolean
isLongAddress(int num)
Local method for deciding short/long address.protected void
makeHardwareDecision(LocoAddress address, ThrottleListener.DecisionType question)
CBUS Hardware will make its own decision on preferred option.void
message(CanMessage m)
Called when an outgoing message is sent to the CAN Network.void
reply(CanReply m)
Called when an incoming CanFrame is received from the CAN Network.void
requestThrottleSetup(LocoAddress address, boolean control)
Abstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC system.void
responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision)
Send a request to steal or share a requested throttle.protected boolean
singleUse()
CBUS allows Throttle sharing, both internally within JMRI and externally by command stationsjava.util.EnumSet<SpeedStepMode>
supportedSpeedModes()
MERG CBUS Throttle sessions default to 128 SS.protected void
updateNumUsers(LocoAddress la, int numUsers)
The number of users of this throttle has been updated-
Methods inherited from class jmri.jmrix.AbstractThrottleManager
addressReleased, addressStillRequired, addressStillRequired, addressStillRequired, addressStillRequired, attachListener, cancelThrottleRequest, cancelThrottleRequest, cancelThrottleRequest, dispatchThrottle, failedThrottleRequest, getAddress, getAddress, getAddressProtocolTypes, getAddressTypes, getAddressTypeString, getProtocolFromString, getThrottleInfo, getThrottleUsageCount, getThrottleUsageCount, getThrottleUsageCount, getThrottleUsageCount, getUserName, hideStealNotifications, notifyDecisionRequest, notifyThrottleKnown, releaseThrottle, removeListener, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottleSetup, responseThrottleDecision, responseThrottleDecision, showSessionCancelDialogue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.can.CanListener
addTc, addTc, removeTc, removeTc
-
-
-
-
Field Detail
-
THROTTLE_TIMEOUT
protected int THROTTLE_TIMEOUT
-
-
Constructor Detail
-
CbusThrottleManager
public CbusThrottleManager(CanSystemConnectionMemo memo)
-
-
Method Detail
-
dispose
public void dispose()
Allow to cleanly release the traffic controller in ThrottleManager Tests- remove listeners, if any
- stop timers, is any
- Specified by:
dispose
in interfaceDisposable
- Specified by:
dispose
in interfaceThrottleManager
- Overrides:
dispose
in classAbstractThrottleManager
-
singleUse
protected boolean singleUse()
CBUS allows Throttle sharing, both internally within JMRI and externally by command stationsDoes this DCC system allow a Throttle (e.g. an address) to be used by only one user at a time?
- Overrides:
singleUse
in classAbstractThrottleManager
- Returns:
- true or false
-
requestThrottleSetup
public void requestThrottleSetup(LocoAddress address, boolean control)
Abstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC system.- Specified by:
requestThrottleSetup
in classAbstractThrottleManager
- Parameters:
address
- addresscontrol
- false - read only.
-
message
public void message(CanMessage m)
Called when an outgoing message is sent to the CAN Network.- Specified by:
message
in interfaceCanListener
- Parameters:
m
- the CanMessage being sent.
-
reply
public void reply(CanReply m)
Called when an incoming CanFrame is received from the CAN Network.- Specified by:
reply
in interfaceCanListener
- Parameters:
m
- the CanReply being received.
-
hasDispatchFunction
public boolean hasDispatchFunction()
CBUS has a dynamic Dispatch function, defaulting to false Check to see if the Dispatch Button should be enabled or not Default to true, override if necessary- Specified by:
hasDispatchFunction
in interfaceThrottleManager
- Overrides:
hasDispatchFunction
in classAbstractThrottleManager
- Returns:
- true if dispatch is possible; false otherwise
-
canBeLongAddress
public boolean canBeLongAddress(int address)
Any address is potentially a long address. Test if a specific number is a valid long address on this system.- Specified by:
canBeLongAddress
in interfaceThrottleManager
- Parameters:
address
- address number to test- Returns:
- true if address can be long; false otherwise
-
canBeShortAddress
public boolean canBeShortAddress(int address)
Address 127 and below is a short address. Test if a specific number is a valid short address on this system.- Specified by:
canBeShortAddress
in interfaceThrottleManager
- Parameters:
address
- address number to test- Returns:
- true if address can be short; false otherwise
-
addressTypeUnique
public boolean addressTypeUnique()
Short and long address spaces overlap and are not unique.- Specified by:
addressTypeUnique
in interfaceThrottleManager
- Returns:
- always false. true if ambiguous addresses are not allowed; false otherwise
-
isLongAddress
static boolean isLongAddress(int num)
Local method for deciding short/long address.- Parameters:
num
- the address number- Returns:
- true if address equal to or greater than 128.
-
enablePrefSilentStealOption
public boolean enablePrefSilentStealOption()
Hardware has a stealing implementation. Hardware that uses the Silent Steal preference will need to override Test if the Silent Steal Throttles preference option should be enabled.- Specified by:
enablePrefSilentStealOption
in interfaceThrottleManager
- Overrides:
enablePrefSilentStealOption
in classAbstractThrottleManager
- Returns:
- true if steal is possible; false otherwise
-
enablePrefSilentShareOption
public boolean enablePrefSilentShareOption()
Hardware has a sharing implementation. Hardware that uses the Silent Share preference will need to override Test if the Silent Share Throttles preference option should be enabled.- Specified by:
enablePrefSilentShareOption
in interfaceThrottleManager
- Overrides:
enablePrefSilentShareOption
in classAbstractThrottleManager
- Returns:
- true if steal is possible; false otherwise
-
makeHardwareDecision
protected void makeHardwareDecision(LocoAddress address, ThrottleListener.DecisionType question)
CBUS Hardware will make its own decision on preferred option.This is the default for scripts that do NOT have a GUI for asking what to do when a steal / share decision is required. For when a steal / share decision is needed and the ThrottleListener has delegated this decision to the ThrottleManager.
Responds to the question by requesting a Throttle "Steal" by default.
Can be overridden by hardware types which do not wish the default behaviour to Steal.
This applies only to those systems where "stealing" or "sharing" applies, such as LocoNet.
- Overrides:
makeHardwareDecision
in classAbstractThrottleManager
- Parameters:
address
- The LocoAddress the steal / share question relates toquestion
- The Question to be put to the ThrottleListener
-
responseThrottleDecision
public void responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision)
Send a request to steal or share a requested throttle.Steal or Share a requested throttle.
- Specified by:
responseThrottleDecision
in interfaceThrottleManager
- Overrides:
responseThrottleDecision
in classAbstractThrottleManager
- Parameters:
address
- desired LocoAddressl
- The ThrottleListener which has made the decisiondecision
- from the ThrottleListener, STEAL or SHARE.
-
supportedSpeedModes
public java.util.EnumSet<SpeedStepMode> supportedSpeedModes()
MERG CBUS Throttle sessions default to 128 SS. This can be changed by a subsequent message from Throttle to CS, or by message from Command Station to CbusThrottle. Supported modes are 128, 28 and 14. What speed modes are supported by this system? value should be xor of possible modes specifed by the DccThrottle interface- Specified by:
supportedSpeedModes
in interfaceThrottleManager
- Overrides:
supportedSpeedModes
in classAbstractThrottleManager
- Returns:
- an XOR of the possible modes specified in the throttle interface
-
disposeThrottle
public boolean disposeThrottle(DccThrottle t, ThrottleListener l)
Not for general use, seereleaseThrottle
anddispatchThrottle
.Dispose of object when finished it. This will free up hardware resource
Used for handling certain internal error conditions, where the object still exists but hardware is not associated with it.
After this, further usage of this Throttle object will result in a JmriException.
- Specified by:
disposeThrottle
in interfaceThrottleManager
- Overrides:
disposeThrottle
in classAbstractThrottleManager
- Parameters:
t
- Throttle being releasedl
- Throttle Listener releasing the throttle- Returns:
- true if the throttle has been disposed of.
-
forceDisposeThrottle
protected void forceDisposeThrottle(LocoAddress la)
Throttle can no longer be relied upon, potentially from an external forced steal or hardware error.Normally, #releaseThrottle should be used to close throttles.
Removes locoaddress from list to force new throttle requests to request new sessions where the Command station model implements a dynamic stack, not a static stack.
Managers still need to advise listeners that the session has been cancelled and actually dispose of the throttle
- Overrides:
forceDisposeThrottle
in classAbstractThrottleManager
- Parameters:
la
- address release
-
updateNumUsers
protected void updateNumUsers(LocoAddress la, int numUsers)
The number of users of this throttle has been updatedTypically used to update dispatch / release availablility specific implementations can override this function to get updates
- Overrides:
updateNumUsers
in classAbstractThrottleManager
- Parameters:
la
- the Loco Address which has been updatednumUsers
- current number of users
-
cancelThrottleRequest
public void cancelThrottleRequest(LocoAddress address, ThrottleListener l)
Cancel a request for a throttle.- Specified by:
cancelThrottleRequest
in interfaceThrottleManager
- Overrides:
cancelThrottleRequest
in classAbstractThrottleManager
- Parameters:
address
- unwanted Loco addressl
- ThrottleListener canceling request for a throttle
-
-