From: Stephen P W. <ste...@pa...> - 2010-03-30 04:53:04
|
This question is probably best answered by either Bob J or Dan Boudreau... I have been playing with the WiThrottle app on my iPhone recently, and have discovered a behavioral difference between how WiThrottle drives advanced consists on a NCE PowerCab with NCE-USB interface versus a full PH-Pro system. Digging deeper, I find that this behavior stems from the NceThrottle class in java/src/jmri/jmrix/nce/NceThrottle.java. Briefly, when you are connected to a PowerCab through an NCE-USB interface, you can drive advance consists in the same way that the regular NCE throttles can: you pick the "front" engine and "forward" makes the consist moves forward, you pick the "rear" engine and "forward" makes the consist move backwards (so the rear engine is moving forwards). But when you are connected through an NCE PowerHouse system, you have to dial up the 7-bit consist address and keep track of which end of the consist is forward or backward yourself. At the moment, this is intentional behavior: when the connection is an NCE-USB, the code sends throttle commands using NCE binary command 0xA2, and when it is not, it makes up the raw DCC packets and sends low-level commands to the command station that bypass the consist/throttle management table in the command station. There is this comment, left by Dan Boudreau at CVS version 1.12: 1.12 (dan_boud 02-Dec-07): // This code can be eliminated once we confirm that the NCE 0xA2 1.12 (dan_boud 02-Dec-07): // commands work properly 1.12 (dan_boud 02-Dec-07): } else { 1.12 (dan_boud 02-Dec-07): byte[] result = jmri.NmraPacket.function5Through8Packet(address 1.12 (dan_boud 02-Dec-07): .getNumber(), address.isLongAddress(), getF5(), getF6(), 1.12 (dan_boud 02-Dec-07): getF7(), getF8()); 1.12 (dan_boud 02-Dec-07): NceMessage m = NceMessage.sendPacketMessage(result); 1.12 (dan_boud 02-Dec-07): NceTrafficController.instance().sendNceMessage(m, null); 1.12 (dan_boud 02-Dec-07): } I do not have a large history with NCE hardware, and do not know what versions of the NCE command station firmware would have had broken 0xA2 commands. I do know that my PowerHouse-Pro with the March 2007a EPROM works just fine with the 0xA2 commands, and I propose the following patch for your consideration. This code sets a boolean member variable called "sendA2Commands" based on querying the command station options and then uses that variable to select among the two existing implementations. My questions: 1. Is the structure of this patch reasonable? It seems to work on my PH-Pro, but I don't have access to earlier EPROMS to test. 2. Is the method of detection of the current (March 2007a) EPROM correct? Anybody see anything else I missed? Thanks, Steve Williams Including the patch in-line because I don't know if the list strips attachments. diff --git a/java/src/jmri/jmrix/nce/NceThrottle.java b/java/src/jmri/jmrix/nce/NceThrottle.java index fc9b79e..f6ab0da 100644 --- a/java/src/jmri/jmrix/nce/NceThrottle.java +++ b/java/src/jmri/jmrix/nce/NceThrottle.java @@ -18,6 +18,7 @@ import jmri.jmrix.AbstractThrottle; */ public class NceThrottle extends AbstractThrottle { + private boolean sendA2Commands = false; /** * Constructor. */ @@ -61,6 +62,12 @@ public class NceThrottle extends AbstractThrottle this.address = address; this.isForward = true; + if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) + this.sendA2Commands = true; + else if (NceMessage.getCommandOptions() == NceMessage.OPTION_2006) + this.sendA2Commands = true; + else + this.sendA2Commands = false; } DccLocoAddress address; @@ -72,7 +79,7 @@ public class NceThrottle extends AbstractThrottle */ protected void sendFunctionGroup1() { // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { int locoAddr = address.getNumber(); if (address.isLongAddress()) locoAddr += 0xC000; @@ -105,7 +112,7 @@ public class NceThrottle extends AbstractThrottle */ protected void sendFunctionGroup2() { // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { int locoAddr = address.getNumber(); if (address.isLongAddress()) locoAddr += 0xC000; @@ -137,7 +144,7 @@ public class NceThrottle extends AbstractThrottle */ protected void sendFunctionGroup3() { // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { int locoAddr = address.getNumber(); if (address.isLongAddress()) locoAddr += 0xC000; @@ -169,7 +176,7 @@ public class NceThrottle extends AbstractThrottle */ protected void sendFunctionGroup4() { // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { int locoAddr = address.getNumber(); if (address.isLongAddress()) locoAddr += 0xC000; @@ -204,7 +211,7 @@ public class NceThrottle extends AbstractThrottle */ protected void sendFunctionGroup5() { // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { int locoAddr = address.getNumber(); if (address.isLongAddress()) locoAddr += 0xC000; @@ -245,7 +252,7 @@ public class NceThrottle extends AbstractThrottle this.speedSetting = speed; // The NCE USB doesn't support the NMRA packet format - if (NceUSB.getUsbSystem() != NceUSB.USB_SYSTEM_NONE) { + if (sendA2Commands) { byte[] bl; int value; @@ -324,8 +331,8 @@ public class NceThrottle extends AbstractThrottle } /** - * Dispose when finished with this object. After this, further usage of this - * Throttle object will result in a JmriException. + * Dispose when finished with this object. After this, further + * usage of this Throttle object will result in a JmriException. */ public void dispose() { log.debug("dispose"); |