Class CbusThrottle

All Implemented Interfaces:
PropertyChangeFirer, PropertyChangeProvider, DccThrottle, Throttle

public class CbusThrottle extends AbstractThrottle
An implementation of DccThrottle via AbstractThrottle with code specific to a CBUS connection.

Speed in the Throttle interfaces and AbstractThrottle is a float, but in CBUS is normally an int with values from 0 to 127.

CBUS 128 Speed Steps
setSpeedSettingCBUS DSPDTranslatedThrottle
0 0 Speed 0 0 %
-1 1 E Stop 0 %
0.007937 2 Speed 1 1/126 %
0.015873 3 Speed 2 2/126 %
0.984127 125 Speed 124 124/126 %
0.992063 126 Speed 125 125/126 %
1 127 Speed 126 100 %
CBUS 28 Speed Steps
CBUS DSPDTranslatedThrottle
0 Speed 0 Encoding 1 0 %
1 Speed 0 Encoding 2 0 %
2 E Stop Encoding 1 0 %
3 E Stop Encoding 2 0 %
4 Speed 1 1/28 %
5 Speed 2 2/28 %
29 Speed 26 26/28 %
30 Speed 27 27/28 %
31 Speed 28 100 %
CBUS 14 Speed Steps
CBUS DSPDTranslatedThrottle
0 Speed 0 0 %
1 E Stop 0 %
2 Speed 1 1/14 %
3 Speed 2 2/14 %
13 0x0D Speed 12 12/14 %
14 0x0E Speed 13 13/14 %
15 0x0F Speed 14 100 %
  • Constructor Details

    • CbusThrottle

      public CbusThrottle(CanSystemConnectionMemo memo, LocoAddress address, int handle)
      Constructor
      Parameters:
      memo - System Connection
      address - The address this throttle relates to.
      handle - the Session ID for the Throttle
  • Method Details

    • throttleInit

      protected void throttleInit(int speed, int f0f4, int f5f8, int f9f12)
      Set initial throttle values as taken from PLOC reply from hardware
      Parameters:
      speed - including direction flag
      f0f4 - Functions 0-4
      f5f8 - Functions 5-8
      f9f12 - Functions 9-12
    • setSpeedStepMode

      public void setSpeedStepMode(SpeedStepMode stepMode)
      setSpeedStepMode - set the speed step value.

      Overridden to capture mode changes to be forwarded to the hardware. New throttles default to 128 step mode. CBUS Command stations also default to 128SS so this does not need to be sent if unchanged.

      Specified by:
      setSpeedStepMode in interface DccThrottle
      Overrides:
      setSpeedStepMode in class AbstractThrottle
      Parameters:
      stepMode - the current speed step mode - default should be 128 speed step mode in most cases
    • floatSpeed

      protected float floatSpeed(int lSpeed)
      Convert a CBUS speed integer to a float speed value
      Parameters:
      lSpeed - -1 to 127
      Returns:
      float value -1 to 1
    • sendFunctionGroup1

      protected void sendFunctionGroup1()
      Send the CBUS message to set the state of functions F0, F1, F2, F3, F4.
      Overrides:
      sendFunctionGroup1 in class AbstractThrottle
    • sendFunctionGroup2

      protected void sendFunctionGroup2()
      Send the CBUS message to set the state of functions F5, F6, F7, F8.
      Overrides:
      sendFunctionGroup2 in class AbstractThrottle
    • sendFunctionGroup3

      protected void sendFunctionGroup3()
      Send the CBUS message to set the state of functions F9, F10, F11, F12.
      Overrides:
      sendFunctionGroup3 in class AbstractThrottle
    • sendFunctionGroup4

      protected void sendFunctionGroup4()
      Send the CBUS message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20
      Overrides:
      sendFunctionGroup4 in class AbstractThrottle
    • sendFunctionGroup5

      protected void sendFunctionGroup5()
      Send the CBUS message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28
      Overrides:
      sendFunctionGroup5 in class AbstractThrottle
    • sendFunctionGroup6

      protected void sendFunctionGroup6()
      Send the CBUS message to set the state of functions F29 - F36
      Overrides:
      sendFunctionGroup6 in class AbstractThrottle
    • sendFunctionGroup

      protected void sendFunctionGroup(int group)
    • updateFunctionGroup

      protected void updateFunctionGroup(int group, int fns)
    • setSpeedSetting

      public void setSpeedSetting(float speed, boolean allowDuplicates, boolean allowDuplicatesOnStop)
      Set the speed.

      This intentionally skips the emergency stop value of 1.

      Specified by:
      setSpeedSetting in interface Throttle
      Overrides:
      setSpeedSetting in class AbstractThrottle
      Parameters:
      speed - Number from 0 to 1; less than zero is emergency stop
      allowDuplicates - don't suppress messages
      allowDuplicatesOnStop - don't suppress messages if the new speed is 'stop'
    • updateSpeedSetting

      protected void updateSpeedSetting(int speed)
      Update the throttles speed setting without sending to hardware. Used to support CBUS sharing by taking speed received from the hardware in an OPC_DSPD message.

      No compensation required for a direction flag

      Parameters:
      speed - integer speed value
    • setIsForward

      public void setIsForward(boolean forward)
      Set the direction and reset speed. Forwards to the layout Implementing functions should override this function, but should either make a call to super.setIsForward() to notify the listeners, or should notify the listeners themselves.
      Specified by:
      setIsForward in interface Throttle
      Overrides:
      setIsForward in class AbstractThrottle
      Parameters:
      forward - true if forward; false otherwise
    • updateIsForward

      protected void updateIsForward(boolean forward)
      Update the throttles direction without sending to hardware.Used to support CBUS sharing by taking direction received from the hardware in an OPC_DSPD message.
      Parameters:
      forward - True if Forward, else False
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getHandle

      protected int getHandle()
      Return the handle for this throttle
      Returns:
      integer session handle
    • setHandle

      protected void setHandle(int newHandle)
      Set the handle for this throttle

      This is normally done on Throttle Construction but certain operations, eg. recovering from an external steal may need to change this.

      Parameters:
      newHandle - session handle
    • setStolen

      protected void setStolen(boolean isStolen)
      Set Throttle Stolen Flag

      This is false on Throttle Construction but certain operations may need to change this, eg. an external steal.

      Sends IsAvailable Property Change Notification

      Parameters:
      isStolen - true if Throttle has been stolen, else false
    • isStolen

      protected boolean isStolen()
      Get Throttle Stolen Flag

      This is false on Throttle Construction but certain operations may need to change this, eg. an external steal.

      Returns:
      true if Throttle has been stolen, else false
    • getNumRecoverAttempts

      protected int getNumRecoverAttempts()
      Get the number of external steal recovery attempts
      Returns:
      Number of attempts since last reset
    • increaseNumRecoverAttempts

      protected void increaseNumRecoverAttempts()
      Increase a count of external steal recovery attempts
    • resetNumRecoverAttempts

      protected void resetNumRecoverAttempts()
      Reset count of recovery attempts
    • releaseFromCommandStation

      protected void releaseFromCommandStation()
      Release session from a command station ie. throttle with clean full dispose called from releaseThrottle
    • throttleDispose

      public void throttleDispose()
      Dispose when finished with this object. After this, further usage of this Throttle object will result in a JmriException.
      Specified by:
      throttleDispose in class AbstractThrottle
    • startRefresh

      protected final void startRefresh()
    • getLocoAddress

      Locomotive address. The exact format is defined by the specific implementation, as subclasses of LocoAddress will contain different information.

      This is an unbound property.

      Returns:
      The locomotive address
    • setDispatchActive

      protected void setDispatchActive(boolean newval)
      Adds extra check for num of this JMRI throttle users before notifying and makes sure these always get sent as a pair the abstracts only send to ThrottleListeners if value has been changed
      Parameters:
      newval - set true if dispatch can be enabled, else false