Package jmri.jmrit.withrottle
Class ThrottleController
- java.lang.Object
-
- jmri.jmrit.withrottle.ThrottleController
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.util.EventListener
,ThrottleListener
- Direct Known Subclasses:
MultiThrottleController
public class ThrottleController extends java.lang.Object implements ThrottleListener, java.beans.PropertyChangeListener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<ControllerInterface>
controllerListeners
(package private) DccThrottle
functionThrottle
(package private) boolean
isAddressSet
(package private) boolean
isMomF2
protected java.util.Queue<java.lang.Float>
lastSentSpeed
(package private) DccLocoAddress
leadAddress
(package private) ConsistFunctionController
leadLocoF
protected java.util.ArrayList<ThrottleControllerListener>
listeners
(package private) java.lang.String
locoKey
protected float
newSpeed
(package private) RosterEntry
rosterLoco
(package private) float
speedMultiplier
(package private) DccThrottle
throttle
(package private) boolean
useLeadLocoF
(package private) char
whichThrottle
-
Constructor Summary
Constructors Constructor Description ThrottleController()
ThrottleController(char whichThrottleChar, ThrottleControllerListener tcl, ControllerInterface cl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addControllerListener(ControllerInterface listener)
Add a listener to handle: listener.sendPacketToDevice(message);void
addressDispatch()
void
addressRelease()
Receive notification that an address has been released/dispatchedvoid
addThrottleControllerListener(ThrottleControllerListener l)
protected java.lang.String
buildFStatesHeader()
protected void
eStop()
RosterEntry
findRosterEntry(DccThrottle t)
protected void
forceFunction(java.lang.String inPackage)
DccLocoAddress
getCurrentAddress()
java.lang.String
getCurrentAddressString()
Get the string representation of this throttles address.java.lang.String
getCurrentRosterIdString()
Get the string representation of this Roster ID.DccThrottle
getFunctionThrottle()
DccThrottle
getThrottle()
protected void
handleFunction(java.lang.String inPackage)
protected void
handleMomentary(java.lang.String inPackage)
protected void
handleRequest(java.lang.String inPackage)
protected void
handleSpeedStepMode(SpeedStepMode newMode)
protected void
idle()
void
notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
calls notifyFailedThrottleRequest, Steal Requiredvoid
notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Get notification that an attempt to request a throttle has failed.void
notifyThrottleFound(DccThrottle t)
Receive notification that a DccThrottle has been found and is in use.void
propertyChange(java.beans.PropertyChangeEvent event)
void
removeControllerListener(ControllerInterface listener)
void
removeThrottleControllerListener(ThrottleControllerListener l)
void
requestEntryFromID(java.lang.String id)
void
sendAddress()
void
sendAllFunctionStates(DccThrottle t)
send all function states, primarily for initial status Current Format: RPF}|{whichThrottle]\[function}|{state]\[function}|{state...protected void
sendAllMomentaryStates(DccThrottle t)
protected void
sendCurrentDirection(DccThrottle t)
protected void
sendCurrentSpeed(DccThrottle t)
void
sendFunctionLabels(RosterEntry re)
Send function labels for a roster entry, using old format.protected void
sendSpeedStepMode(DccThrottle t)
protected void
setAddress(int number, boolean isLong)
protected void
setDirection(boolean isForward)
void
setFunctionThrottle(DccThrottle t)
void
setLocoForConsistFunctions(java.lang.String inPackage)
void
setRosterLocoForConsistFunctions(java.lang.String id)
protected void
setSpeed(int rawSpeed)
handle the conversion from rawSpeed to the float value needed in the DccThrottlevoid
setWhichThrottle(char c)
void
shutdownThrottle()
boolean
sort(java.lang.String inPackage)
Figure out what the received command means, where it has to go, and translate to a jmri method.void
syncThrottleFunctions(DccThrottle t, RosterEntry re)
-
-
-
Field Detail
-
throttle
DccThrottle throttle
-
functionThrottle
DccThrottle functionThrottle
-
rosterLoco
RosterEntry rosterLoco
-
leadAddress
DccLocoAddress leadAddress
-
whichThrottle
char whichThrottle
-
speedMultiplier
float speedMultiplier
-
lastSentSpeed
protected java.util.Queue<java.lang.Float> lastSentSpeed
-
newSpeed
protected float newSpeed
-
isAddressSet
boolean isAddressSet
-
listeners
protected java.util.ArrayList<ThrottleControllerListener> listeners
-
controllerListeners
protected java.util.ArrayList<ControllerInterface> controllerListeners
-
useLeadLocoF
boolean useLeadLocoF
-
leadLocoF
ConsistFunctionController leadLocoF
-
locoKey
java.lang.String locoKey
-
isMomF2
final boolean isMomF2
-
-
Constructor Detail
-
ThrottleController
public ThrottleController()
-
ThrottleController
public ThrottleController(char whichThrottleChar, ThrottleControllerListener tcl, ControllerInterface cl)
-
-
Method Detail
-
setWhichThrottle
public void setWhichThrottle(char c)
-
addThrottleControllerListener
public void addThrottleControllerListener(ThrottleControllerListener l)
-
removeThrottleControllerListener
public void removeThrottleControllerListener(ThrottleControllerListener l)
-
addControllerListener
public void addControllerListener(ControllerInterface listener)
Add a listener to handle: listener.sendPacketToDevice(message);- Parameters:
listener
- handle of listener to add
-
removeControllerListener
public void removeControllerListener(ControllerInterface listener)
-
addressRelease
public void addressRelease()
Receive notification that an address has been released/dispatched
-
addressDispatch
public void addressDispatch()
-
notifyThrottleFound
public void notifyThrottleFound(DccThrottle t)
Receive notification that a DccThrottle has been found and is in use.- Specified by:
notifyThrottleFound
in interfaceThrottleListener
- Parameters:
t
- The throttle which has been found
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Description copied from interface:ThrottleListener
Get notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequest
in interfaceThrottleListener
- Parameters:
address
- address of the failed requestreason
- failure cause
-
notifyDecisionRequired
public void notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
calls notifyFailedThrottleRequest, Steal RequiredGet notification that a throttle request is in use by another device, and a "steal", "share", or "steal/share" decision may be required.
- Specified by:
notifyDecisionRequired
in interfaceThrottleListener
- Parameters:
address
- The LocoAddress that needs the decision.question
- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent event)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
findRosterEntry
public RosterEntry findRosterEntry(DccThrottle t)
-
syncThrottleFunctions
public void syncThrottleFunctions(DccThrottle t, RosterEntry re)
-
sendFunctionLabels
public void sendFunctionLabels(RosterEntry re)
Send function labels for a roster entry, using old format. This implementation is legacy and should not change from the limit of 29 functions.- Parameters:
re
- The roster entry to get the labels from.
-
sendAllFunctionStates
public void sendAllFunctionStates(DccThrottle t)
send all function states, primarily for initial status Current Format: RPF}|{whichThrottle]\[function}|{state]\[function}|{state... This implementation is legacy and should not change from the limit of 29 functions.- Parameters:
t
- throttle to send functions to
-
buildFStatesHeader
protected java.lang.String buildFStatesHeader()
-
sendCurrentSpeed
protected void sendCurrentSpeed(DccThrottle t)
-
sendCurrentDirection
protected void sendCurrentDirection(DccThrottle t)
-
sendSpeedStepMode
protected void sendSpeedStepMode(DccThrottle t)
-
sendAllMomentaryStates
protected void sendAllMomentaryStates(DccThrottle t)
-
sort
public boolean sort(java.lang.String inPackage)
Figure out what the received command means, where it has to go, and translate to a jmri method.- Parameters:
inPackage
- The package minus its prefix which steered it here.- Returns:
- true to keep reading in run loop.
-
setFunctionThrottle
public void setFunctionThrottle(DccThrottle t)
-
setLocoForConsistFunctions
public void setLocoForConsistFunctions(java.lang.String inPackage)
-
setRosterLocoForConsistFunctions
public void setRosterLocoForConsistFunctions(java.lang.String id)
-
shutdownThrottle
public void shutdownThrottle()
-
setSpeed
protected void setSpeed(int rawSpeed)
handle the conversion from rawSpeed to the float value needed in the DccThrottle- Parameters:
rawSpeed
- Value sent from mobile device, range 0 - 126
-
setDirection
protected void setDirection(boolean isForward)
-
eStop
protected void eStop()
-
idle
protected void idle()
-
setAddress
protected void setAddress(int number, boolean isLong)
-
requestEntryFromID
public void requestEntryFromID(java.lang.String id)
-
getThrottle
public DccThrottle getThrottle()
-
getFunctionThrottle
public DccThrottle getFunctionThrottle()
-
getCurrentAddress
public DccLocoAddress getCurrentAddress()
-
getCurrentAddressString
public java.lang.String getCurrentAddressString()
Get the string representation of this throttles address. Returns 'Not Set' if no address in use.- Returns:
- string value of throttle address
-
getCurrentRosterIdString
public java.lang.String getCurrentRosterIdString()
Get the string representation of this Roster ID. Returns empty string if no address in use. since 4.15.4- Returns:
- string value of throttle Roster ID
-
sendAddress
public void sendAddress()
-
handleFunction
protected void handleFunction(java.lang.String inPackage)
-
forceFunction
protected void forceFunction(java.lang.String inPackage)
-
handleSpeedStepMode
protected void handleSpeedStepMode(SpeedStepMode newMode)
-
handleMomentary
protected void handleMomentary(java.lang.String inPackage)
-
handleRequest
protected void handleRequest(java.lang.String inPackage)
-
-