Class LnThrottleManager

java.lang.Object
jmri.jmrix.AbstractThrottleManager
jmri.jmrix.loconet.LnThrottleManager
All Implemented Interfaces:
EventListener, SlotListener, ThrottleManager
Direct Known Subclasses:
Ib1ThrottleManager, Ib2ThrottleManager, UhlenbrockLnThrottleManager

LocoNet implementation of a ThrottleManager.

Works in cooperation with the SlotManager, which actually handles the communications.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • 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
    • enablePrefSilentStealOption

      public boolean enablePrefSilentStealOption()
      Display the Silent Stealing checkbox option in Throttles Preferences
      Specified by:
      enablePrefSilentStealOption in interface ThrottleManager
      Overrides:
      enablePrefSilentStealOption in class AbstractThrottleManager
      Returns:
      true if steal is possible; false otherwise
    • 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

      Processes the next loco from the queue of requested locos for which to get a LocoNetThrottle.
    • hasDispatchFunction

      public boolean hasDispatchFunction()
      LocoNet does have a Dispatch function.
      Specified by:
      hasDispatchFunction in interface ThrottleManager
      Overrides:
      hasDispatchFunction in class AbstractThrottleManager
      Returns:
      true
    • supportedSpeedModes

      What speed modes are supported by this system? value should be xor of possible modes specified by the DccThrottle interface.
      Specified by:
      supportedSpeedModes in interface ThrottleManager
      Overrides:
      supportedSpeedModes in class AbstractThrottleManager
      Returns:
      an integer containing the combined speed step modes supported
    • 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, 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

      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
    • disposeThrottle

      Disposes a LnThrottle object.

      Generally, this will cause the slot to be made "common" and the LnThrottle is disposed of.

      After disposal, the throttle may not be used to control the loco.

      Specified by:
      disposeThrottle in interface ThrottleManager
      Overrides:
      disposeThrottle in class AbstractThrottleManager
      Parameters:
      t - is a throttle to be disposed of
      l - is the listener for the throttle
      Returns:
      false if throttle is not a LocoNetThrottle, else true
    • dispatchThrottle

      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
    • releaseThrottle

      Dispatch a loco from a LnThrottle object.

      Generally, this will cause the slot to be made "common".

      After disposal, the throttle may not be used to control the loco.

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

      public void failedThrottleRequest(LocoAddress address, String reason)
      Cancels the loco acquisition process when throttle acquisition of a loco fails.
      Overrides:
      failedThrottleRequest in class AbstractThrottleManager
      Parameters:
      address - loco address which could not be acquired
      reason - for the failure
    • cancelThrottleRequest

      Cancel a request for a throttle.
      Specified by:
      cancelThrottleRequest in interface ThrottleManager
      Overrides:
      cancelThrottleRequest in class AbstractThrottleManager
      Parameters:
      address - The decoder address desired. address.
      l - The ThrottleListener cancelling request for a 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

      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