001package jmri.jmrix.nce; 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 * NCE implementation of a ThrottleManager. 013 * 014 * @author Bob Jacobsen Copyright (C) 2001 015 */ 016public class NceThrottleManager extends AbstractThrottleManager { 017 018 /** 019 * Constructor. 020 * @param memo system connection memo 021 */ 022 public NceThrottleManager(NceSystemConnectionMemo memo) { 023 super(memo); 024 this.tc = memo.getNceTrafficController(); 025 this.prefix = memo.getSystemPrefix(); 026 } 027 028 NceTrafficController tc = null; 029 String prefix = ""; 030 031 @Override 032 public void requestThrottleSetup(LocoAddress a, boolean control) { 033 if (a instanceof DccLocoAddress ) { 034 // the NCE protocol doesn't require an interaction with the command 035 // station for this, so immediately trigger the callback. 036 DccLocoAddress address = (DccLocoAddress) a; 037 log.debug("new NceThrottle for {}", address); 038 notifyThrottleKnown(new NceThrottle((NceSystemConnectionMemo) adapterMemo, address), address); 039 } 040 else { 041 log.error("{} is not a DccLocoAddress",a); 042 failedThrottleRequest(a, "LocoAddress " +a+ " is not a DccLocoAddress"); 043 } 044 } 045 046 /** 047 * Addresses 0-10239 can be long 048 * 049 */ 050 @Override 051 public boolean canBeLongAddress(int address) { 052 return ((address >= 0) && (address <= 10239)); 053 } 054 055 /** 056 * The short addresses 1-127 are available 057 * 058 */ 059 @Override 060 public boolean canBeShortAddress(int address) { 061 return ((address >= 1) && (address <= 127)); 062 } 063 064 /** 065 * Are there any ambiguous addresses (short vs long) on this system? 066 */ 067 @Override 068 public boolean addressTypeUnique() { 069 return false; 070 } 071 072 @Override 073 public EnumSet<SpeedStepMode> supportedSpeedModes() { 074 return EnumSet.of(SpeedStepMode.NMRA_DCC_128, SpeedStepMode.NMRA_DCC_28); 075 } 076 077 @Override 078 public boolean disposeThrottle(jmri.DccThrottle t, jmri.ThrottleListener l) { 079 if (super.disposeThrottle(t, l)) { 080 if (t instanceof NceThrottle) { 081 NceThrottle nct = (NceThrottle) t; 082 nct.throttleDispose(); 083 return true; 084 } 085 } 086 return false; 087 } 088 089 private final static Logger log = LoggerFactory.getLogger(NceThrottleManager.class); 090 091}