use of jmri.SensorManager in project JMRI by JMRI.
the class AbstractTurnout method provideSecondFeedbackSensor.
@Override
public void provideSecondFeedbackSensor(String pName) throws jmri.JmriException, IllegalArgumentException {
if (InstanceManager.getNullableDefault(SensorManager.class) != null) {
if (pName == null || pName.equals("")) {
provideSecondFeedbackNamedSensor(null);
} else {
Sensor sensor = InstanceManager.sensorManagerInstance().provideSensor(pName);
provideSecondFeedbackNamedSensor(jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(pName, sensor));
}
} else {
log.error("No SensorManager for this protocol");
throw new jmri.JmriException("No Sensor Manager Found");
}
}
use of jmri.SensorManager in project JMRI by JMRI.
the class JsonUtil method getRoute.
@Deprecated
public static JsonNode getRoute(Locale locale, String name) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, ROUTE);
ObjectNode data = root.putObject(DATA);
try {
Route route = InstanceManager.getDefault(jmri.RouteManager.class).getRoute(name);
SensorManager s = InstanceManager.sensorManagerInstance();
data.put(NAME, route.getSystemName());
data.put(USERNAME, route.getUserName());
data.put(COMMENT, route.getComment());
Sensor sensor = s.getSensor(route.getTurnoutsAlignedSensor());
if (sensor != null) {
switch(sensor.getKnownState()) {
case Sensor.ACTIVE:
data.put(STATE, ACTIVE);
break;
case Sensor.INACTIVE:
data.put(STATE, INACTIVE);
break;
case Sensor.INCONSISTENT:
data.put(STATE, INCONSISTENT);
break;
case Sensor.UNKNOWN:
default:
data.put(STATE, UNKNOWN);
break;
}
} else {
data.put(STATE, UNKNOWN);
}
} catch (NullPointerException e) {
log.error("Unable to get route [{}].", name);
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", ROUTE, name));
}
return root;
}
use of jmri.SensorManager in project JMRI by JMRI.
the class OBlockTest method testSetErrorSensor.
@Test
public void testSetErrorSensor() throws Exception {
OBlock b = blkMgr.createNewOBlock("OB101", "b");
Assert.assertFalse("setErrorSensor foo", b.setErrorSensor("foo"));
Assert.assertNull("getErrorSensor foo", b.getErrorSensor());
SensorManager sensorMgr = InstanceManager.getDefault(SensorManager.class);
Sensor se = sensorMgr.newSensor("ISE1", "error1");
se.setState(Sensor.ACTIVE);
Assert.assertTrue("setErrorSensor only", b.setErrorSensor("error1"));
Assert.assertEquals("getErrorSensor only", se, b.getErrorSensor());
Assert.assertEquals("state error only", OBlock.TRACK_ERROR | OBlock.UNDETECTED, b.getState());
Sensor s1 = sensorMgr.newSensor("IS1", "sensor1");
s1.setState(Sensor.ACTIVE);
Assert.assertTrue("setSensor", b.setSensor("IS1"));
Assert.assertEquals("getErrorSensor se", se, b.getErrorSensor());
Assert.assertEquals("state error", OBlock.TRACK_ERROR | OBlock.OCCUPIED, b.getState());
Assert.assertTrue("setErrorSensor", b.setErrorSensor(" "));
Assert.assertNull("getErrorSensor none", b.getErrorSensor());
Assert.assertEquals("state dark", OBlock.OCCUPIED, b.getState());
}
use of jmri.SensorManager in project JMRI by JMRI.
the class OBlockTest method testSetSensor.
@Test
public void testSetSensor() throws Exception {
OBlock b = blkMgr.createNewOBlock("OB100", "a");
Assert.assertFalse("setSensor", b.setSensor("foo"));
Assert.assertNull("getSensor", b.getSensor());
SensorManager sensorMgr = InstanceManager.getDefault(SensorManager.class);
Sensor s1 = sensorMgr.newSensor("IS1", "sensor1");
Assert.assertTrue("setSensor", b.setSensor("sensor1"));
Assert.assertEquals("getSensor", s1, b.getSensor());
Assert.assertEquals("state unknown", OBlock.UNKNOWN, b.getState());
Assert.assertTrue("dup setSensor", b.setSensor("IS1"));
Assert.assertEquals("dup getSensor s1", s1, b.getSensor());
Assert.assertEquals("dup state unknown", OBlock.UNKNOWN, b.getState());
Assert.assertTrue("setSensor none", b.setSensor(" "));
Assert.assertNull("getSensor none", b.getSensor());
Assert.assertEquals("none state dark", OBlock.UNDETECTED, b.getState());
Assert.assertTrue("Not Free", b.isFree());
b.setState(b.getState() | OBlock.ALLOCATED | OBlock.RUNNING);
Assert.assertFalse("Is Free", b.isFree());
s1.setState(Sensor.ACTIVE);
Assert.assertTrue("setSensor sensor1", b.setSensor("sensor1"));
Assert.assertEquals("state allocated&running", OBlock.OCCUPIED | OBlock.ALLOCATED | OBlock.RUNNING, b.getState());
}
use of jmri.SensorManager in project JMRI by JMRI.
the class InternalSensorManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
// ask for a Sensor, and check type
SensorManager lm = jmri.InstanceManager.sensorManagerInstance();
Sensor tl = lm.newSensor("IS21", "my name");
if (log.isDebugEnabled()) {
log.debug("received sensor value " + tl);
}
Assert.assertTrue(null != tl);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + lm.getBySystemName("IS21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + lm.getByUserName("my name"));
}
Assert.assertTrue(null != lm.getBySystemName("IS21"));
Assert.assertTrue(null != lm.getByUserName("my name"));
}
Aggregations