001package jmri.jmrix.mrc;
002
003import java.util.EnumSet;
004import jmri.DccLocoAddress;
005import jmri.LocoAddress;
006import jmri.SpeedStepMode;
007import jmri.jmrix.AbstractThrottleManager;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * MRC implementation of a ThrottleManager.
013 *
014 * @author Bob Jacobsen Copyright (C) 2001
015 * 
016 */
017public class MrcThrottleManager extends AbstractThrottleManager {
018
019    /**
020     * Throttle Manager Constructor.
021     * @param memo system connection memo
022     */
023    public MrcThrottleManager(MrcSystemConnectionMemo memo) {
024        super(memo);
025        this.tc = memo.getMrcTrafficController();
026        this.prefix = memo.getSystemPrefix();
027    }
028
029    MrcTrafficController tc = null;
030    String prefix = "";
031
032    @Override
033    public void requestThrottleSetup(LocoAddress a, boolean control) {
034        //We do minimal interaction
035        if (a instanceof DccLocoAddress ) {
036            DccLocoAddress address = (DccLocoAddress) a;
037            log.debug("new MrcThrottle for {}", address); // NOI18N
038            notifyThrottleKnown(new MrcThrottle((MrcSystemConnectionMemo) adapterMemo, address), address);
039        }
040        else {
041            log.error("{} is not a DccLocoAddress",a);
042            failedThrottleRequest(a, "LocoAddress " +a+ " is not a DccLocoAddress");
043            return;
044        }
045    }
046
047    /**
048     * Addresses 0-10239 can be long
049     *
050     */
051    @Override
052    public boolean canBeLongAddress(int address) {
053        return ((address >= 0) && (address <= 10239));
054    }
055
056    /**
057     * The short addresses 1-127 are available
058     *
059     */
060    @Override
061    public boolean canBeShortAddress(int address) {
062        return ((address >= 1) && (address <= 127));
063    }
064
065    /**
066     * Are there any ambiguous addresses (short vs long) on this system?
067     */
068    @Override
069    public boolean addressTypeUnique() {
070        return false;
071    }
072
073    @Override
074    public EnumSet<SpeedStepMode> supportedSpeedModes() {
075        return EnumSet.of(SpeedStepMode.NMRA_DCC_128, SpeedStepMode.NMRA_DCC_28);
076    }
077
078    @Override
079    public boolean disposeThrottle(jmri.DccThrottle t, jmri.ThrottleListener l) {
080        if (super.disposeThrottle(t, l)) {
081            if (t instanceof MrcThrottle) {
082                MrcThrottle nct = (MrcThrottle) t;
083                nct.throttleDispose();
084                return true;
085            }
086        }
087        return false;
088    }
089
090    private final static Logger log = LoggerFactory.getLogger(MrcThrottleManager.class);
091
092}