Skip to content
Permalink
Browse files

minor refactoring and code cleanup in XPressNet throttles.

  • Loading branch information...
pabender committed Oct 23, 2018
1 parent 36229ec commit d47f0e32785ba36923b3cae0a179e045fbb590b3
@@ -87,7 +87,11 @@ public void setProgrammerManager(XNetProgrammerManager p) {
*/
public ThrottleManager getThrottleManager() {
if (throttleManager == null) {
throttleManager = new XNetThrottleManager(this);
if (xt.getCommandStation().getCommandStationType() == 0x10) {
throttleManager = new jmri.jmrix.roco.RocoXNetThrottleManager(this);
} else {
throttleManager = new XNetThrottleManager(this);
}
}
return throttleManager;
}

Large diffs are not rendered by default.

@@ -0,0 +1,98 @@
package jmri.jmrix.roco;

import jmri.LocoAddress;
import jmri.jmrix.lenz.XNetMessage;
import jmri.jmrix.lenz.XNetReply;
import jmri.jmrix.lenz.XNetSystemConnectionMemo;
import jmri.jmrix.lenz.XNetTrafficController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An implementation of DccThrottle with code specific to a Roco XpressNet
* connection.
*
* @author Paul Bender (C) 2015
* @author Giorgio Terdina (C) 2007
*/
public class RocoXNetThrottle extends jmri.jmrix.lenz.XNetThrottle {

/**
* Constructor
*/
public RocoXNetThrottle(XNetSystemConnectionMemo memo, XNetTrafficController controller) {
super(memo,controller);
}

/**
* Constructor
*/
public RocoXNetThrottle(XNetSystemConnectionMemo memo, LocoAddress address, XNetTrafficController controller) {
super(memo,address,controller);
}

// The Roco doesn't support setting the momentary/continuous status of
// functions, so override the sending of all momentary/continuous
// from the parent class.
@Override
protected void sendMomentaryFunctionGroup1() {
log.debug("Command station does not support Momentary functions");
}

@Override
protected void sendMomentaryFunctionGroup2() {
log.debug("Command station does not support Momentary functions");
}

@Override
protected void sendMomentaryFunctionGroup3() {
log.debug("Command station does not support Momentary functions");
}

@Override
protected void sendMomentaryFunctionGroup4() {
log.debug("Command station does not support Momentary functions");
}

@Override
protected void sendMomentaryFunctionGroup5() {
log.debug("Command station does not support Momentary functions");
}

// also prevent requesting the momentary status information
@Override
synchronized protected void sendFunctionStatusInformationRequest() {
log.debug("Command station does not support Momentary functions");
}

@Override
synchronized protected void sendFunctionHighMomentaryStatusRequest() {
log.debug("Command station does not support Momentary functions");
}

// The Roco Doesn't support the XpressNet directed emergency stop
// instruction, so override sendEmergencyStop in the parent, and
// just send speed step 0.
@Override
protected void sendEmergencyStop(){
setSpeedSetting(0);
}

/**
* Dispose when finished with this object. After this, further usage of this
* Throttle object will result in a JmriException.
* <p>
* This is quite problematic, because a using object doesn't know when it's
* the last user.
*/
@Override
protected void throttleDispose() {
active = false;
stopStatusTimer();
finishRecord();
}

// register for notification
private final static Logger log = LoggerFactory.getLogger(RocoXNetThrottle.class);

}
@@ -0,0 +1,44 @@
package jmri.jmrix.roco;

import jmri.LocoAddress;
import jmri.jmrix.lenz.XNetSystemConnectionMemo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Roco XNet implementation of a ThrottleManager based on the
* AbstractThrottleManager.
*
* @author Paul Bender Copyright (C) 2002-2004
*/
public class RocoXNetThrottleManager extends jmri.jmrix.lenz.XNetThrottleManager {

/**
* Constructor.
*/
public RocoXNetThrottleManager(XNetSystemConnectionMemo memo) {
super(memo);
}

/**
* Request a new throttle object be created for the address, and let the
* throttle listeners know about it.
*/
@Override
public void requestThrottleSetup(LocoAddress address, boolean control) {
RocoXNetThrottle throttle;
if (log.isDebugEnabled()) {
log.debug("Requesting Throttle: " + address);
}
if (throttles.containsKey(address)) {
notifyThrottleKnown(throttles.get(address), address);
} else {
throttle = new RocoXNetThrottle((XNetSystemConnectionMemo) adapterMemo, address, tc);
throttles.put(address, throttle);
notifyThrottleKnown(throttle, address);
}
}

private final static Logger log = LoggerFactory.getLogger(RocoXNetThrottleManager.class);

}
@@ -14,7 +14,7 @@
*
* @author Paul Bender (C) 2015
*/
public class Z21XNetThrottle extends jmri.jmrix.lenz.XNetThrottle {
public class Z21XNetThrottle extends jmri.jmrix.roco.RocoXNetThrottle {

/**
* Constructor
@@ -180,35 +180,7 @@ protected void sendFunctionGroup5() {
queueMessage(msg7, THROTTLEFUNCSENT);
}

// The Z21 doesn't support setting the momentary/continuous status of
// functions, so override the sending of all momentary/continuous
// from the parent class.
@Override
protected void sendMomentaryFunctionGroup1() {
}
@Override
protected void sendMomentaryFunctionGroup2() {
}
@Override
protected void sendMomentaryFunctionGroup3() {
}
@Override
protected void sendMomentaryFunctionGroup4() {
}
@Override
protected void sendMomentaryFunctionGroup5() {
}

// also prevent requesting the momentary status information
@Override
synchronized protected void sendFunctionStatusInformationRequest() {
}
@Override
synchronized protected void sendFunctionHighMomentaryStatusRequest() {
}


// The Z21 Doesn't support the XpressNet directed emergency stop
// The Roco Doesn't support the XpressNet directed emergency stop
// instruction, so override sendEmergencyStop in the parent, and
// just send speed step 0.
@Override
@@ -11,7 +11,7 @@
*
* @author Paul Bender Copyright (C) 2002-2004
*/
public class Z21XNetThrottleManager extends jmri.jmrix.lenz.XNetThrottleManager {
public class Z21XNetThrottleManager extends jmri.jmrix.roco.RocoXNetThrottleManager {

/**
* Constructor.
@@ -20,19 +20,6 @@ public Z21XNetThrottleManager(XNetSystemConnectionMemo memo) {
super(memo);
}

/**
* What speed modes are supported by this system? value should be xor of
* possible modes specifed by the DccThrottle interface.
* Z21 XpressNet supports 14,28 and 128 speed step modes.
*/
@Override
public int supportedSpeedModes() {
return (jmri.DccThrottle.SpeedStepMode128
| jmri.DccThrottle.SpeedStepMode28
| jmri.DccThrottle.SpeedStepMode27
| jmri.DccThrottle.SpeedStepMode14);
}

/**
* Request a new throttle object be created for the address, and let the
* throttle listeners know about it.
@@ -86,10 +86,12 @@ public void testInitSequenceNormalUnitSpeedStep128() throws Exception {

// now we're going to wait and verify the throttle eventually has
// its status set to idle.
jmri.util.JUnitAppender.assertErrorMessage("Unsupported Command Sent to command station");

jmri.util.JUnitUtil.releaseThread(this); // give the messages
// some time to process;

jmri.util.JUnitAppender.assertErrorMessage("Unsupported Command Sent to command station");

Assert.assertEquals("Throttle in THROTTLEIDLE state", XNetThrottle.THROTTLEIDLE, t.requestState);

// and verify all the data was set correctly.
@@ -9,6 +9,8 @@
jmri.jmrix.roco.z21.PackageTest.class,
BundleTest.class,
RocoCommandStationTest.class,
RocoXNetThrottleTest.class,
RocoXNetThrottleManagerTest.class,
})

/**
@@ -0,0 +1,34 @@
package jmri.jmrix.roco;

import jmri.jmrix.lenz.XNetInterfaceScaffold;
import jmri.jmrix.lenz.XNetSystemConnectionMemo;
import jmri.jmrix.lenz.XNetThrottleManagerTest;
import jmri.util.JUnitUtil;
import org.junit.After;
import org.junit.Before;


/**
* Tests for the jmri.jmrix.roco.RocoXNetThrottleManager class
*
* @author Paul Bender Copyright (C) 2015,2016
*/
public class RocoXNetThrottleManagerTest extends XNetThrottleManagerTest {

// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp();
XNetInterfaceScaffold tc = new XNetInterfaceScaffold(new RocoCommandStation());
tm = new RocoXNetThrottleManager(new XNetSystemConnectionMemo(tc));
}

@After
@Override
public void tearDown() {
tm = null;
JUnitUtil.tearDown();
}

}

0 comments on commit d47f0e3

Please sign in to comment.
You can’t perform that action at this time.