Search in sources :

Example 11 with SensorManager

use of jmri.SensorManager in project JMRI by JMRI.

the class DCCppSensorManagerTest method testAsAbstractFactory.

@Test
public void testAsAbstractFactory() {
    // ask for a Sensor, and check type
    SensorManager t = jmri.InstanceManager.sensorManagerInstance();
    Sensor o = t.newSensor("DCCPPS21", "my name");
    if (log.isDebugEnabled()) {
        log.debug("received sensor value " + o);
    }
    Assert.assertTrue(null != (DCCppSensor) o);
    // make sure loaded into tables
    if (log.isDebugEnabled()) {
        log.debug("by system name: " + t.getBySystemName("DCCPPS21"));
    }
    if (log.isDebugEnabled()) {
        log.debug("by user name:   " + t.getByUserName("my name"));
    }
    Assert.assertTrue(null != t.getBySystemName("DCCPPS21"));
    Assert.assertTrue(null != t.getByUserName("my name"));
}
Also used : SensorManager(jmri.SensorManager) Sensor(jmri.Sensor) Test(org.junit.Test)

Example 12 with SensorManager

use of jmri.SensorManager in project JMRI by JMRI.

the class XNetSensorManagerTest method testAsAbstractFactory.

@Test
public void testAsAbstractFactory() {
    jmri.InstanceManager.setSensorManager(l);
    // ask for a Sensor, and check type
    SensorManager t = jmri.InstanceManager.sensorManagerInstance();
    Sensor o = t.newSensor("XS21", "my name");
    if (log.isDebugEnabled()) {
        log.debug("received sensor value " + o);
    }
    Assert.assertTrue(null != (XNetSensor) o);
    // make sure loaded into tables
    if (log.isDebugEnabled()) {
        log.debug("by system name: " + t.getBySystemName("XS21"));
    }
    if (log.isDebugEnabled()) {
        log.debug("by user name:   " + t.getByUserName("my name"));
    }
    Assert.assertTrue(null != t.getBySystemName("XS21"));
    Assert.assertTrue(null != t.getByUserName("my name"));
}
Also used : SensorManager(jmri.SensorManager) Sensor(jmri.Sensor) Test(org.junit.Test)

Example 13 with SensorManager

use of jmri.SensorManager in project JMRI by JMRI.

the class LnSensorManagerTest method testAsAbstractFactory.

@Test
public void testAsAbstractFactory() {
    // ask for a Sensor, and check type
    SensorManager t = jmri.InstanceManager.sensorManagerInstance();
    Sensor o = t.newSensor("LS21", "my name");
    if (log.isDebugEnabled()) {
        log.debug("received sensor value " + o);
    }
    Assert.assertTrue(null != (LnSensor) o);
    // make sure loaded into tables
    if (log.isDebugEnabled()) {
        log.debug("by system name: " + t.getBySystemName("LS21"));
    }
    if (log.isDebugEnabled()) {
        log.debug("by user name:   " + t.getByUserName("my name"));
    }
    Assert.assertTrue(null != t.getBySystemName("LS21"));
    Assert.assertTrue(null != t.getByUserName("my name"));
}
Also used : LnSensor(jmri.jmrix.loconet.LnSensor) SensorManager(jmri.SensorManager) Sensor(jmri.Sensor) LnSensor(jmri.jmrix.loconet.LnSensor) Test(org.junit.Test)

Example 14 with SensorManager

use of jmri.SensorManager in project JMRI by JMRI.

the class PositionableShape method setControlSensor.

/**
     * Attach a named sensor to shape
     *
     * @param pName Used as a system/user name to lookup the sensor object
     * @param hide true if sensor should be hidden
     * @param level level at which sensor is placed
     * @return error message, if any
     */
public String setControlSensor(String pName, boolean hide, int level) {
    String msg = null;
    if (pName == null || pName.trim().isEmpty()) {
        setControlSensorHandle(null);
        return null;
    }
    NamedBeanHandle<Sensor> senHandle = null;
    _saveLevel = super.getDisplayLevel();
    Optional<SensorManager> sensorManager = InstanceManager.getOptionalDefault(SensorManager.class);
    if (sensorManager.isPresent()) {
        Sensor sensor = sensorManager.get().getSensor(pName);
        Optional<NamedBeanHandleManager> nbhm = InstanceManager.getOptionalDefault(NamedBeanHandleManager.class);
        if (sensor != null) {
            if (nbhm.isPresent()) {
                senHandle = nbhm.get().getNamedBeanHandle(pName, sensor);
            }
            _doHide = hide;
            _changeLevel = level;
            if (_changeLevel <= 0) {
                _changeLevel = super.getDisplayLevel();
            }
        } else {
            // NOI18N
            msg = Bundle.getMessage("badSensorName", pName);
        }
    } else {
        // NOI18N
        msg = Bundle.getMessage("NoSensorManager");
    }
    if (msg != null) {
        log.warn("{} for {} sensor", msg, Bundle.getMessage("VisibleSensor"));
    }
    setControlSensorHandle(senHandle);
    return msg;
}
Also used : NamedBeanHandleManager(jmri.NamedBeanHandleManager) SensorManager(jmri.SensorManager) Sensor(jmri.Sensor)

Example 15 with SensorManager

use of jmri.SensorManager in project JMRI by JMRI.

the class AbstractTurnout method provideFirstFeedbackSensor.

@Override
public void provideFirstFeedbackSensor(String pName) throws jmri.JmriException, IllegalArgumentException {
    if (InstanceManager.getNullableDefault(SensorManager.class) != null) {
        if (pName == null || pName.equals("")) {
            provideFirstFeedbackNamedSensor(null);
        } else {
            Sensor sensor = InstanceManager.sensorManagerInstance().provideSensor(pName);
            provideFirstFeedbackNamedSensor(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");
    }
}
Also used : SensorManager(jmri.SensorManager) JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Aggregations

SensorManager (jmri.SensorManager)22 Sensor (jmri.Sensor)20 Test (org.junit.Test)9 JsonException (jmri.server.json.JsonException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JmriException (jmri.JmriException)4 Element (org.jdom2.Element)3 IOException (java.io.IOException)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 NamedBeanHandleManager (jmri.NamedBeanHandleManager)1 Route (jmri.Route)1 Positionable (jmri.jmrit.display.Positionable)1 LayoutBlock (jmri.jmrit.display.layoutEditor.LayoutBlock)1 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)1 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)1 LnSensor (jmri.jmrix.loconet.LnSensor)1 Document (org.jdom2.Document)1 XMLOutputter (org.jdom2.output.XMLOutputter)1