001package jmri.jmrix.roco;
002
003import jmri.LocoAddress;
004import jmri.jmrix.lenz.XNetSystemConnectionMemo;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Roco XNet implementation of a ThrottleManager based on the
010 * AbstractThrottleManager.
011 *
012 * @author Paul Bender Copyright (C) 2002-2004
013 */
014public class RocoXNetThrottleManager extends jmri.jmrix.lenz.XNetThrottleManager {
015
016    /**
017     * Constructor.
018     * @param memo system connection.
019     */
020    public RocoXNetThrottleManager(XNetSystemConnectionMemo memo) {
021        super(memo);
022    }
023
024    /**
025     * Request a new throttle object be created for the address, and let the
026     * throttle listeners know about it.
027     */
028    @Override
029    public void requestThrottleSetup(LocoAddress address, boolean control) {
030        // range check for LocoMaus II
031        if (tc.getCommandStation().getCommandStationType() == 0x04 ) {
032            if(address.getNumber()>=100) {
033               String typeString = Bundle.getMessage("CSTypeLokMaus");
034               failedThrottleRequest(address,Bundle.getMessage("ThrottleErrorCSTwoDigit",typeString));
035               return;
036            }
037        }
038        RocoXNetThrottle throttle;
039        if (log.isDebugEnabled()) {
040            log.debug("Requesting Throttle: {}", address);
041        }
042        if (throttles.containsKey(address)) {
043            notifyThrottleKnown(throttles.get(address), address);
044        } else {
045            throttle = new RocoXNetThrottle((XNetSystemConnectionMemo) adapterMemo, address, tc);
046            throttles.put(address, throttle);
047            notifyThrottleKnown(throttle, address);
048        }
049    }
050
051    private final static Logger log = LoggerFactory.getLogger(RocoXNetThrottleManager.class);
052
053}