Package jmri.jmrix.loconet
Class LocoNetThrottle
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.jmrix.AbstractThrottle
-
- jmri.jmrix.loconet.LocoNetThrottle
-
- All Implemented Interfaces:
java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,DccThrottle
,SlotListener
,Throttle
- Direct Known Subclasses:
Ib1Throttle
,Ib2Throttle
public class LocoNetThrottle extends AbstractThrottle implements SlotListener
An implementation of DccThrottle via AbstractThrottle with code specific to a LocoNet connection.Speed in the Throttle interfaces and AbstractThrottle is a float, but in LocoNet is an int with values from 0 to 127.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
address
protected boolean
isDisposing
protected int
layout_dirf
protected int
layout_snd
protected int
layout_spd
protected int
layout_stat1
(package private) javax.swing.Timer
mRefreshTimer
protected LocoNetInterface
network
protected boolean
new_isFwd
protected long
new_isFwd_lastupdated
protected int
new_spd
protected long
new_spd_lastupdated
protected LocoNetSlot
slot
protected int
slotStatus
protected LnThrottleManager
throttleManager
-
Fields inherited from class jmri.jmrix.AbstractThrottle
active, adapterMemo, FUNCTION_GROUPS, isForward, speedSetting, speedStepMode, start
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
Fields inherited from interface jmri.Throttle
F0, F0Momentary, F1, F10, F10Momentary, F11, F11Momentary, F12, F12Momentary, F13, F13Momentary, F14, F14Momentary, F15, F15Momentary, F16, F16Momentary, F17, F17Momentary, F18, F18Momentary, F19, F19Momentary, F1Momentary, F2, F20, F20Momentary, F21, F21Momentary, F22, F22Momentary, F23, F23Momentary, F24, F24Momentary, F25, F25Momentary, F26, F26Momentary, F27, F27Momentary, F28, F28Momentary, F2Momentary, F3, F3Momentary, F4, F4Momentary, F5, F5Momentary, F6, F6Momentary, F7, F7Momentary, F8, F8Momentary, F9, F9Momentary, ISFORWARD, SPEEDINCREMENT, SPEEDSETTING, SPEEDSTEPMODE, SPEEDSTEPS
-
-
Constructor Summary
Constructors Constructor Description LocoNetThrottle(LocoNetSystemConnectionMemo memo, LocoNetSlot slot)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispatchThrottle(DccThrottle t, ThrottleListener l)
"Dispatch" a LocoNet throttle by setting the slot as "common" then performing a slot move to slot 0.protected float
floatSpeed(int lSpeed)
Convert a LocoNet speed integer to a float speed valueLocoAddress
getLocoAddress()
Get the address controlled by this throttle.LocoNetSlot
getLocoNetSlot()
Get the LocoNetSlot which is used for controlling the loco assoicated with this throttle.protected int
intSpeed(float fSpeed)
Computes the integer speed value from a float.void
notifyChangedSlot(LocoNetSlot pSlot)
Get notified when underlying slot information changesvoid
notifyRefused(int addr, java.lang.String s)
Get notified when underlying slot acquisition process fails.protected void
sendExpFunctionGroup1()
Send the Expanded LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4, F5, F6protected void
sendExpFunctionGroup2()
Send the Expanded LocoNet message to set the state of functions F7, F8, F8, F9, F10, F11, F12, F13protected void
sendExpFunctionGroup3()
Sends expanded loconet message F14 thru F20 Message.protected void
sendExpFunctionGroup4()
Sends Expanded loconet message F21 thru F28 Message.protected void
sendExpSpeedAndDirection(boolean isFwd)
Send the expanded slot command for speed and direction on change of direction Note we send our stored speed if slot has not yet been updated by the echoprotected void
sendExpSpeedAndDirection(int speed)
Send the expanded slot command for speed and direction on change of speed Note we send our stored values as slot is updated via an echo and may not have been updated yet when sending rapid commandsprotected void
sendFunctionGroup(int functionNum, boolean momentary)
Send whole (DCC) Function Group for a particular function number.protected void
sendFunctionGroup1()
Send the LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4 Unfortunately this is used by all throttles to send direction changes, but the expanded slots dont use this for direction changes, they use speed...protected void
sendFunctionGroup10()
Sends Function Group 10 values - F61 thru F68, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup2()
Send the LocoNet message to set the state of functions F5, F6, F7, F8protected void
sendFunctionGroup3()
Sends Function Group 3 values - F9 thru F12, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup4()
Sends Function Group 4 values - F13 thru F20, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup5()
Sends Function Group 5 values - F21 thru F28, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup6()
Sends Function Group 6 values - F29 thru F36, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup7()
Sends Function Group 7 values - F37 thru F44, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup8()
Sends Function Group 8 values - F45 thru F52, using an "OPC_IMM_PACKET" LocoNet Message.protected void
sendFunctionGroup9()
Sends Function Group 9 values - F53 thru F60, using an "OPC_IMM_PACKET" LocoNet Message.void
setIsForward(boolean forward)
Send a LocoNet message containing the specified direction of travel.void
setSpeedSetting(float speed)
Send a LocoNet message to set the loco speed speed.void
setSpeedSetting(float speed, boolean allowDuplicates, boolean allowDuplicatesOnStop)
Set the speed.void
setSpeedSettingAgain(float speed)
Set the Speed, ensuring that a LocoNet message is sent to update the slot even if the new speed is effectively the same as the current speed.void
setSpeedStepMode(SpeedStepMode Mode)
Set the speed step value and the related speedIncrement value.protected void
startRefresh()
Start the "refresh" timer.void
throttleDispose()
Dispose the LocoNetThrottle when finished with this object.protected void
timeout()
Internal routine to resend the speed on a timeoutjava.lang.String
toString()
protected void
updateFunctions()
update the F0-F29 functions.-
Methods inherited from class jmri.jmrix.AbstractThrottle
addPropertyChangeListener, dispatch, dispose, finishRecord, getFunction, getFunctionMomentary, getFunctionMomentaryNoWarn, getFunctionNoWarn, getFunctions, getFunctionsMomentary, getIsForward, getRosterEntry, getSpeedIncrement, getSpeedSetting, getSpeedStepMode, intSpeed, notifyThrottleDisconnect, notifyThrottleDispatchEnabled, notifyThrottleReleaseEnabled, record, release, removePropertyChangeListener, sendMomentaryFunctionGroup1, sendMomentaryFunctionGroup10, sendMomentaryFunctionGroup2, sendMomentaryFunctionGroup3, sendMomentaryFunctionGroup4, sendMomentaryFunctionGroup5, sendMomentaryFunctionGroup6, sendMomentaryFunctionGroup7, sendMomentaryFunctionGroup8, sendMomentaryFunctionGroup9, setFunction, setFunctionMomentary, setRosterEntry, startClock, updateFunction, updateFunctionMomentary
-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
Methods inherited from interface jmri.Throttle
getF0, getF0Momentary, getF1, getF10, getF10Momentary, getF11, getF11Momentary, getF12, getF12Momentary, getF13, getF13Momentary, getF14, getF14Momentary, getF15, getF15Momentary, getF16, getF16Momentary, getF17, getF17Momentary, getF18, getF18Momentary, getF19, getF19Momentary, getF1Momentary, getF2, getF20, getF20Momentary, getF21, getF21Momentary, getF22, getF22Momentary, getF23, getF23Momentary, getF24, getF24Momentary, getF25, getF25Momentary, getF26, getF26Momentary, getF27, getF27Momentary, getF28, getF28Momentary, getF2Momentary, getF3, getF3Momentary, getF4, getF4Momentary, getF5, getF5Momentary, getF6, getF6Momentary, getF7, getF7Momentary, getF8, getF8Momentary, getF9, getF9Momentary, setF0, setF0Momentary, setF1, setF10, setF10Momentary, setF11, setF11Momentary, setF12, setF12Momentary, setF13, setF13Momentary, setF14, setF14Momentary, setF15, setF15Momentary, setF16, setF16Momentary, setF17, setF17Momentary, setF18, setF18Momentary, setF19, setF19Momentary, setF1Momentary, setF2, setF20, setF20Momentary, setF21, setF21Momentary, setF22, setF22Momentary, setF23, setF23Momentary, setF24, setF24Momentary, setF25, setF25Momentary, setF26, setF26Momentary, setF27, setF27Momentary, setF28, setF28Momentary, setF2Momentary, setF3, setF3Momentary, setF4, setF4Momentary, setF5, setF5Momentary, setF6, setF6Momentary, setF7, setF7Momentary, setF8, setF8Momentary, setF9, setF9Momentary
-
-
-
-
Field Detail
-
slot
protected LocoNetSlot slot
-
network
protected LocoNetInterface network
-
throttleManager
protected LnThrottleManager throttleManager
-
address
protected int address
-
layout_spd
protected int layout_spd
-
layout_dirf
protected int layout_dirf
-
layout_snd
protected int layout_snd
-
layout_stat1
protected int layout_stat1
-
new_spd
protected int new_spd
-
new_spd_lastupdated
protected long new_spd_lastupdated
-
new_isFwd
protected boolean new_isFwd
-
new_isFwd_lastupdated
protected long new_isFwd_lastupdated
-
slotStatus
protected int slotStatus
-
isDisposing
protected boolean isDisposing
-
mRefreshTimer
javax.swing.Timer mRefreshTimer
-
-
Constructor Detail
-
LocoNetThrottle
public LocoNetThrottle(LocoNetSystemConnectionMemo memo, LocoNetSlot slot)
Constructor- Parameters:
memo
- connection detailsslot
- The LocoNetSlot this throttle will talk on.
-
-
Method Detail
-
floatSpeed
protected float floatSpeed(int lSpeed)
Convert a LocoNet speed integer to a float speed value- Parameters:
lSpeed
- LocoNet style speed value- Returns:
- speed as float 0->1.0, or -1.0 to indicate E-Stop
-
intSpeed
protected int intSpeed(float fSpeed)
Computes the integer speed value from a float.Values of less than 0 indicate Emergency Stop.
Value of 0.0 indicates stop.
Values between 0.0+ and 1.0 imply speed step values between 2 and the maximum value allowed for the loco's speed step mode.
- Overrides:
intSpeed
in classAbstractThrottle
- Parameters:
fSpeed
- is the floating-point speed value to be converted- Returns:
- an integer which represents the speed step value
-
sendFunctionGroup
protected void sendFunctionGroup(int functionNum, boolean momentary)
Send whole (DCC) Function Group for a particular function number.- Overrides:
sendFunctionGroup
in classAbstractThrottle
- Parameters:
functionNum
- Function Numbermomentary
- False to send normal function status, true to send momentary.
-
sendFunctionGroup1
protected void sendFunctionGroup1()
Send the LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4 Unfortunately this is used by all throttles to send direction changes, but the expanded slots dont use this for direction changes, they use speed... And we don't know if the caller wants to send functions or direction.- Overrides:
sendFunctionGroup1
in classAbstractThrottle
-
sendFunctionGroup2
protected void sendFunctionGroup2()
Send the LocoNet message to set the state of functions F5, F6, F7, F8- Overrides:
sendFunctionGroup2
in classAbstractThrottle
-
sendFunctionGroup3
protected void sendFunctionGroup3()
Sends Function Group 3 values - F9 thru F12, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup3
in classAbstractThrottle
-
sendFunctionGroup4
protected void sendFunctionGroup4()
Sends Function Group 4 values - F13 thru F20, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup4
in classAbstractThrottle
-
sendFunctionGroup5
protected void sendFunctionGroup5()
Sends Function Group 5 values - F21 thru F28, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup5
in classAbstractThrottle
-
sendFunctionGroup6
protected void sendFunctionGroup6()
Sends Function Group 6 values - F29 thru F36, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup6
in classAbstractThrottle
-
sendFunctionGroup7
protected void sendFunctionGroup7()
Sends Function Group 7 values - F37 thru F44, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup7
in classAbstractThrottle
-
sendFunctionGroup8
protected void sendFunctionGroup8()
Sends Function Group 8 values - F45 thru F52, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup8
in classAbstractThrottle
-
sendFunctionGroup9
protected void sendFunctionGroup9()
Sends Function Group 9 values - F53 thru F60, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup9
in classAbstractThrottle
-
sendFunctionGroup10
protected void sendFunctionGroup10()
Sends Function Group 10 values - F61 thru F68, using an "OPC_IMM_PACKET" LocoNet Message.- Overrides:
sendFunctionGroup10
in classAbstractThrottle
-
sendExpFunctionGroup1
protected void sendExpFunctionGroup1()
Send the Expanded LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4, F5, F6
-
sendExpFunctionGroup2
protected void sendExpFunctionGroup2()
Send the Expanded LocoNet message to set the state of functions F7, F8, F8, F9, F10, F11, F12, F13
-
sendExpFunctionGroup3
protected void sendExpFunctionGroup3()
Sends expanded loconet message F14 thru F20 Message.
-
sendExpFunctionGroup4
protected void sendExpFunctionGroup4()
Sends Expanded loconet message F21 thru F28 Message.
-
sendExpSpeedAndDirection
protected void sendExpSpeedAndDirection(int speed)
Send the expanded slot command for speed and direction on change of speed Note we send our stored values as slot is updated via an echo and may not have been updated yet when sending rapid commands- Parameters:
speed
- the speed to set
-
sendExpSpeedAndDirection
protected void sendExpSpeedAndDirection(boolean isFwd)
Send the expanded slot command for speed and direction on change of direction Note we send our stored speed if slot has not yet been updated by the echo- Parameters:
isFwd
- new direction
-
setSpeedSetting
public void setSpeedSetting(float speed)
Send a LocoNet message to set the loco speed speed.- Specified by:
setSpeedSetting
in interfaceThrottle
- Overrides:
setSpeedSetting
in classAbstractThrottle
- Parameters:
speed
- Number from 0 to 1; less than zero is "emergency stop"
-
setSpeedSettingAgain
public void setSpeedSettingAgain(float speed)
Set the Speed, ensuring that a LocoNet message is sent to update the slot even if the new speed is effectively the same as the current speed. Note: this can cause an increase in LocoNet traffic.- Specified by:
setSpeedSettingAgain
in interfaceThrottle
- Overrides:
setSpeedSettingAgain
in classAbstractThrottle
- Parameters:
speed
- Number from 0 to 1; less than zero is emergency stop
-
setSpeedSetting
public void setSpeedSetting(float speed, boolean allowDuplicates, boolean allowDuplicatesOnStop)
Set the speed. No LocoNet message is sent if the new speed would result in a 'duplicate' - ie. a speed setting no different to the one the slot currently has - unless the boolean paramters indicate it should be.- Specified by:
setSpeedSetting
in interfaceThrottle
- Overrides:
setSpeedSetting
in classAbstractThrottle
- Parameters:
speed
- Number from 0 to 1; less than zero is emergency stopallowDuplicates
- boolean - if true, send a LocoNet message no matter whatallowDuplicatesOnStop
- boolean - if true, send a LocoNet message if the new speed is 'idle' or 'emergency stop', even if that matches the existing speed.
-
setIsForward
public void setIsForward(boolean forward)
Send a LocoNet message containing the specified direction of travel. LocoNet actually puts forward and backward in the same message as the first function group.- Specified by:
setIsForward
in interfaceThrottle
- Overrides:
setIsForward
in classAbstractThrottle
- Parameters:
forward
- is true for forward movement, else false
-
getLocoNetSlot
@CheckForNull public LocoNetSlot getLocoNetSlot()
Get the LocoNetSlot which is used for controlling the loco assoicated with this throttle.- Returns:
- the LocoNetSlot
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
throttleDispose
public void throttleDispose()
Dispose the LocoNetThrottle when finished with this object. After this is executed, further use of this Throttle object will result in a JmriException.- Specified by:
throttleDispose
in classAbstractThrottle
-
startRefresh
protected void startRefresh()
Start the "refresh" timer. The "refresh" timer determines when to send a new LocoNet message to "refresh" the slot's speed setting, so that the slot does not get "purged".
-
timeout
protected void timeout()
Internal routine to resend the speed on a timeout
-
notifyRefused
public void notifyRefused(int addr, java.lang.String s)
Get notified when underlying slot acquisition process fails. Slot acquisition failure is handled by @link LnThrottleManager, so no code is required here.- Parameters:
addr
- Locomotive addresss
- reason the acquisition failed
-
notifyChangedSlot
public void notifyChangedSlot(LocoNetSlot pSlot)
Get notified when underlying slot information changes- Specified by:
notifyChangedSlot
in interfaceSlotListener
- Parameters:
pSlot
- the slot which was changed
-
updateFunctions
protected void updateFunctions()
update the F0-F29 functions. Invoked by notifyChangedSlot(), this nominally updates from the slot.
-
setSpeedStepMode
public void setSpeedStepMode(SpeedStepMode Mode)
Set the speed step value and the related speedIncrement value.- Specified by:
setSpeedStepMode
in interfaceDccThrottle
- Overrides:
setSpeedStepMode
in classAbstractThrottle
- Parameters:
Mode
- the current speed step mode - default should be 128 speed step mode in most cases
-
getLocoAddress
public LocoAddress getLocoAddress()
Get the address controlled by this throttle. If the throttle is controlling.- Specified by:
getLocoAddress
in interfaceThrottle
- Returns:
- a LocoAddress for the address controlled by this throttle
-
dispatchThrottle
public void dispatchThrottle(DccThrottle t, ThrottleListener l)
"Dispatch" a LocoNet throttle by setting the slot as "common" then performing a slot move to slot 0.The throttle being dispatched no longer has control of the loco, but other throttles may continue to control the loco.
- Parameters:
t
- throttle being dispatchedl
- throttle listener to remove
-
-