use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistController method setConsistCVs.
/**
* set CV 21&22 for consist functions send each CV individually
*
* @param message RCF<;> locoAddress <:> CV# <;> value
*/
private void setConsistCVs(String message) {
DccLocoAddress loco;
List<String> headerAndCVs = Arrays.asList(message.split("<:>"));
if (log.isDebugEnabled()) {
log.debug("setConsistCVs string: " + message);
}
try {
List<String> headerData = Arrays.asList(headerAndCVs.get(0).split("<;>"));
loco = stringToDcc(headerData.get(1));
if (checkForBroadcastAddress(loco)) {
return;
}
} catch (NullPointerException e) {
log.warn("setConsistCVs error for message: " + message);
return;
}
AddressedProgrammer pom = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(loco.isLongAddress(), loco.getNumber());
// loco done, now get CVs
for (int i = 1; i < headerAndCVs.size(); i++) {
List<String> CVData = Arrays.asList(headerAndCVs.get(i).split("<;>"));
try {
int CVNum = Integer.parseInt(CVData.get(0));
int CVValue = Integer.parseInt(CVData.get(1));
try {
pom.writeCV(CVNum, CVValue, this);
} catch (ProgrammerException e) {
}
} catch (NumberFormatException nfe) {
log.warn("Error in setting CVs: " + nfe);
}
}
jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(pom);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistController method stringToDcc.
public DccLocoAddress stringToDcc(String s) {
int num = Integer.parseInt(s.substring(1));
boolean isLong = (s.charAt(0) == 'L');
return (new DccLocoAddress(num, isLong));
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistController method reorderConsist.
/**
* Change the sequence of locos in this consist. Reorders the consistList,
* instead of setting the 'position' value. Lead and Trail are set on first
* and last locos by DccConsist.
*
* @param message RCP<;>consistAddress<:>leadLoco<;>nextLoco<;>...
* ...<;>nextLoco<;>trailLoco
*/
private void reorderConsist(String message) {
Consist consist;
List<String> headerAndLocos = Arrays.asList(message.split("<:>"));
if (headerAndLocos.size() < 2) {
log.warn("reorderConsist missing data in message: " + message);
return;
}
try {
List<String> headerData = Arrays.asList(headerAndLocos.get(0).split("<;>"));
//
consist = manager.getConsist(stringToDcc(headerData.get(1)));
List<String> locoData = Arrays.asList(headerAndLocos.get(1).split("<;>"));
/*
* Reorder the consistList:
* For each loco sent, remove it from the consistList
* and reinsert it at the front of the list.
*/
for (String loco : locoData) {
ArrayList<DccLocoAddress> conList = consist.getConsistList();
int index = conList.indexOf(stringToDcc(loco));
if (index != -1) {
conList.add(conList.remove(index));
}
}
} catch (NullPointerException e) {
log.warn("reorderConsist error for message: " + message);
return;
}
writeFile();
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistController method removeLoco.
/**
* remove a loco if it exist in this consist.
*
* @param message RC-<;>consistAddress<:>locoAddress
*/
private void removeLoco(String message) {
Consist consist;
List<String> headerAndLoco = Arrays.asList(message.split("<:>"));
if (log.isDebugEnabled()) {
log.debug("remove loco string: " + message);
}
try {
List<String> headerData = Arrays.asList(headerAndLoco.get(0).split("<;>"));
consist = manager.getConsist(stringToDcc(headerData.get(1)));
List<String> locoData = Arrays.asList(headerAndLoco.get(1).split("<;>"));
DccLocoAddress loco = stringToDcc(locoData.get(0));
if (checkForBroadcastAddress(loco)) {
return;
}
if (consist.contains(loco)) {
consist.remove(loco);
if (log.isDebugEnabled()) {
log.debug("Remove loco: " + loco + ", from consist: " + headerData.get(1));
}
}
} catch (NullPointerException e) {
log.warn("removeLoco error for message: " + message);
return;
}
writeFile();
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class WiFiConsistManager method stringToDcc.
public DccLocoAddress stringToDcc(String s) {
int num = Integer.parseInt(s.substring(1));
boolean isLong = (s.charAt(0) == 'L');
return (new DccLocoAddress(num, isLong));
}
Aggregations