Skip to content

Commit

Permalink
Fix NCE simulator problems when selected the early NCE EPROM
Browse files Browse the repository at this point in the history
  • Loading branch information
danielboudreau authored and danielboudreau committed May 22, 2021
1 parent dd5365c commit ba42c97
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 89 deletions.
157 changes: 89 additions & 68 deletions java/src/jmri/jmrix/nce/NceConnectionStatus.java
@@ -1,10 +1,12 @@
package jmri.jmrix.nce;

import javax.swing.JOptionPane;
import jmri.jmrix.ConnectionStatus;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jmri.jmrix.ConnectionStatus;

@SuppressWarnings("unused")
/**
* Continuously checks and confirms that the communication link to the NCE
Expand Down Expand Up @@ -47,8 +49,6 @@ public class NceConnectionStatus implements NceListener {
private int epromState = INIT_STATE; // Eprom state
private boolean epromChecked = false;

private static boolean nceEpromMarch2007 = false; // flag to allow JMRI to be bug for bug compatible

// Our current knowledge of NCE Command Station EPROMs
private static final int VV_1999 = 4; // Revision of Apr 1999 EPROM VV.MM.mm = 4.0.1
private static final int MM_1999 = 0;
Expand Down Expand Up @@ -85,20 +85,20 @@ public class NceConnectionStatus implements NceListener {
// V6 flavors
private static final int mm_USB_V6_PwrCab = 0; // PowerCab
private static final int mm_USB_V6_SB3 = 1; // SB3
private static final int mm_USB_V6_PH = 2; // PH-Pro or PH-10
private static final int mm_USB_V6_PH = 2; // PH-Pro or PH-10
// Future releases by NCE (Not used by JMRI yet!)
private static final int mm_USB_V6_ALL = 3; // All systems, not currently used
private static final int mm_USB_V6_ALL = 3; // All systems, not currently used
private static final int mm_USB_V6_PC161 = 4; // Future use, PowerCab 1.61, not currently used
private static final int mm_USB_V6_SB161 = 5; // Future use, SB3 1.61, not currently used
// V7 flavors
private static final int mm_USB_V7_PC_128_A = 0; // PowerCab with 1.28c
private static final int mm_USB_V7_SB5_165_A = 1; // SB5 with 1.65
private static final int mm_USB_V7_SB5_165_B = 2; // SB5 with 1.65
private static final int mm_USB_V7_PC_165 = 3; // PowerCab with 1.65
private static final int mm_USB_V7_PC_165 = 3; // PowerCab with 1.65
private static final int mm_USB_V7_PC_128_B = 4; // PowerCab with 1.28c
private static final int mm_USB_V7_SB3 = 5; // SB3 with 1.28c
private static final int mm_USB_V7_PH = 6; // PowerPro with 3.1.2007
private static final int mm_USB_V7_ALL = 7; // All systems
private static final int mm_USB_V7_SB3 = 5; // SB3 with 1.28c
private static final int mm_USB_V7_PH = 6; // PowerPro with 3.1.2007
private static final int mm_USB_V7_ALL = 7; // All systems

private NceTrafficController tc = null;

Expand All @@ -113,7 +113,7 @@ public NceMessage nceEpromPoll() {
return null;
}

// normal state for this routine?
// normal state for this routine
if (epromState == NORMAL_STATE) {
// are there interface timeouts?
if (tc.hasTimeouts()) {
Expand All @@ -124,13 +124,15 @@ public NceMessage nceEpromPoll() {
}

if (epromState == CHECK_OK) {
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(), ConnectionStatus.CONNECTION_UP);
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(),
ConnectionStatus.CONNECTION_UP);
epromState = NORMAL_STATE;
return null;
}

if (epromState != INIT_STATE) {
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(), ConnectionStatus.CONNECTION_DOWN);
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(),
ConnectionStatus.CONNECTION_DOWN);
}

// no response from command station?
Expand All @@ -139,24 +141,26 @@ public NceMessage nceEpromPoll() {

if (JOptPane_WARNING_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null,
"JMRI could not establish communication with NCE command station. \n"
+ "Check the \"Serial port:\" and \"Baud rate:\" in Edit -> Preferences. \n"
+ "Confirm cabling and that the NCE system is powered up.", "Warning",
JOptionPane.WARNING_MESSAGE);
"JMRI could not establish communication with NCE command station. \n" +
"Check the \"Serial port:\" and \"Baud rate:\" in Edit -> Preferences. \n" +
"Confirm cabling and that the NCE system is powered up.",
"Warning", JOptionPane.WARNING_MESSAGE);
}

epromState = WARN1_STATE;
} // still no response from command station?
}

// still no response from command station?
else if (epromState == WARN1_STATE) {
log.warn("No response from NCE command station");
}

if (epromState == ERROR1_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null,
"Wrong revision of Command Station EPROM selected in Preferences \n"
+ "Change the Command Station EPROM selection to \"2004 or earlier\"", "Error",
JOptionPane.ERROR_MESSAGE);
"Wrong revision of Command Station EPROM selected in Preferences \n" +
"Change the Command Station EPROM selection to \"2004 or earlier\"",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
Expand All @@ -165,89 +169,106 @@ else if (epromState == WARN1_STATE) {
if (epromState == ERROR2_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null,
"Wrong revision of Command Station EPROM selected in Preferences \n"
+ "Change the Command Station EPROM selection to \"2006 or later\"", "Error",
JOptionPane.ERROR_MESSAGE);
"Wrong revision of Command Station EPROM selected in Preferences \n" +
"Change the Command Station EPROM selection to \"2006 or later\"",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

if (epromState == WARN2_STATE) {
log.warn("Detected 2007 March EPROM which doesn't provide reliable MONITORING feedback for turnouts");
if (JOptPane_WARNING_MESSAGES_ENABLED) // Need to add checkbox "Do not show this message again" otherwise
// Need to add checkbox "Do not show this message again" otherwise
// the message can be a pain.
{
JOptionPane.showMessageDialog(null, "The 2007 March EPROM doesn't provide reliable feedback,"
+ " contact NCE if you want to use MONITORING feedback ", "Warning",
JOptionPane.INFORMATION_MESSAGE);
if (JOptPane_WARNING_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null,
"The 2007 March EPROM doesn't provide reliable feedback," +
" contact NCE if you want to use MONITORING feedback ",
"Warning", JOptionPane.INFORMATION_MESSAGE);
}
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(), ConnectionStatus.CONNECTION_UP);
ConnectionStatus.instance().setConnectionState(tc.getUserName(), tc.getPortName(),
ConnectionStatus.CONNECTION_UP);
epromState = NORMAL_STATE;
return null;
}

if (epromState == ERROR4_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null, "Wrong NCE System Connection selected in Preferences. "
+ "Change the System Connection to \"" + jmri.jmrix.nce.serialdriver.ConnectionConfig.NAME
+ "\" or \"" + jmri.jmrix.nce.networkdriver.ConnectionConfig.NAME + "\".", "Error",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Wrong NCE System Connection selected in Preferences. " +
"Change the System Connection to \"" +
jmri.jmrix.nce.serialdriver.ConnectionConfig.NAME +
"\" or \"" +
jmri.jmrix.nce.networkdriver.ConnectionConfig.NAME +
"\".",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

if (epromState == ERROR5_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null, "Wrong NCE System Connection selected in Preferences. "
+ "The System Connection \"" + jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME
+ "\" should change the system to \"Power Cab\".", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Wrong NCE System Connection selected in Preferences. " +
"The System Connection \"" +
jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME +
"\" should change the system to \"Power Cab\".",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

if (epromState == ERROR6_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null, "Wrong NCE System Connection selected in Preferences. "
+ "The System Connection \"" + jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME
+ "\" should change the system to \"Smart Booster SB3\".", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Wrong NCE System Connection selected in Preferences. " +
"The System Connection \"" +
jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME +
"\" should change the system to \"Smart Booster SB3\".",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

if (epromState == ERROR7_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null, "Wrong NCE System Connection selected in Preferences. "
+ "The System Connection \"" + jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME
+ "\" should change the system to \"Power Pro\".", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Wrong NCE System Connection selected in Preferences. " +
"The System Connection \"" +
jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME +
"\" should change the system to \"Power Pro\".",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

if (epromState == ERROR8_STATE) {
if (JOptPane_ERROR_MESSAGES_ENABLED) {
JOptionPane.showMessageDialog(null, "Wrong NCE System Connection selected in Preferences. "
+ "The System Connection \"" + jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME
+ "\" should change the system to \"SB5\".", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,
"Wrong NCE System Connection selected in Preferences. " +
"The System Connection \"" +
jmri.jmrix.nce.usbdriver.ConnectionConfig.NAME +
"\" should change the system to \"SB5\".",
"Error", JOptionPane.ERROR_MESSAGE);
}
epromState = NORMAL_STATE;
return null;
}

// go ahead and read the EPROM revision
if (epromState != WARN1_STATE) // stay in error state until reply
{
// stay in error state until reply
if (epromState != WARN1_STATE) {
epromState = WAIT_STATE;
}

byte[] bl = NceBinaryCommand.getNceEpromRev();
NceMessage m = NceMessage.createBinaryMessage(tc, bl, REPLY_LEN);
return m;

}

@Override
Expand All @@ -266,7 +287,8 @@ public void reply(NceReply r) {
byte mm = (byte) r.getElement(2);
tc.setPwrProVers(VV, MM, mm);

// Is the reply valid? Check major revision, there are only three valid responses
// Is the reply valid? Check major revision, there are only three valid
// responses
// note that VV_2004 = VV_2007 = VV_USB
if (VV != VV_2012 && VV != VV_2004 && VV != VV_1999) {
log.error("Wrong major revision: {}", Integer.toHexString(VV & 0xFF));
Expand All @@ -289,7 +311,7 @@ public void reply(NceReply r) {

// Warn about the March 2007 CS EPROM
if (VV == VV_2007 && MM == MM_2007 && mm == mm_2007) {
setNceEpromMarch2007(true);
tc.setNceEpromMarch2007(true);
epromState = WARN2_STATE;
}

Expand All @@ -298,26 +320,32 @@ public void reply(NceReply r) {
tc.setPwrProVer060203orLater(true);
}

// Confirm that user selected correct revision of EPROM, check for old EPROM installed, new EPROM
// Confirm that user selected correct revision of EPROM, check for old EPROM
// installed, new EPROM
// preferences
if ((VV <= VV_2007 && MM < MM_2007) && (tc.getCommandOptions() >= NceTrafficController.OPTION_2006)) {
log.error("Wrong revision ({}) of the NCE Command Station EPROM selected in Preferences", tc.getPwrProVersHexText());
log.error("Wrong revision ({}) of the NCE Command Station EPROM selected in Preferences",
tc.getPwrProVersHexText());
epromState = ERROR1_STATE;
}

// Confirm that user selected correct revision of EPROM, check for new EPROM installed, old EPROM
// Confirm that user selected correct revision of EPROM, check for new EPROM
// installed, old EPROM
// preferences
boolean eprom2007orNewer = ((VV == VV_2007) && (MM >= MM_2007));
if (((VV > VV_2007) || eprom2007orNewer) && (tc.getCommandOptions() < NceTrafficController.OPTION_2006)) {
log.error("Wrong revision ({}) of the NCE Command Station EPROM selected in Preferences", tc.getPwrProVersHexText());
log.error("Wrong revision ({}) of the NCE Command Station EPROM selected in Preferences",
tc.getPwrProVersHexText());
epromState = ERROR2_STATE;
}

// Check that layout connection is correct
// PowerPro? 4 cases for PH, 1999, 2004, 2007, & 2012
if (VV == VV_1999 || (VV == VV_2004 && MM == MM_2004) || (VV == VV_2007 && MM == MM_2007)
|| (VV == VV_2012 && MM == MM_2012)) // make sure system connection is not NCE USB
{
if (VV == VV_1999 ||
(VV == VV_2004 && MM == MM_2004) ||
(VV == VV_2007 && MM == MM_2007) ||
(VV == VV_2012 && MM == MM_2012)) {
// make sure system connection is not NCE USB
if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE) {
log.error("System Connection is incorrect, detected Power Pro");
epromState = ERROR4_STATE;
Expand All @@ -343,7 +371,8 @@ public void reply(NceReply r) {
// Check for USB 7.3.x
if (VV == VV_USB_V7 && MM == MM_USB) {
// USB V7 detected, check to see if user preferences are correct
if (((mm == mm_USB_V7_PC_128_A) || (mm == mm_USB_V7_PC_128_B)) && tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_POWERCAB) {
if (((mm == mm_USB_V7_PC_128_A) || (mm == mm_USB_V7_PC_128_B)) &&
tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_POWERCAB) {
log.error("System Connection is incorrect, detected USB connected to a PowerCab");
epromState = ERROR5_STATE;
}
Expand All @@ -355,25 +384,17 @@ public void reply(NceReply r) {
log.error("System Connection is incorrect, detected USB connected to a Power Pro");
epromState = ERROR7_STATE;
}
if (((mm == mm_USB_V7_SB5_165_A) || (mm == mm_USB_V7_SB5_165_B)) && tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_SB5) {
if (((mm == mm_USB_V7_SB5_165_A) || (mm == mm_USB_V7_SB5_165_B)) &&
tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_SB5) {
log.error("System Connection is incorrect, detected USB connected to a Smart Booster SB5");
epromState = ERROR8_STATE;
}
}

} else {
log.warn("wrong number of read bytes for revision check");
}
}

public static boolean isNceEpromMarch2007() {
return nceEpromMarch2007;
}

private static void setNceEpromMarch2007(boolean b) {
nceEpromMarch2007 = b;
}

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

}
3 changes: 2 additions & 1 deletion java/src/jmri/jmrix/nce/NceSystemConnectionMemo.java
Expand Up @@ -76,7 +76,7 @@ public NceProgrammerManager getProgrammerManager() {
if (getDisabled()) {
return null;
}
return (NceProgrammerManager) classObjectMap.computeIfAbsent(NceProgrammerManager.class,(Class c) -> new NceProgrammerManager(this));
return (NceProgrammerManager) classObjectMap.computeIfAbsent(NceProgrammerManager.class,(Class<?> c) -> new NceProgrammerManager(this));
}

public void setProgrammerManager(NceProgrammerManager p) {
Expand All @@ -98,6 +98,7 @@ public void configureCommandStation(int val) {
* Configure the common managers for NCE connections. This puts the common
* manager config in one place.
*/
@Override
public void configureManagers() {
log.trace("configureManagers() with: {} ", getNceUsbSystem());
PowerManager powerManager = new jmri.jmrix.nce.NcePowerManager(this);
Expand Down

0 comments on commit ba42c97

Please sign in to comment.