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