001package jmri.jmrix.zimo;
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 Mx1ThrottleManager extends AbstractThrottleManager {
018
019    /**
020     * Create a new manager.
021     *
022     * @param memo the system connection this manager is associated with
023     */
024    public Mx1ThrottleManager(Mx1SystemConnectionMemo memo) {
025        super(memo);
026        this.tc = memo.getMx1TrafficController();
027        this.prefix = memo.getSystemPrefix();
028    }
029
030    Mx1TrafficController tc = null;
031    String prefix = "";
032
033    @Override
034    public void requestThrottleSetup(LocoAddress a, boolean control) {
035        if (a instanceof DccLocoAddress ) {
036            //We do interact
037            DccLocoAddress address = (DccLocoAddress) a;
038            log.debug("new Mx1Throttle for {}", address); // NOI18N
039            notifyThrottleKnown(new Mx1Throttle((Mx1SystemConnectionMemo) adapterMemo, address), address);
040        }
041        else {
042            log.error("{} is not a DccLocoAddress",a);
043            failedThrottleRequest(a, "LocoAddress " +a+ " is not a DccLocoAddress");
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 Mx1Throttle) {
082                Mx1Throttle nct = (Mx1Throttle) t;
083                nct.throttleDispose();
084                return true;
085            }
086        }
087        return false;
088    }
089
090    private final static Logger log = LoggerFactory.getLogger(Mx1ThrottleManager.class);
091
092}