001package jmri.jmrix.xpa;
002
003import java.util.EnumSet;
004
005import jmri.LocoAddress;
006import jmri.SpeedStepMode;
007import jmri.jmrix.AbstractThrottleManager;
008
009/**
010 * XPA implementation of a ThrottleManager.
011 *
012 * @author Paul Bender Copyright (C) 2004
013 */
014public class XpaThrottleManager extends AbstractThrottleManager {
015
016    private final XpaTrafficController tc;
017
018    /**
019     * Create a throttle manager.
020     *
021     * @param m the memo for the connection the manager is associated with
022     */
023    public XpaThrottleManager(XpaSystemConnectionMemo m) {
024        super(m);
025        userName = m.getUserName();
026        tc = m.getXpaTrafficController();
027    }
028
029    /**
030     * Request a new throttle object be created for the address, and let the
031     * throttle listeners know about it.
032     *
033     * {@inheritDoc }
034     */
035    @Override
036    public void requestThrottleSetup(LocoAddress address, boolean control) {
037        XpaThrottle throttle = new XpaThrottle(address, tc);
038        notifyThrottleKnown(throttle, address);
039    }
040
041    /**
042     * The XPA does not support the dispatch function.
043     *
044     * @return false
045     */
046    @Override
047    public boolean hasDispatchFunction() {
048        return false;
049    }
050
051    /**
052     * {@inheritDoc } Address 100 and above is a long address.
053     */
054    @Override
055    public boolean canBeLongAddress(int address) {
056        return isLongAddress(address);
057    }
058
059    /**
060     * {@inheritDoc } Address 99 and below is a short address.
061     */
062    @Override
063    public boolean canBeShortAddress(int address) {
064        return !isLongAddress(address);
065    }
066
067    /**
068     * {@inheritDoc }
069     *
070     * @return true because this type of throttle has no long/short overlap
071     */
072    @Override
073    public boolean addressTypeUnique() {
074        return true;
075    }
076
077    /**
078     * Local method for deciding short/long address.
079     * @param num address to check
080     * @return true if valid as long address
081     */
082    static boolean isLongAddress(int num) {
083        return (num >= 100);
084    }
085
086    /**
087     * What speed modes are supported by this system? value should be xor of
088     * possible modes specifed by the DccThrottle interface
089     */
090    @Override
091    public EnumSet<SpeedStepMode> supportedSpeedModes() {
092        return EnumSet.of(SpeedStepMode.INCREMENTAL);
093    }
094}