Class LnThrottleManager

    • Method Detail

      • singleUse

        protected boolean singleUse()
        LocoNet allows multiple throttles for the same device.

        Does this DCC system allow a Throttle (e.g. an address) to be used by only one user at a time?

        Overrides:
        singleUse in class AbstractThrottleManager
        Returns:
        false always
      • requestThrottleSetup

        public void requestThrottleSetup​(LocoAddress address,
                                         boolean control)
        Start creating a Throttle object. This returns directly, having arranged for the Throttle object to be delivered via callback since there are situations where the command station does not respond, (slots full, command station powered off, others?) this code will retry and then fail the request if no response occurs.
        Specified by:
        requestThrottleSetup in class AbstractThrottleManager
        Parameters:
        address - locomotive address to be controlled
        control - true if throttle wishes to control the speed and direction of the loco.
      • processQueuedThrottleSetupRequest

        protected void processQueuedThrottleSetupRequest()
        Processes the next loco from the queue of requested locos for which to get a LocoNetThrottle.
      • notifyChangedSlot

        public void notifyChangedSlot​(LocoNetSlot s)
        Get notification that an address has changed slot. This method creates a throttle for all ThrottleListeners of that address and notifies them via the ThrottleListener.notifyThrottleFound method.
        Specified by:
        notifyChangedSlot in interface SlotListener
        Parameters:
        s - LocoNet slot which has been changed
      • notifyComplete

        protected void notifyComplete​(DccThrottle t,
                                      LocoNetSlot s)
        Called from the throttle slot when the final write of throttle id has been completed, and the slot is set as initialized, or called directly for our own shared throttles.
        Parameters:
        t - the throttle
        s - the lot.
      • notifyRefused

        public void notifyRefused​(int address,
                                  java.lang.String cause)
        Loco acquisition failed. Propagate the failure message to the (GUI) throttle.
        Parameters:
        address - of the loco which could not be acquired
        cause - reason for the failure
      • createThrottle

        DccThrottle createThrottle​(LocoNetSystemConnectionMemo memo,
                                   LocoNetSlot s)
        Create a LocoNet Throttle to control a loco.

        This is called during the loco acquisition process by logic within LnThrottleManager. Generally, it should not be directly called by other methods.

        Parameters:
        memo - connection memo used by the throttle for communications
        s - slot holding an acquired loco
        Returns:
        throttle holding an acquired loco
      • canBeLongAddress

        public boolean canBeLongAddress​(int address)
        Determines if the loco address is a long address.

        For LocoNet, address 128 and above is a long address.

        Specified by:
        canBeLongAddress in interface ThrottleManager
        Parameters:
        address - to be checked
        Returns:
        true if long address, else false
      • canBeShortAddress

        public boolean canBeShortAddress​(int address)
        Determines if the loco address is a short address.

        For LocoNet, address 127 and below is a short address

        Specified by:
        canBeShortAddress in interface ThrottleManager
        Parameters:
        address - to be checked
        Returns:
        true if short address, else false
      • addressTypeUnique

        public boolean addressTypeUnique()
        Reports whether all loco addresses are uniquely long or short, without any ambiguity for any address.

        For LocoNet, there are no ambiguous addresses.

        Specified by:
        addressTypeUnique in interface ThrottleManager
        Returns:
        true
      • isLongAddress

        protected static boolean isLongAddress​(int num)
        Local method for deciding short/long address.
        Parameters:
        num - address to be checked
        Returns:
        true if num is a long address else false
      • dispatchThrottle

        public void dispatchThrottle​(DccThrottle t,
                                     ThrottleListener l)
        Dispatches a loco from a LnThrottle object.

        Generally, this will cause the slot to be made "common" and then linked via the "Dispatch" slot.

        After dispatching, the throttle may not be used to control the loco. You should check getUsageCountBefore calling as it will fail if not 1.

        Specified by:
        dispatchThrottle in interface ThrottleManager
        Overrides:
        dispatchThrottle in class AbstractThrottleManager
        Parameters:
        t - is a throttle to be disposed of
        l - is the listener for the throttle
      • getThrottleID

        public int getThrottleID()
        Get the ThrottleID value for this throttle.
        Returns:
        the ThrottleID value
      • dispose

        public void dispose()
        Allow to cleanly release the traffic controller in ThrottleManager Tests
        • remove listeners, if any
        • stop timers, is any
        Dispose of this manager, typically for testing.
        Specified by:
        dispose in interface ThrottleManager
        Overrides:
        dispose in class AbstractThrottleManager
      • notifyStealRequest

        public void notifyStealRequest​(int locoAddr)
        Inform the requesting throttle object (not the connection-specific throttle implementation!) that the address is in-use and the throttle user may either choose to "steal" the address, or quit the acquisition process. The LocoNet acquisition process "retry" timer is stopped as part of this process, since a positive response has been received from the command station and since user intervention is required. Reminder: for LocoNet throttles which are not using "expanded slot" functionality, "steal" really means "share". For those LocoNet throttles which are using "expanded slots", "steal" really means take control and let the command station issue a "StealZap" LocoNet message to the other throttle.
        Parameters:
        locoAddr - address of DCC loco or consist
      • responseThrottleDecision

        public void responseThrottleDecision​(LocoAddress address,
                                             ThrottleListener l,
                                             ThrottleListener.DecisionType decision)
        Perform the actual "Steal" of the requested throttle.

        This is a call-back, as a result of the throttle user's agreement to "steal" the locomotive.

        Reminder: for LocoNet throttles which are not using "expanded slot" functionality, "steal" really means "share". For those LocoNet throttles which are using "expanded slots", "steal" really means "force any other throttle running that address to drop the loco".

        Specified by:
        responseThrottleDecision in interface ThrottleManager
        Overrides:
        responseThrottleDecision in class AbstractThrottleManager
        Parameters:
        address - desired DccLocoAddress
        decision - made by the ThrottleListener, only listening for STEAL
        l - The ThrottleListener which has made the decision
        Since:
        4.9.2