Search in sources :

Example 36 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetProgrammerTest method testWriteHighCvSequence.

// this test is the same as the testWriteCvSequence test, but
// it checks the sequence for CVs greater than 256, which use 
// different XPressNet commands.
@Override
public void testWriteHighCvSequence() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation());
    jmri.ProgListenerScaffold l = new jmri.ProgListenerScaffold();
    Z21XNetProgrammer p = new Z21XNetProgrammer(t) {

        @Override
        protected synchronized void restartTimer(int delay) {
            super.restartTimer(RESTART_TIME);
        }
    };
    // and do the write
    p.writeCV(300, 34, l);
    // check "prog mode" message sent
    Assert.assertEquals("mode message sent", 1, t.outbound.size());
    Assert.assertEquals("write message contents", "24 12 01 2B 22 3E", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x64);
    mr1.setElement(1, 0x14);
    mr1.setElement(2, 0x01);
    mr1.setElement(3, 0x2B);
    mr1.setElement(4, 0x22);
    mr1.setElement(5, 0x78);
    t.sendTestMessage(mr1);
    // At this point, the z21XPressNetProgrammer 
    // should send a result to the programmer listeners, and 
    // wait for either the next read/write request or for the 
    // traffic controller to exit from service mode.  We just
    // need to wait a few seconds and see that the listener we
    // registered earlier received the values we expected.
    jmri.util.JUnitUtil.waitFor(() -> {
        return l.getRcvdInvoked() != 0;
    }, "Receive Called by Programmer");
    Assert.assertEquals("Direct mode received value", 34, l.getRcvdValue());
}
Also used : XNetInterfaceScaffold(jmri.jmrix.lenz.XNetInterfaceScaffold) LenzCommandStation(jmri.jmrix.lenz.LenzCommandStation) XNetReply(jmri.jmrix.lenz.XNetReply)

Example 37 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetProgrammerTest method testReadCvSequence.

@Override
public void testReadCvSequence() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation());
    jmri.ProgListenerScaffold l = new jmri.ProgListenerScaffold();
    Z21XNetProgrammer p = new Z21XNetProgrammer(t) {

        @Override
        protected synchronized void restartTimer(int delay) {
            super.restartTimer(RESTART_TIME);
        }
    };
    // and do the read
    p.readCV(29, l);
    // check "prog mode" message sent
    Assert.assertEquals("mode message sent", 1, t.outbound.size());
    Assert.assertEquals("read message contents", "23 11 00 1C 2E", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x64);
    mr1.setElement(1, 0x14);
    mr1.setElement(2, 0x00);
    mr1.setElement(3, 0x1C);
    mr1.setElement(4, 0x22);
    mr1.setElement(5, 0x4E);
    t.sendTestMessage(mr1);
    // At this point, the z21XPressNetProgrammer 
    // should send a result to the programmer listeners, and 
    // wait for either the next read/write request or for the 
    // traffic controller to exit from service mode.  We just
    // need to wait a few seconds and see that the listener we
    // registered earlier received the values we expected.
    jmri.util.JUnitUtil.waitFor(() -> {
        return l.getRcvdInvoked() != 0;
    }, "Receive Called by Programmer");
    Assert.assertEquals("Direct mode received value", 34, l.getRcvdValue());
}
Also used : XNetInterfaceScaffold(jmri.jmrix.lenz.XNetInterfaceScaffold) LenzCommandStation(jmri.jmrix.lenz.LenzCommandStation) XNetReply(jmri.jmrix.lenz.XNetReply)

Example 38 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetProgrammerTest method testReadCvHighSequence.

