Search in sources :

Example 66 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class JsonTurnoutSocketService method addListenersToChildren.

private void addListenersToChildren() {
    InstanceManager.getDefault(TurnoutManager.class).getSystemNameList().stream().forEach((tn) -> {
        //add listeners to each child (if not already)
        if (!turnoutListeners.containsKey(tn)) {
            log.debug("adding TurnoutListener for Turnout {}", tn);
            Turnout t = InstanceManager.getDefault(TurnoutManager.class).getTurnout(tn);
            if (t != null) {
                turnoutListeners.put(tn, new TurnoutListener(t));
                t.addPropertyChangeListener(this.turnoutListeners.get(tn));
            }
        }
    });
}
Also used : TurnoutManager(jmri.TurnoutManager) Turnout(jmri.Turnout)

Example 67 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class JsonTurnoutSocketService method onMessage.

@Override
public void onMessage(String type, JsonNode data, Locale locale) throws IOException, JmriException, JsonException {
    this.locale = locale;
    String name = data.path(NAME).asText();
    if (data.path(METHOD).asText().equals(PUT)) {
        this.connection.sendMessage(this.service.doPut(type, name, data, locale));
    } else {
        this.connection.sendMessage(this.service.doPost(type, name, data, locale));
    }
    if (!this.turnoutListeners.containsKey(name)) {
        Turnout turnout = InstanceManager.getDefault(TurnoutManager.class).getTurnout(name);
        TurnoutListener listener = new TurnoutListener(turnout);
        if (turnout != null) {
            turnout.addPropertyChangeListener(listener);
            this.turnoutListeners.put(name, listener);
        }
    }
}
Also used : Turnout(jmri.Turnout) TurnoutManager(jmri.TurnoutManager)

Example 68 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class MergSD2SignalHeadTest method testCTor.

@Test
public void testCTor() {
    Turnout it = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT1");
    NamedBeanHandle<Turnout> green = new NamedBeanHandle<>("green handle", it);
    Turnout it2 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT3");
    NamedBeanHandle<Turnout> red = new NamedBeanHandle<>("red handle", it2);
    Turnout it3 = (InstanceManager.getDefault(TurnoutManager.class)).provideTurnout("IT2");
    NamedBeanHandle<Turnout> yellow = new NamedBeanHandle<>("yellow handle", it3);
    MergSD2SignalHead t = new MergSD2SignalHead("testsys", "testuser", 3, green, yellow, red, false, false);
    Assert.assertNotNull("exists", t);
}
Also used : Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Test(org.junit.Test)

Example 69 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class MatrixSignalMastTest method testAspects.

@Test
// it11 etc. are indirectly used as NamedBeans IT11 etc.
@SuppressWarnings("unused")
public void testAspects() {
    // provide 3 turnouts:
    Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
    Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
    Turnout it13 = InstanceManager.turnoutManagerInstance().provideTurnout("13");
    MatrixSignalMast m = new MatrixSignalMast("IF$xsm:basic:one-low($0001)-3t", "user");
    m.setBitNum(3);
    m.setOutput("output1", "IT11");
    m.setOutput("output2", "IT12");
    m.setOutput("output3", "IT13");
    // used for test below
    m.setBitstring("Clear", "111");
    m.setBitstring("Approach", "100");
    // used for test below
    m.setBitstring("Stop", "001");
    m.setBitstring("Unlit", "000");
    m.setAllowUnLit(true);
    m.setUnLitBits("000");
    m.setAspectEnabled("Clear");
    m.setAspectEnabled("Approach");
    m.setAspectEnabled("Stop");
    m.setAspectEnabled("Unlit");
    // define some initial aspect before setting any aspect
    m.aspect = "Stop";
    // wait for outputs and outputbits to be set
    //debug
    log.debug(java.util.Arrays.toString(m.getBitsForAspect("Clear")));
    Assert.assertEquals("check bitarray for stop", "[0, 0, 1]", java.util.Arrays.toString(m.getBitsForAspect("Stop")));
    m.setAspect("Clear");
    Assert.assertEquals("check clear", "Clear", m.getAspect());
    Assert.assertEquals("it12 for Clear", Turnout.CLOSED, it12.getCommandedState());
    m.setAspect("Stop");
    Assert.assertEquals("check stop", "Stop", m.getAspect());
    Assert.assertEquals("it12 for Stop", Turnout.THROWN, it12.getCommandedState());
}
Also used : Turnout(jmri.Turnout) Test(org.junit.Test)

Example 70 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class MatrixSignalMastTest method testLit.

@Test
// it11 etc. are indirectly used as NamedBeans IT11 etc.
@SuppressWarnings("unused")
public void testLit() {
    // provide 3 turnouts:
    Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
    Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
    Turnout it13 = InstanceManager.turnoutManagerInstance().provideTurnout("13");
    MatrixSignalMast m = new MatrixSignalMast("IF$xsm:basic:one-low($0001)-3t", "user");
    m.setBitNum(3);
    // Note: "IT" added to name by system
    m.setOutput("output1", "IT11");
    m.setOutput("output2", "IT12");
    m.setOutput("output3", "IT13");
    m.setBitstring("Clear", "111");
    m.setBitstring("Approach", "100");
    m.setBitstring("Stop", "001");
    m.setBitstring("Unlit", "000");
    m.setAllowUnLit(true);
    m.setUnLitBits("000");
    // define some initial aspect before setting any aspect
    m.aspect = "Clear";
    // wait for outputs and outputbits to be set
    Assert.assertTrue(m.getLit());
    m.setLit(false);
    Assert.assertTrue(!m.getLit());
    m.setLit(true);
    Assert.assertTrue(m.getLit());
}
Also used : Turnout(jmri.Turnout) Test(org.junit.Test)

Aggregations

Turnout (jmri.Turnout)221 Test (org.junit.Test)63 Sensor (jmri.Sensor)26 SignalHead (jmri.SignalHead)20 Element (org.jdom2.Element)20 TurnoutManager (jmri.TurnoutManager)17 JmriException (jmri.JmriException)11 Light (jmri.Light)10 SignalMast (jmri.SignalMast)10 ActionEvent (java.awt.event.ActionEvent)9 NamedBeanHandle (jmri.NamedBeanHandle)9 JsonException (jmri.server.json.JsonException)9 ActionListener (java.awt.event.ActionListener)8 Block (jmri.Block)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 NamedBean (jmri.NamedBean)6 Route (jmri.Route)6 AbstractTurnout (jmri.implementation.AbstractTurnout)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5