예제 #1
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);
     }
   }
 }
예제 #2
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());
  }
예제 #3
0
  /**
   * This test checks that the store operation runs, but doesn't check the output for correctness.
   */
  public void testStore() throws jmri.JmriException {
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initConfigureManager();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initMemoryManager();
    JUnitUtil.initLayoutBlockManager();

    Block b1 =
        InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb1", "");

    Block b2 =
        InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemNameb2", "");

    Sensor s2 =
        new AbstractSensor("IS2") {
          public void requestUpdateFromLayout() {}
        };
    b2.setSensor("IS2");
    s2.setState(Sensor.ACTIVE);
    b2.setValue("b2 contents");

    Path p21 = new Path();
    p21.setBlock(b1);
    p21.setFromBlockDirection(Path.RIGHT);
    p21.setToBlockDirection(Path.LEFT);
    p21.addSetting(
        new BeanSetting(
            new jmri.implementation.AbstractTurnout("IT1") {
              public void turnoutPushbuttonLockout(boolean b) {}

              public void forwardCommandChangeToLayout(int i) {}
            },
            jmri.Turnout.THROWN));
    b2.addPath(p21);

    // BlockManagerXml tb = new BlockManagerXml();
  }
예제 #4
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());
  }
예제 #5
0
 @Override
 public Object getValueAt(int row, int col) {
   if (row > sysNameList.size()) {
     return "";
   }
   OBlock b = null;
   if (row < sysNameList.size()) {
     String name = sysNameList.get(row);
     b = _manager.getBySystemName(name);
   }
   switch (col) {
     case SYSNAMECOL:
       if (b != null) {
         return b.getSystemName();
       }
       return tempRow[col];
     case USERNAMECOL:
       if (b != null) {
         return b.getUserName();
       }
       return tempRow[col];
     case COMMENTCOL:
       if (b != null) {
         return b.getComment();
       }
       return tempRow[col];
     case STATECOL:
       if (b != null) {
         int state = b.getState();
         int num = Integer.numberOfLeadingZeros(state) - 24;
         if (num >= 0) {
           return ZEROS.substring(0, num) + Integer.toBinaryString(state);
         }
       }
       return ZEROS;
     case SENSORCOL:
       if (b != null) {
         Sensor s = b.getSensor();
         if (s == null) {
           return "";
         }
         return s.getDisplayName();
       }
       return tempRow[col];
     case LENGTHCOL:
       if (b != null) {
         if (b.isMetric()) {
           return (twoDigit.format(b.getLengthCm()));
         }
         return (twoDigit.format(b.getLengthIn()));
       }
       if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) {
         return (twoDigit.format(_tempLen / 10));
       }
       return (twoDigit.format(_tempLen / 25.4f));
     case UNITSCOL:
       if (b != null) {
         if (log.isDebugEnabled()) {
           log.debug(
               "getValueAt: row= "
                   + row
                   + ", col= "
                   + col
                   + ", "
                   + b.getDisplayName()
                   + " isMetric= "
                   + b.isMetric());
         }
         return b.isMetric();
       }
       if (log.isDebugEnabled()) {
         log.debug(
             "getValueAt: row= "
                 + row
                 + ", col= "
                 + col
                 + ", is cm= "
                 + tempRow[UNITSCOL].equals(Bundle.getMessage("cm")));
       }
       return Boolean.valueOf(tempRow[UNITSCOL].equals(Bundle.getMessage("cm")));
     case CURVECOL:
       if (b != null) {
         String c = "";
         if (b.getCurvature() == Block.NONE) {
           c = noneText;
         } else if (b.getCurvature() == Block.GRADUAL) {
           c = gradualText;
         } else if (b.getCurvature() == Block.TIGHT) {
           c = tightText;
         } else if (b.getCurvature() == Block.SEVERE) {
           c = severeText;
         }
         return c;
       }
       return tempRow[col];
     case ERR_SENSORCOL:
       if (b != null) {
         Sensor s = b.getErrorSensor();
         if (s == null) {
           return "";
         }
         return s.getDisplayName();
       }
       return tempRow[col];
     case REPORTERCOL:
       if (b != null) {
         Reporter r = b.getReporter();
         if (r == null) {
           return "";
         }
         return r.getDisplayName();
       }
       return tempRow[col];
     case REPORT_CURRENTCOL:
       if (b != null) {
         if (b.getReporter() != null) {
           return b.isReportingCurrent();
         }
         return "";
       }
       return Boolean.valueOf(tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current")));
     case PERMISSIONCOL:
       if (b != null) {
         return b.getPermissiveWorking();
       }
       return Boolean.valueOf(tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive")));
     case SPEEDCOL:
       if (b != null) {
         return b.getBlockSpeed();
       }
       return tempRow[col];
     case EDIT_COL:
       if (b != null) {
         return Bundle.getMessage("ButtonEditPath");
       }
       return "";
     case DELETE_COL:
       if (b != null) {
         return Bundle.getMessage("ButtonDelete");
       }
       return Bundle.getMessage("ButtonClear");
   }
   return super.getValueAt(row, col);
 }