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));
}
}
});
}
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);
}
}
}
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);
}
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());
}
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());
}
Aggregations