Skip to content
Permalink
Browse files

CBUS turnout feedback / sensor tst

  • Loading branch information...
icklesteve committed Jan 24, 2019
1 parent 75c510e commit fada924fb5b10ef48a49c15e79961e591ce62cf5
Showing with 75 additions and 1 deletion.
  1. +75 −1 java/test/jmri/jmrix/can/cbus/CbusTurnoutTest.java
@@ -3,6 +3,7 @@

import jmri.jmrix.can.CanMessage;
import jmri.jmrix.can.CanReply;
import jmri.jmrix.can.CanSystemConnectionMemo;
import jmri.jmrix.can.TrafficControllerScaffold;
import jmri.Turnout;
import jmri.util.JUnitUtil;
@@ -65,6 +66,33 @@ public void testRequestUpdate() {

}

@Test
public void testRequestUpdateSensors() {

CanSystemConnectionMemo memo = new CanSystemConnectionMemo();
memo.setTrafficController(tcis);
jmri.InstanceManager.setDefault(jmri.SensorManager.class,new CbusSensorManager(memo));

t.requestUpdateFromLayout();
Assert.assertEquals(1,tcis.outbound.size());
tcis.outbound.clear();

try {
t.provideFirstFeedbackSensor("MS+54321");
} catch (jmri.JmriException ex) { }
t.setFeedbackMode("ONESENSOR");
t.requestUpdateFromLayout();
Assert.assertEquals(2,tcis.outbound.size());
tcis.outbound.clear();

try {
t.provideSecondFeedbackSensor("MS+4545");
} catch (jmri.JmriException ex) { }
t.setFeedbackMode("TWOSENSOR");
t.requestUpdateFromLayout();
Assert.assertEquals(3,tcis.outbound.size());
}

@Test
public void testNullEvent() {
try {
@@ -323,7 +351,6 @@ public void testTurnoutCanReply() throws jmri.JmriException {
Assert.assertTrue(t.getCommandedState() == Turnout.CLOSED);
}


// with presence of node number should still resolve to short event turnout due to opc
@Test
public void testTurnoutCanMessageShortEvWithNode() throws jmri.JmriException {
@@ -372,6 +399,53 @@ public void testTurnoutCanReplyShortEvWithNode() throws jmri.JmriException {

}

@Test
public void testDelayedTurnoutCanMessage() throws jmri.JmriException {
CbusTurnout t = new CbusTurnout("MT","+N54321E12345",tcis);
CanMessage m = new CanMessage(tcis.getCanid());
m.setNumDataElements(5);
m.setElement(0, 0x90); // ACON OPC
m.setElement(1, 0xd4);
m.setElement(2, 0x31);
m.setElement(3, 0x30);
m.setElement(4, 0x39);

CbusTurnout.DELAYED_FEEDBACK_INTERVAL=1;
t.setFeedbackMode("DELAYED");
t.message(m);
Assert.assertTrue(t.getKnownState() == Turnout.INCONSISTENT);
JUnitUtil.waitFor(()->{ return(t.getKnownState() == Turnout.THROWN); }, "msg Turnout.THROWN didn't arrive");

m.setElement(0, 0x91); // ACOF OPC
t.message(m);
Assert.assertTrue(t.getKnownState() == Turnout.INCONSISTENT);
JUnitUtil.waitFor(()->{ return(t.getKnownState() == Turnout.CLOSED); }, "msg Turnout.CLOSED didn't arrive");
}


@Test
public void testDelayedTurnoutCanReply() throws jmri.JmriException {
CbusTurnout t = new CbusTurnout("MT","+N54321E12345",tcis);
CanReply m = new CanReply(tcis.getCanid());
m.setNumDataElements(5);
m.setElement(0, 0x90); // ACON OPC
m.setElement(1, 0xd4);
m.setElement(2, 0x31);
m.setElement(3, 0x30);
m.setElement(4, 0x39);

CbusTurnout.DELAYED_FEEDBACK_INTERVAL=1;
t.setFeedbackMode("DELAYED");
t.reply(m);
Assert.assertTrue(t.getKnownState() == Turnout.INCONSISTENT);
JUnitUtil.waitFor(()->{ return(t.getKnownState() == Turnout.THROWN); }, "reply Turnout.THROWN didn't arrive");

m.setElement(0, 0x91); // ACOF OPC
t.reply(m);
Assert.assertTrue(t.getKnownState() == Turnout.INCONSISTENT);
JUnitUtil.waitFor(()->{ return(t.getKnownState() == Turnout.CLOSED); }, "reply Turnout.CLOSED didn't arrive");
}

// The minimal setup for log4J
@Before
public void setUp() {

0 comments on commit fada924

Please sign in to comment.
You can’t perform that action at this time.