use of jmri.TurnoutManager in project JMRI by JMRI.
the class JsonTurnoutHttpServiceTest method testDoPut.
public void testDoPut() {
ObjectMapper mapper = new ObjectMapper();
JsonTurnoutHttpService service = new JsonTurnoutHttpService(mapper);
TurnoutManager manager = InstanceManager.getDefault(TurnoutManager.class);
JsonNode message;
try {
// add a turnout
Assert.assertNull(manager.getTurnout("IT1"));
message = mapper.createObjectNode().put(JSON.NAME, "IT1").put(JSON.STATE, Turnout.CLOSED);
service.doPut(JsonTurnoutServiceFactory.TURNOUT, "IT1", message, Locale.ENGLISH);
Assert.assertNotNull(manager.getTurnout("IT1"));
} catch (JsonException ex) {
Assert.fail(ex.getMessage());
}
}
use of jmri.TurnoutManager in project JMRI by JMRI.
the class AbstractTurnoutManagerConfigXML method store.
/**
* Default implementation for storing the contents of a TurnoutManager and
* associated TurnoutOperation's
*
* @param o Object to store, of type TurnoutManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element turnouts = new Element("turnouts");
setStoreElementClass(turnouts);
TurnoutManager tm = (TurnoutManager) o;
if (tm != null) {
TurnoutOperationManagerXml tomx = new TurnoutOperationManagerXml();
Element opElem = tomx.store(TurnoutOperationManager.getInstance());
turnouts.addContent(opElem);
java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
// don't return an element if there are not turnouts to include
if (!iter.hasNext()) {
return null;
}
String defaultclosed = tm.getDefaultClosedSpeed();
String defaultthrown = tm.getDefaultThrownSpeed();
turnouts.addContent(new Element("defaultclosedspeed").addContent(defaultclosed));
turnouts.addContent(new Element("defaultthrownspeed").addContent(defaultthrown));
// store the turnouts
while (iter.hasNext()) {
String sname = iter.next();
log.debug("system name is " + sname);
Turnout t = tm.getBySystemName(sname);
Element elem = new Element("turnout");
elem.addContent(new Element("systemName").addContent(sname));
log.debug("store turnout " + sname);
storeCommon(t, elem);
// include feedback info
elem.setAttribute("feedback", t.getFeedbackModeName());
NamedBeanHandle<Sensor> s;
s = t.getFirstNamedSensor();
if (s != null) {
elem.setAttribute("sensor1", s.getName());
}
s = t.getSecondNamedSensor();
if (s != null) {
elem.setAttribute("sensor2", s.getName());
}
// include turnout inverted
elem.setAttribute("inverted", t.getInverted() ? "true" : "false");
if (t.canLock(Turnout.CABLOCKOUT | Turnout.PUSHBUTTONLOCKOUT)) {
// include turnout locked
elem.setAttribute("locked", t.getLocked(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT) ? "true" : "false");
// include turnout lock mode
String lockOpr;
if (t.canLock(Turnout.CABLOCKOUT) && t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
lockOpr = "both";
} else if (t.canLock(Turnout.CABLOCKOUT)) {
lockOpr = "cab";
} else if (t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
lockOpr = "pushbutton";
} else {
lockOpr = "none";
}
elem.setAttribute("lockMode", lockOpr);
// include turnout decoder
elem.setAttribute("decoder", t.getDecoderName());
}
// include number of control bits, if different from one
int iNum = t.getNumberOutputBits();
if (iNum != 1) {
elem.setAttribute("numBits", "" + iNum);
}
// include turnout control type, if different from 0
int iType = t.getControlType();
if (iType != 0) {
elem.setAttribute("controlType", "" + iType);
}
// add operation stuff
String opstr = null;
TurnoutOperation op = t.getTurnoutOperation();
if (t.getInhibitOperation()) {
opstr = "Off";
} else if (op == null) {
opstr = "Default";
} else if (op.isNonce()) {
// nonce operation appears as subelement
TurnoutOperationXml adapter = TurnoutOperationXml.getAdapter(op);
if (adapter != null) {
Element nonceOpElem = adapter.store(op);
elem.addContent(nonceOpElem);
}
} else {
opstr = op.getName();
}
if (opstr != null) {
elem.setAttribute("automate", opstr);
}
if ((t.getDivergingSpeed() != null) && (!t.getDivergingSpeed().equals("")) && !t.getDivergingSpeed().contains("Global")) {
elem.addContent(new Element("divergingSpeed").addContent(t.getDivergingSpeed()));
}
if ((t.getStraightSpeed() != null) && (!t.getStraightSpeed().equals("")) && !t.getStraightSpeed().contains("Global")) {
elem.addContent(new Element("straightSpeed").addContent(t.getStraightSpeed()));
}
// add element
turnouts.addContent(elem);
}
}
return turnouts;
}
use of jmri.TurnoutManager in project JMRI by JMRI.
the class Z21XNetTurnoutManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
lnis = new XNetInterfaceScaffold(new RocoZ21CommandStation());
// create and register the manager object
Z21XNetTurnoutManager l = new Z21XNetTurnoutManager(lnis, "X");
jmri.InstanceManager.setTurnoutManager(l);
// ask for a Turnout, and check type
TurnoutManager t = jmri.InstanceManager.turnoutManagerInstance();
Turnout o = t.newTurnout("XT21", "my name");
if (log.isDebugEnabled()) {
log.debug("received turnout value " + o);
}
Assert.assertTrue(null != (Z21XNetTurnout) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("XT21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("XT21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
use of jmri.TurnoutManager in project JMRI by JMRI.
the class EliteXNetTurnoutManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
lnis = new XNetInterfaceScaffold(new HornbyEliteCommandStation());
// create and register the manager object
EliteXNetTurnoutManager l = new EliteXNetTurnoutManager(lnis, "X");
jmri.InstanceManager.setTurnoutManager(l);
// ask for a Turnout, and check type
TurnoutManager t = jmri.InstanceManager.turnoutManagerInstance();
Turnout o = t.newTurnout("XT21", "my name");
if (log.isDebugEnabled()) {
log.debug("received turnout value " + o);
}
Assert.assertTrue(null != (EliteXNetTurnout) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("XT21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("XT21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
use of jmri.TurnoutManager in project JMRI by JMRI.
the class LnTurnoutManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
// create and register the manager object
LnTurnoutManager l = new LnTurnoutManager(lnis, lnis, "L", false);
jmri.InstanceManager.setTurnoutManager(l);
// ask for a Turnout, and check type
TurnoutManager t = jmri.InstanceManager.turnoutManagerInstance();
Turnout o = t.newTurnout("LT21", "my name");
if (log.isDebugEnabled()) {
log.debug("received turnout value " + o);
}
Assert.assertTrue(null != (LnTurnout) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("LT21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("LT21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
Aggregations