001package jmri.jmrix.debugthrottle; 002 003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 004import jmri.DccLocoAddress; 005import jmri.LocoAddress; 006import jmri.jmrix.AbstractThrottle; 007import jmri.SystemConnectionMemo; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011/** 012 * An implementation of DccThrottle for debugging use. 013 * 014 * @author Bob Jacobsen Copyright (C) 2003 015 */ 016public class DebugThrottle extends AbstractThrottle { 017 018 /** 019 * Constructor. 020 * @param address loco address. 021 * @param memo system connection. 022 */ 023 public DebugThrottle(DccLocoAddress address, SystemConnectionMemo memo) { 024 super(memo); 025 026 log.debug("DebugThrottle constructor called for address {}", address); 027 028 // cache settings. It would be better to read the 029 // actual state, but I don't know how to do this 030 synchronized(this) { 031 this.speedSetting = 0; 032 } 033 // Functions default to false 034 this.isForward = true; 035 036 this.address = address; 037 setSpeedStepMode(jmri.SpeedStepMode.NMRA_DCC_128); 038 } 039 040 DccLocoAddress address; 041 042 @Override 043 public LocoAddress getLocoAddress() { 044 return address; 045 } 046 047 @Override 048 public String toString() { 049 return getLocoAddress().toString(); 050 } 051 052 /** 053 * Send the message to set the state of functions F0, F1, F2, F3, F4 054 */ 055 @Override 056 protected void sendFunctionGroup1() { 057 log.debug("sendFunctionGroup1 called for address {}, dir={},F0={},F1={},F2={},F3={},F4={}", 058 this.address, 059 (this.isForward ? "FWD":"REV"), 060 (getFunction(0) ? "On":"Off"), 061 (getFunction(1) ? "On":"Off"), 062 (getFunction(2) ? "On":"Off"), 063 (getFunction(3) ? "On":"Off"), 064 (getFunction(4) ? "On":"Off")); 065 } 066 067 /** 068 * Send the message to set the state of functions F5, F6, F7, F8 069 */ 070 @Override 071 protected void sendFunctionGroup2() { 072 log.debug("sendFunctionGroup2() called"); 073 } 074 075 /** 076 * Send the message to set the state of functions F9, F10, F11, F12 077 */ 078 @Override 079 protected void sendFunctionGroup3() { 080 log.debug("sendFunctionGroup3() called"); 081 } 082 083 /** 084 * Set the speed and direction 085 * <p> 086 * This intentionally skips the emergency stop value of 1. 087 * 088 * @param speed Number from 0 to 1; less than zero is emergency stop 089 */ 090 @SuppressFBWarnings(value = "FE_FLOATING_POINT_EQUALITY") // OK to compare floating point, notify on any change 091 @Override 092 public synchronized void setSpeedSetting(float speed) { 093 log.debug("setSpeedSetting: float speed: {} for address {}", speed, this.address); 094 float oldSpeed = this.speedSetting; 095 if (speed > 1.0) { 096 log.warn("Speed was set too high: {}", speed); 097 } 098 this.speedSetting = speed; 099 firePropertyChange(SPEEDSETTING, oldSpeed, this.speedSetting); 100 record(speed); 101 } 102 103 @Override 104 public void setIsForward(boolean forward) { 105 log.debug("setIsForward({}) called for address {}, was {}", forward, this.address, this.isForward); 106 boolean old = this.isForward; 107 this.isForward = forward; 108 sendFunctionGroup1(); // send the command 109 firePropertyChange(ISFORWARD, old, this.isForward); 110 } 111 112 @Override 113 public void throttleDispose() { 114 log.debug("throttleDispose() called for address {}", this.address); 115 finishRecord(); 116 } 117 118 // initialize logging 119 private final static Logger log = LoggerFactory.getLogger(DebugThrottle.class); 120 121}