// this test is the same as the testReadCvSequence test, but
// it checks the sequence for CVs greater than 256, which use 
// different XPressNet commands.
@Override
public void testReadCvHighSequence() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation());
    jmri.ProgListenerScaffold l = new jmri.ProgListenerScaffold();
    Z21XNetProgrammer p = new Z21XNetProgrammer(t) {

        @Override
        protected synchronized void restartTimer(int delay) {
            super.restartTimer(RESTART_TIME);
        }
    };
    // and do the read
    p.readCV(300, l);
    // check "prog mode" message sent
    Assert.assertEquals("mode message sent", 1, t.outbound.size());
    Assert.assertEquals("read message contents", "23 11 01 2B 18", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x64);
    mr1.setElement(1, 0x14);
    mr1.setElement(2, 0x01);
    mr1.setElement(3, 0x2B);
    mr1.setElement(4, 0x22);
    mr1.setElement(5, 0x78);
    t.sendTestMessage(mr1);
    // At this point, the z21XPressNetProgrammer 
    // should send a result to the programmer listeners, and 
    // wait for either the next read/write request or for the 
    // traffic controller to exit from service mode.  We just
    // need to wait a few seconds and see that the listener we
    // registered earlier received the values we expected.
    jmri.util.JUnitUtil.waitFor(() -> {
        return l.getRcvdInvoked() != 0;
    }, "Receive Called by Programmer");
    Assert.assertEquals("Direct mode received value", 34, l.getRcvdValue());
}
Also used : XNetInterfaceScaffold(jmri.jmrix.lenz.XNetInterfaceScaffold) LenzCommandStation(jmri.jmrix.lenz.LenzCommandStation) XNetReply(jmri.jmrix.lenz.XNetReply)

Example 39 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetTurnoutTest method testXNetTurnoutMsgSequence.

// Test the Z21XNetTurnout message sequence.
@Test
@Override
public void testXNetTurnoutMsgSequence() {
    t.setFeedbackMode(jmri.Turnout.DIRECT);
    // set closed
    try {
        t.setCommandedState(jmri.Turnout.CLOSED);
    } catch (Exception e) {
        log.error("TO exception: " + e);
    }
    Assert.assertTrue(t.getCommandedState() == jmri.Turnout.CLOSED);
    Assert.assertEquals("on message sent", "53 00 15 88 CE", lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
    // notify that the command station received the reply
    XNetReply m = new XNetReply();
    m.setElement(0, 0x43);
    m.setElement(1, 0x00);
    m.setElement(2, 0x15);
    // set CLOSED
    m.setElement(3, 0x00);
    m.setElement(4, 0x56);
    int n = lnis.outbound.size();
    ((jmri.jmrix.roco.z21.Z21XNetTurnout) t).message(m);
    while (n == lnis.outbound.size()) {
    }
    // busy loop.  Wait for 
    // outbound size to change.
    Assert.assertEquals("off message sent", "53 00 15 80 C6", lnis.outbound.elementAt(n).toString());
    // the turnout will not set its state until it sees a reply message.
    m = new XNetReply();
    m.setElement(0, 0x43);
    m.setElement(1, 0x00);
    m.setElement(2, 0x15);
    m.setElement(3, 0x00);
    m.setElement(4, 0x56);
    ((jmri.jmrix.roco.z21.Z21XNetTurnout) t).message(m);
    // no wait here.  The last reply should cause the turnout to 
    // set it's state, but it will not cause another reply.
    Assert.assertTrue(t.getKnownState() == jmri.Turnout.CLOSED);
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) Test(org.junit.Test)

Example 40 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetSimulatorAdapterTest method testGenerateResumeOperationsReply.

@Test
public void testGenerateResumeOperationsReply() {
    Z21XNetSimulatorAdapter a = new Z21XNetSimulatorAdapter();
    Assert.assertEquals("CS Resume Operations Reply", new XNetReply("61 82 E3"), a.generateReply(new XNetMessage("21 81 A0")));
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Aggregations

XNetReply (jmri.jmrix.lenz.XNetReply)57 XNetInterfaceScaffold (jmri.jmrix.lenz.XNetInterfaceScaffold)18 Test (org.junit.Test)17 XNetMessage (jmri.jmrix.lenz.XNetMessage)14 LenzCommandStation (jmri.jmrix.lenz.LenzCommandStation)10 IOException (java.io.IOException)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Z21Reply (jmri.jmrix.roco.z21.Z21Reply)1