Skip to content

Commit

Permalink
minor refactoring and code cleanup in XPressNet throttles.
Browse files Browse the repository at this point in the history
  • Loading branch information
pabender committed Oct 23, 2018
1 parent 36229ec commit d47f0e3
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 324 deletions.
6 changes: 5 additions & 1 deletion java/src/jmri/jmrix/lenz/XNetSystemConnectionMemo.java
Expand Up @@ -87,7 +87,11 @@ public void setProgrammerManager(XNetProgrammerManager p) {
*/ */
public ThrottleManager getThrottleManager() { public ThrottleManager getThrottleManager() {
if (throttleManager == null) { 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; return throttleManager;
} }
Expand Down
238 changes: 49 additions & 189 deletions java/src/jmri/jmrix/lenz/XNetThrottle.java

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions java/src/jmri/jmrix/roco/RocoXNetThrottle.java
@@ -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);

}
44 changes: 44 additions & 0 deletions java/src/jmri/jmrix/roco/RocoXNetThrottleManager.java
@@ -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);

}
32 changes: 2 additions & 30 deletions java/src/jmri/jmrix/roco/z21/Z21XNetThrottle.java
Expand Up @@ -14,7 +14,7 @@
* *
* @author Paul Bender (C) 2015 * @author Paul Bender (C) 2015
*/ */
public class Z21XNetThrottle extends jmri.jmrix.lenz.XNetThrottle { public class Z21XNetThrottle extends jmri.jmrix.roco.RocoXNetThrottle {


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


// The Z21 doesn't support setting the momentary/continuous status of // The Roco Doesn't support the XpressNet directed emergency stop
// 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
// instruction, so override sendEmergencyStop in the parent, and // instruction, so override sendEmergencyStop in the parent, and
// just send speed step 0. // just send speed step 0.
@Override @Override
Expand Down
15 changes: 1 addition & 14 deletions java/src/jmri/jmrix/roco/z21/Z21XNetThrottleManager.java
Expand Up @@ -11,7 +11,7 @@
* *
* @author Paul Bender Copyright (C) 2002-2004 * @author Paul Bender Copyright (C) 2002-2004
*/ */
public class Z21XNetThrottleManager extends jmri.jmrix.lenz.XNetThrottleManager { public class Z21XNetThrottleManager extends jmri.jmrix.roco.RocoXNetThrottleManager {


/** /**
* Constructor. * Constructor.
Expand All @@ -20,19 +20,6 @@ public Z21XNetThrottleManager(XNetSystemConnectionMemo memo) {
super(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 * Request a new throttle object be created for the address, and let the
* throttle listeners know about it. * throttle listeners know about it.
Expand Down
4 changes: 3 additions & 1 deletion java/test/jmri/jmrix/lenz/XNetThrottleTest.java
Expand Up @@ -86,10 +86,12 @@ public void testInitSequenceNormalUnitSpeedStep128() throws Exception {


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


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

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


// and verify all the data was set correctly. // and verify all the data was set correctly.
Expand Down
2 changes: 2 additions & 0 deletions java/test/jmri/jmrix/roco/PackageTest.java
Expand Up @@ -9,6 +9,8 @@
jmri.jmrix.roco.z21.PackageTest.class, jmri.jmrix.roco.z21.PackageTest.class,
BundleTest.class, BundleTest.class,
RocoCommandStationTest.class, RocoCommandStationTest.class,
RocoXNetThrottleTest.class,
RocoXNetThrottleManagerTest.class,
}) })


/** /**
Expand Down
34 changes: 34 additions & 0 deletions java/test/jmri/jmrix/roco/RocoXNetThrottleManagerTest.java
@@ -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.