示例#1
0
  public void testInvokeNoLock() throws JmriException {
    OsIndicator os = new OsIndicator("IT12", "IS34", "");

    Turnout t1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT12");
    t1.setCommandedState(Turnout.CLOSED);

    Sensor s1 = InstanceManager.sensorManagerInstance().provideSensor("IS34");
    s1.setKnownState(Sensor.INACTIVE);

    Assert.assertEquals("sensor before", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("output before", Turnout.CLOSED, t1.getCommandedState());

    os.instantiate();

    Assert.assertEquals("sensor after instantiate", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("output after instantiate", Turnout.CLOSED, t1.getCommandedState());

    // and change
    s1.setKnownState(Sensor.ACTIVE);

    Assert.assertEquals("sensor after activate", Sensor.ACTIVE, s1.getKnownState());
    Assert.assertEquals("output after activate", Turnout.THROWN, t1.getCommandedState());

    s1.setKnownState(Sensor.INACTIVE);

    Assert.assertEquals("sensor after inactivate", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("output after inactivate", Turnout.CLOSED, t1.getCommandedState());
  }
示例#2
0
 @Override
 public void parseStatus(String statusString) throws jmri.JmriException, java.io.IOException {
   int index;
   index = statusString.indexOf(" ") + 1;
   if (statusString.contains("INACTIVE")) {
     if (log.isDebugEnabled()) {
       log.debug("Setting Sensor INACTIVE");
     }
     initSensor(statusString.substring(index, statusString.indexOf(" ", index + 1)).toUpperCase());
     setSensorInactive(
         statusString.substring(index, statusString.indexOf(" ", index + 1)).toUpperCase());
   } else if (statusString.contains("ACTIVE")) {
     if (log.isDebugEnabled()) {
       log.debug("Setting Sensor ACTIVE");
     }
     initSensor(statusString.substring(index, statusString.indexOf(" ", index + 1)).toUpperCase());
     setSensorActive(
         statusString.substring(index, statusString.indexOf(" ", index + 1)).toUpperCase());
   } else {
     // default case, return status for this sensor/
     String sensorName =
         statusString.substring(index, statusString.length() - 1).toUpperCase(); // remove the \n
     if (sensorName.contains(" ")) {
       // remove anything following the space.
       sensorName = sensorName.substring(0, sensorName.indexOf(" "));
     }
     try {
       Sensor sensor = jmri.InstanceManager.sensorManagerInstance().provideSensor(sensorName);
       sendStatus(sensorName, sensor.getKnownState());
     } catch (IllegalArgumentException ex) {
       log.warn("Failed to provide Sensor \"{}\" in sendStatus", sensorName);
     }
   }
 }
示例#3
0
  public void testIntantiateLocked() throws JmriException {
    OsIndicator os = new OsIndicator("IT12", "IS34", "IS56");

    Turnout t1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT12");
    t1.setCommandedState(Turnout.CLOSED);

    Sensor s1 = InstanceManager.sensorManagerInstance().provideSensor("IS34");
    s1.setKnownState(Sensor.INACTIVE);

    Sensor s2 = InstanceManager.sensorManagerInstance().provideSensor("IS56");
    s2.setKnownState(Sensor.INACTIVE);

    Assert.assertEquals("sensor before", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("lock before", Sensor.INACTIVE, s2.getKnownState());
    Assert.assertEquals("output before", Turnout.CLOSED, t1.getCommandedState());

    os.instantiate();

    Assert.assertEquals("sensor after instantiate", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("lock after instantiate", Sensor.INACTIVE, s2.getKnownState());
    Assert.assertEquals("output after instantiate", Turnout.CLOSED, t1.getCommandedState());
  }