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 Detail

      • CbusThrottle

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

      • throttleInit

        protected void throttleInit​(int speed,
                                    int f0f4,
                                    int f5f8,
                                    int f9f12)
        Set initial throttle values as taken from PLOC reply from hardware
        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
        setSpeedStepMode in class AbstractThrottle
        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
        lSpeed - -1 to 127
        float value -1 to 1
      • 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
        setSpeedSetting in class AbstractThrottle
        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

        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
        setIsForward in class AbstractThrottle
        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.
        forward - True if Forward, else False
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object
      • getHandle

        protected int getHandle()
        Return the handle for this throttle
        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.

        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

        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.

        true if Throttle has been stolen, else false
      • getNumRecoverAttempts

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

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

        public LocoAddress 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.

        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
        newval - set true if dispatch can be enabled, else false