Package jmri.jmrix.lenz
Class XNetThrottle
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.jmrix.AbstractThrottle
-
- jmri.jmrix.lenz.XNetThrottle
-
- All Implemented Interfaces:
java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,DccThrottle
,AbstractMRListener
,XNetListener
,Throttle
- Direct Known Subclasses:
EliteXNetThrottle
,RocoXNetThrottle
public class XNetThrottle extends AbstractThrottle implements XNetListener
An implementation of DccThrottle with code specific to an XpressNet connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
XNetThrottle.RequestMessage
Internal class to hold a request message, along with the associated throttle state.
-
Field Summary
Fields Modifier and Type Field Description protected int
address
protected boolean
isAvailable
protected java.util.concurrent.LinkedBlockingQueue<XNetThrottle.RequestMessage>
requestList
protected int
requestState
protected static int
statTimeoutValue
protected java.util.TimerTask
statusTask
protected XNetTrafficController
tc
protected static int
THROTTLEFUNCSENT
protected static int
THROTTLEHIGHMOMSTATSENT
protected static int
THROTTLEHIGHSTATSENT
protected static int
THROTTLEIDLE
protected static int
THROTTLEMOMSTATSENT
protected static int
THROTTLESPEEDSENT
protected static int
THROTTLESTATSENT
-
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 XNetThrottle(XNetSystemConnectionMemo memo, XNetTrafficController controller)
ConstructorXNetThrottle(XNetSystemConnectionMemo memo, LocoAddress address, XNetTrafficController controller)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkForFunctionMomentaryValueChange(int funcNum, int bytevalue, int bitmask, boolean currentValue)
protected boolean
csVersionSupportFn13to28()
protected boolean
csVersionSupportFn29to68()
int
getDccAddress()
protected int
getDccAddressHigh()
protected int
getDccAddressLow()
LocoAddress
getLocoAddress()
Locomotive address.void
message(XNetMessage l)
Member function that will be invoked by an XNetInterface implementation to forward an XNet message sent to the layout.void
message(XNetReply l)
Member function that will be invoked by an XNetInterface implementation to forward an XNet message from the layout.protected void
notifyNewDirection(boolean forward)
protected void
notifyNewSpeedStepMode(SpeedStepMode mode)
void
notifyTimeout(XNetMessage msg)
Member function invoked by an XNetInterface implementation to notify a sender that an outgoing message timed out and was dropped from the queue.protected void
parseFunctionHighInformation(int b3, int b4)
protected void
parseFunctionHighMomentaryInformation(int b3, int b4)
protected void
parseFunctionInformation(int b3, int b4)
protected void
parseFunctionMomentaryInformation(int b3, int b4)
protected void
parseSpeedAndAvailability(int b1)
Get SpeedStep and availability information.protected void
parseSpeedAndDirection(int b2)
Get Speed and Direction information.protected void
queueMessage(XNetMessage m, int s)
Queue a message.protected void
sendEmergencyStop()
Since XpressNet has a seperate Opcode for emergency stop, we're setting this up as a seperate protected function.protected void
sendFunctionGroup1()
Send the XpressNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4.protected void
sendFunctionGroup10()
Send the XpressNet message to set the state of functions F61-68protected void
sendFunctionGroup2()
Send the XpressNet message to set the state of functions F5, F6, F7, F8.protected void
sendFunctionGroup3()
Send the XpressNet message to set the state of functions F9, F10, F11, F12.protected void
sendFunctionGroup4()
Send the XpressNet message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20.protected void
sendFunctionGroup5()
Send the XpressNet message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28.protected void
sendFunctionGroup6()
Send the XpressNet message to set the state of functions F29-36protected void
sendFunctionGroup7()
Send the XpressNet message to set the state of functions F37-44protected void
sendFunctionGroup8()
Send the XpressNet message to set the state of functions F45-52protected void
sendFunctionGroup9()
Send the XpressNet message to set the state of functions F53-60protected void
sendFunctionHighInformationRequest()
Send a request to get the on/off status of functions 13-28 from the command station.protected void
sendFunctionHighMomentaryStatusRequest()
Send a request to get the status of functions from the command station.protected void
sendFunctionStatusInformationRequest()
Send a request to get the status of functions from the command station.protected void
sendMomentaryFunctionGroup1()
Send the XpressNet message to set the Momentary state of locomotive functions F0, F1, F2, F3, F4.protected void
sendMomentaryFunctionGroup10()
Send the XpressNet message to set the momentary state of functions F61-68protected void
sendMomentaryFunctionGroup2()
Send the XpressNet message to set the momentary state of functions F5, F6, F7, F8.protected void
sendMomentaryFunctionGroup3()
Send the XpressNet message to set the momentary state of functions F9, F10, F11, F12.protected void
sendMomentaryFunctionGroup4()
Send the XpressNet message to set the momentary state of functions F13, F14, F15, F16, F17, F18, F19, F20.protected void
sendMomentaryFunctionGroup5()
Send the XpressNet message to set the momentary state of functions F21, F22, F23, F24, F25, F26, F27, F28.protected void
sendMomentaryFunctionGroup6()
Send the XpressNet message to set the momentary state of functions F29-36protected void
sendMomentaryFunctionGroup7()
Send the XpressNet message to set the momentary state of functions F37-44protected void
sendMomentaryFunctionGroup8()
Send the XpressNet message to set the momentary state of functions F45-52protected void
sendMomentaryFunctionGroup9()
Send the XpressNet message to set the momentary state of functions F53-60protected void
sendQueuedMessage()
Send message from queue.protected void
sendStatusInformationRequest()
Send a request to get the speed, direction and function status from the command station.int
setDccAddress(int newaddress)
protected void
setIsAvailable(boolean available)
Set the internal isAvailable property.void
setIsForward(boolean forward)
When we set the direction, we're going to set the speed to zero as well.void
setSpeedSetting(float speed)
Notify listeners and send the new speed to the command station.void
setSpeedStepMode(SpeedStepMode Mode)
Set the speed step value and the related speedIncrement value.void
setXNetTrafficController(XNetTrafficController controller)
protected void
startStatusTimer()
Set up the status timer, and start it.protected void
stopStatusTimer()
Stop the Status Timervoid
throttleDispose()
Dispose when finished with this object.-
Methods inherited from class jmri.jmrix.AbstractThrottle
addPropertyChangeListener, dispatch, dispose, finishRecord, getFunction, getFunctionMomentary, getFunctionMomentaryNoWarn, getFunctionNoWarn, getFunctions, getFunctionsMomentary, getIsForward, getRosterEntry, getSpeedIncrement, getSpeedSetting, getSpeedStepMode, intSpeed, intSpeed, notifyThrottleDisconnect, notifyThrottleDispatchEnabled, notifyThrottleReleaseEnabled, record, release, removePropertyChangeListener, sendFunctionGroup, setFunction, setFunctionMomentary, setRosterEntry, setSpeedSetting, setSpeedSettingAgain, 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, toString, 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
-
isAvailable
protected boolean isAvailable
-
statusTask
protected java.util.TimerTask statusTask
-
statTimeoutValue
protected static final int statTimeoutValue
- See Also:
- Constant Field Values
-
tc
protected XNetTrafficController tc
-
THROTTLEIDLE
protected static final int THROTTLEIDLE
- See Also:
- Constant Field Values
-
THROTTLESTATSENT
protected static final int THROTTLESTATSENT
- See Also:
- Constant Field Values
-
THROTTLESPEEDSENT
protected static final int THROTTLESPEEDSENT
- See Also:
- Constant Field Values
-
THROTTLEFUNCSENT
protected static final int THROTTLEFUNCSENT
- See Also:
- Constant Field Values
-
THROTTLEMOMSTATSENT
protected static final int THROTTLEMOMSTATSENT
- See Also:
- Constant Field Values
-
THROTTLEHIGHSTATSENT
protected static final int THROTTLEHIGHSTATSENT
- See Also:
- Constant Field Values
-
THROTTLEHIGHMOMSTATSENT
protected static final int THROTTLEHIGHMOMSTATSENT
- See Also:
- Constant Field Values
-
requestState
protected int requestState
-
address
protected int address
-
requestList
protected java.util.concurrent.LinkedBlockingQueue<XNetThrottle.RequestMessage> requestList
-
-
Constructor Detail
-
XNetThrottle
public XNetThrottle(XNetSystemConnectionMemo memo, XNetTrafficController controller)
Constructor- Parameters:
memo
- system connection.controller
- system connection traffic controller.
-
XNetThrottle
public XNetThrottle(XNetSystemConnectionMemo memo, LocoAddress address, XNetTrafficController controller)
Constructor.- Parameters:
memo
- system connection.address
- loco address.controller
- system connection traffic controller.
-
-
Method Detail
-
setXNetTrafficController
public void setXNetTrafficController(XNetTrafficController controller)
-
csVersionSupportFn13to28
protected boolean csVersionSupportFn13to28()
-
csVersionSupportFn29to68
protected boolean csVersionSupportFn29to68()
-
sendFunctionGroup1
protected void sendFunctionGroup1()
Send the XpressNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4.- Overrides:
sendFunctionGroup1
in classAbstractThrottle
-
sendFunctionGroup2
protected void sendFunctionGroup2()
Send the XpressNet message to set the state of functions F5, F6, F7, F8.- Overrides:
sendFunctionGroup2
in classAbstractThrottle
-
sendFunctionGroup3
protected void sendFunctionGroup3()
Send the XpressNet message to set the state of functions F9, F10, F11, F12.- Overrides:
sendFunctionGroup3
in classAbstractThrottle
-
sendFunctionGroup4
protected void sendFunctionGroup4()
Send the XpressNet message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20.- Overrides:
sendFunctionGroup4
in classAbstractThrottle
-
sendFunctionGroup5
protected void sendFunctionGroup5()
Send the XpressNet message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28.- Overrides:
sendFunctionGroup5
in classAbstractThrottle
-
sendFunctionGroup6
protected void sendFunctionGroup6()
Send the XpressNet message to set the state of functions F29-36- Overrides:
sendFunctionGroup6
in classAbstractThrottle
-
sendFunctionGroup7
protected void sendFunctionGroup7()
Send the XpressNet message to set the state of functions F37-44- Overrides:
sendFunctionGroup7
in classAbstractThrottle
-
sendFunctionGroup8
protected void sendFunctionGroup8()
Send the XpressNet message to set the state of functions F45-52- Overrides:
sendFunctionGroup8
in classAbstractThrottle
-
sendFunctionGroup9
protected void sendFunctionGroup9()
Send the XpressNet message to set the state of functions F53-60- Overrides:
sendFunctionGroup9
in classAbstractThrottle
-
sendFunctionGroup10
protected void sendFunctionGroup10()
Send the XpressNet message to set the state of functions F61-68- Overrides:
sendFunctionGroup10
in classAbstractThrottle
-
sendMomentaryFunctionGroup1
protected void sendMomentaryFunctionGroup1()
Send the XpressNet message to set the Momentary state of locomotive functions F0, F1, F2, F3, F4.- Overrides:
sendMomentaryFunctionGroup1
in classAbstractThrottle
-
sendMomentaryFunctionGroup2
protected void sendMomentaryFunctionGroup2()
Send the XpressNet message to set the momentary state of functions F5, F6, F7, F8.- Overrides:
sendMomentaryFunctionGroup2
in classAbstractThrottle
-
sendMomentaryFunctionGroup3
protected void sendMomentaryFunctionGroup3()
Send the XpressNet message to set the momentary state of functions F9, F10, F11, F12.- Overrides:
sendMomentaryFunctionGroup3
in classAbstractThrottle
-
sendMomentaryFunctionGroup4
protected void sendMomentaryFunctionGroup4()
Send the XpressNet message to set the momentary state of functions F13, F14, F15, F16, F17, F18, F19, F20.- Overrides:
sendMomentaryFunctionGroup4
in classAbstractThrottle
-
sendMomentaryFunctionGroup5
protected void sendMomentaryFunctionGroup5()
Send the XpressNet message to set the momentary state of functions F21, F22, F23, F24, F25, F26, F27, F28.- Overrides:
sendMomentaryFunctionGroup5
in classAbstractThrottle
-
sendMomentaryFunctionGroup6
protected void sendMomentaryFunctionGroup6()
Send the XpressNet message to set the momentary state of functions F29-36- Overrides:
sendMomentaryFunctionGroup6
in classAbstractThrottle
-
sendMomentaryFunctionGroup7
protected void sendMomentaryFunctionGroup7()
Send the XpressNet message to set the momentary state of functions F37-44- Overrides:
sendMomentaryFunctionGroup7
in classAbstractThrottle
-
sendMomentaryFunctionGroup8
protected void sendMomentaryFunctionGroup8()
Send the XpressNet message to set the momentary state of functions F45-52- Overrides:
sendMomentaryFunctionGroup8
in classAbstractThrottle
-
sendMomentaryFunctionGroup9
protected void sendMomentaryFunctionGroup9()
Send the XpressNet message to set the momentary state of functions F53-60- Overrides:
sendMomentaryFunctionGroup9
in classAbstractThrottle
-
sendMomentaryFunctionGroup10
protected void sendMomentaryFunctionGroup10()
Send the XpressNet message to set the momentary state of functions F61-68- Overrides:
sendMomentaryFunctionGroup10
in classAbstractThrottle
-
setSpeedSetting
public void setSpeedSetting(float speed)
Notify listeners and send the new speed to the command station.- Specified by:
setSpeedSetting
in interfaceThrottle
- Overrides:
setSpeedSetting
in classAbstractThrottle
- Parameters:
speed
- the speed as a 0.0 -> 1.0. fraction of maximum possible speed or -1 for emergency stop.
-
sendEmergencyStop
protected void sendEmergencyStop()
Since XpressNet has a seperate Opcode for emergency stop, we're setting this up as a seperate protected function.
-
setIsForward
public void setIsForward(boolean forward)
When we set the direction, we're going to set the speed to zero as well.- Specified by:
setIsForward
in interfaceThrottle
- Overrides:
setIsForward
in classAbstractThrottle
- Parameters:
forward
- true if forward; false otherwise
-
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
-
throttleDispose
public void throttleDispose()
Dispose when finished with this object. After this, further usage of this Throttle object will result in a JmriException.This is quite problematic, because a using object doesn't know when it's the last user.
- Specified by:
throttleDispose
in classAbstractThrottle
-
setDccAddress
public int setDccAddress(int newaddress)
-
getDccAddress
public int getDccAddress()
-
getDccAddressHigh
protected int getDccAddressHigh()
-
getDccAddressLow
protected int getDccAddressLow()
-
sendStatusInformationRequest
protected void sendStatusInformationRequest()
Send a request to get the speed, direction and function status from the command station.
-
sendFunctionStatusInformationRequest
protected void sendFunctionStatusInformationRequest()
Send a request to get the status of functions from the command station.
-
sendFunctionHighInformationRequest
protected void sendFunctionHighInformationRequest()
Send a request to get the on/off status of functions 13-28 from the command station.
-
sendFunctionHighMomentaryStatusRequest
protected void sendFunctionHighMomentaryStatusRequest()
Send a request to get the status of functions from the command station.
-
message
public void message(XNetReply l)
Description copied from interface:XNetListener
Member function that will be invoked by an XNetInterface implementation to forward an XNet message from the layout.- Specified by:
message
in interfaceXNetListener
- Parameters:
l
- The received XNet message. Note that this same object may be presented to multiple users. It should not be modified here.
-
message
public void message(XNetMessage l)
Member function that will be invoked by an XNetInterface implementation to forward an XNet message sent to the layout. Normally, this function will do nothing.- Specified by:
message
in interfaceXNetListener
- Parameters:
l
- The received XNet message. Note that this same object may be presented to multiple users. It should not be modified here.
-
notifyTimeout
public void notifyTimeout(XNetMessage msg)
Member function invoked by an XNetInterface implementation to notify a sender that an outgoing message timed out and was dropped from the queue.- Specified by:
notifyTimeout
in interfaceXNetListener
- Parameters:
msg
- message which has timed out.
-
parseSpeedAndAvailability
protected void parseSpeedAndAvailability(int b1)
Get SpeedStep and availability information.- Parameters:
b1
- 1st byte of message to examine
-
notifyNewSpeedStepMode
protected void notifyNewSpeedStepMode(SpeedStepMode mode)
-
parseSpeedAndDirection
protected void parseSpeedAndDirection(int b2)
Get Speed and Direction information.- Parameters:
b2
- 2nd byte of message to examine
-
notifyNewDirection
protected void notifyNewDirection(boolean forward)
-
parseFunctionInformation
protected void parseFunctionInformation(int b3, int b4)
-
parseFunctionHighInformation
protected void parseFunctionHighInformation(int b3, int b4)
-
parseFunctionMomentaryInformation
protected void parseFunctionMomentaryInformation(int b3, int b4)
-
parseFunctionHighMomentaryInformation
protected void parseFunctionHighMomentaryInformation(int b3, int b4)
-
checkForFunctionMomentaryValueChange
protected void checkForFunctionMomentaryValueChange(int funcNum, int bytevalue, int bitmask, boolean currentValue)
-
setIsAvailable
protected void setIsAvailable(boolean available)
Set the internal isAvailable property.- Parameters:
available
- true if available; false otherwise
-
startStatusTimer
protected void startStatusTimer()
Set up the status timer, and start it.
-
stopStatusTimer
protected void stopStatusTimer()
Stop the Status Timer
-
getLocoAddress
public LocoAddress getLocoAddress()
Description copied from interface:Throttle
Locomotive address. The exact format is defined by the specific implementation, as subclasses of LocoAddress will contain different information.This is an unbound property.
- Specified by:
getLocoAddress
in interfaceThrottle
- Returns:
- The locomotive address
-
sendQueuedMessage
protected void sendQueuedMessage()
Send message from queue.
-
queueMessage
protected void queueMessage(XNetMessage m, int s)
Queue a message.- Parameters:
m
- message to sends
- state
-
-