use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.
the class JmriSRCPSensorServer method sendStatus.
public void sendStatus(int bus, int address) throws IOException {
log.debug("send Status called with bus " + bus + " and address " + address);
java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
SystemConnectionMemo memo;
try {
memo = list.get(bus - 1);
} catch (java.lang.IndexOutOfBoundsException obe) {
TimeStampedOutput.writeTimestamp(output, "412 ERROR wrong value\n\r");
return;
}
String sensorName = memo.getSystemPrefix() + "S" + address;
try {
int Status = InstanceManager.sensorManagerInstance().provideSensor(sensorName).getKnownState();
if (Status == Sensor.ACTIVE) {
TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " FB " + address + " 1\n\r");
} else if (Status == Sensor.INACTIVE) {
TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " FB " + address + " 0\n\r");
} else {
// unknown state
TimeStampedOutput.writeTimestamp(output, "411 ERROR unknown value\n\r");
}
} catch (IllegalArgumentException ex) {
log.warn("Failed to provide Sensor \"{}\" in sendStatus", sensorName);
}
}
use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.
the class SerialDriverAdapter method validOption1.
/**
* Option 1 controls the connection used for programming
*/
public String[] validOption1() {
List<SystemConnectionMemo> connList = jmri.InstanceManager.getList(SystemConnectionMemo.class);
if (!connList.isEmpty()) {
ArrayList<String> progConn = new ArrayList<>();
progConn.add("");
String userName = "Dcc4Pc";
if (this.getSystemConnectionMemo() != null) {
userName = this.getSystemConnectionMemo().getUserName();
}
for (int i = 0; i < connList.size(); i++) {
SystemConnectionMemo scm = connList.get(i);
if (scm.provides(jmri.ProgrammerManager.class) && (!scm.getUserName().equals(userName))) {
progConn.add(scm.getUserName());
}
}
return progConn.toArray(new String[progConn.size()]);
} else {
return new String[] { "" };
}
}
use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.
the class ManagerDefaultSelector method configure.
/**
* Load into InstanceManager
*
* @return an exception that can be passed to the user or null if no errors
* occur
*/
@CheckForNull
public InitializationException configure() {
InitializationException error = null;
List<SystemConnectionMemo> connList = InstanceManager.getList(SystemConnectionMemo.class);
log.debug("configure defaults into InstanceManager from {} memos, {} defaults", connList.size(), defaults.keySet().size());
for (Class<?> c : defaults.keySet()) {
// 'c' is the class to load
String connectionName = this.defaults.get(c);
// have to find object of that type from proper connection
boolean found = false;
for (SystemConnectionMemo memo : connList) {
String testName = memo.getUserName();
if (testName.equals(connectionName)) {
found = true;
// match, store
try {
if (memo.provides(c)) {
log.debug(" setting default for \"{}\" to \"{}\" in configure", c, memo.get(c));
InstanceManager.setDefault(c, memo.get(c));
}
} catch (NullPointerException ex) {
// NOI18N
String englishMsg = Bundle.getMessage(Locale.ENGLISH, "ErrorNullDefault", memo.getUserName(), c);
// NOI18N
String localizedMsg = Bundle.getMessage("ErrorNullDefault", memo.getUserName(), c);
error = new InitializationException(englishMsg, localizedMsg);
log.warn("SystemConnectionMemo for {} ({}) provides a null {} instance", memo.getUserName(), memo.getClass(), c);
}
break;
} else {
log.debug(" memo name didn't match: {} vs {}", testName, connectionName);
}
}
/*
* If the set connection can not be found then we shall set the manager default to use what
* has currently been set.
*/
if (!found) {
log.debug("!found, so resetting");
String currentName = null;
if (c == ThrottleManager.class && InstanceManager.getNullableDefault(ThrottleManager.class) != null) {
currentName = InstanceManager.throttleManagerInstance().getUserName();
} else if (c == PowerManager.class && InstanceManager.getNullableDefault(PowerManager.class) != null) {
currentName = InstanceManager.getDefault(PowerManager.class).getUserName();
} else if (c == ProgrammerManager.class && InstanceManager.getNullableDefault(ProgrammerManager.class) != null) {
currentName = InstanceManager.getDefault(ProgrammerManager.class).getUserName();
}
if (currentName != null) {
log.warn("The configured " + connectionName + " for " + c + " can not be found so will use the default " + currentName);
this.defaults.put(c, currentName);
}
}
}
return error;
}
Aggregations