use of jmri.JmriException in project JMRI by JMRI.
the class SerialTurnoutManager method createSystemName.
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
String tmpSName = prefix + "T" + curAddress;
if (curAddress.contains(":")) {
//Address format passed is in the form of node:cardOutput or node:card:address
int seperator = curAddress.indexOf(":");
try {
nNode = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
int nxSeperator = curAddress.indexOf(":", seperator + 1);
if (nxSeperator == -1) {
//Address has been entered in the format node:cardOutput
bitNum = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
} else {
//Address has been entered in the format node:card:output
nCard = Integer.valueOf(curAddress.substring(seperator + 1, nxSeperator)).intValue() * 100;
bitNum = Integer.valueOf(curAddress.substring(nxSeperator + 1)).intValue();
}
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
throw new JmriException("Hardware Address passed should be a number");
}
tmpSName = prefix + "T" + nNode + (nCard + bitNum);
} else {
bitNum = SerialAddress.getBitFromSystemName(tmpSName);
nNode = SerialAddress.getNodeAddressFromSystemName(tmpSName);
tmpSName = prefix + "T" + nNode + bitNum;
}
return (tmpSName);
}
use of jmri.JmriException in project JMRI by JMRI.
the class XNetSensorManager method getNextValidAddress.
/**
* Does not enforce any rules on the encoder or input values.
*/
@Override
public synchronized String getNextValidAddress(String curAddress, String prefix) {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
Sensor s = getBySystemName(tmpSName);
if (s != null) {
for (int x = 1; x < 10; x++) {
iName = iName + 1;
s = getBySystemName(prefix + typeLetter() + iName);
if (s == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.JmriException in project JMRI by JMRI.
the class LnSensorManager method getNextValidAddress.
@Override
public String getNextValidAddress(String curAddress, String prefix) {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, // NOI18N
false);
return null;
}
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
Sensor s = getBySystemName(tmpSName);
if (s != null) {
for (int x = 1; x < 10; x++) {
iName = iName + 1;
s = getBySystemName(prefix + typeLetter() + iName);
if (s == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.JmriException in project JMRI by JMRI.
the class LnSensorManager method createSystemName.
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
if (curAddress.contains(":")) {
int board = 0;
int channel = 0;
//Address format passed is in the form of board:channel or T:turnout address
int seperator = curAddress.indexOf(":");
boolean turnout = false;
if (curAddress.substring(0, seperator).toUpperCase().equals("T")) {
turnout = true;
} else {
try {
board = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
} catch (NumberFormatException ex) {
// NOI18N
log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
// NOI18N
throw new JmriException("Hardware Address passed should be a number");
}
}
try {
channel = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
} catch (NumberFormatException ex) {
// NOI18N
log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
// NOI18N
throw new JmriException("Hardware Address passed should be a number");
}
if (turnout) {
iName = 2 * (channel - 1) + 1;
} else {
iName = 16 * board + channel - 16;
}
} else {
//Entered in using the old format
try {
iName = Integer.parseInt(curAddress);
} catch (NumberFormatException ex) {
// NOI18N
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
// NOI18N
throw new JmriException("Hardware Address passed should be a number");
}
}
return prefix + typeLetter() + iName;
}
use of jmri.JmriException in project JMRI by JMRI.
the class SerialTurnoutManager method getNextValidAddress.
@Override
public String getNextValidAddress(String curAddress, String prefix) {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//If the hardware address past does not already exist then this can
//be considered the next valid address.
Turnout t = getBySystemName(tmpSName);
if (t == null) {
int seperator = tmpSName.lastIndexOf("T") + 1;
curAddress = tmpSName.substring(seperator);
return curAddress;
}
//The Number of Output Bits of the previous turnout will help determine the next
//valid address.
bitNum = bitNum + t.getNumberOutputBits();
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
tmpSName = SerialAddress.makeSystemName("T", nAddress, bitNum);
t = getBySystemName(tmpSName);
if (t != null) {
for (int x = 1; x < 10; x++) {
bitNum = bitNum + t.getNumberOutputBits();
//This should increment " + bitNum
tmpSName = SerialAddress.makeSystemName("T", nAddress, bitNum);
t = getBySystemName(tmpSName);
if (t == null) {
int seperator = tmpSName.lastIndexOf("T") + 1;
curAddress = tmpSName.substring(seperator);
return curAddress;
}
}
return null;
} else {
int seperator = tmpSName.lastIndexOf("T") + 1;
curAddress = tmpSName.substring(seperator);
return curAddress;
}
}
Aggregations