Search in sources :

Example 1 with XNetReply

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

the class LI100XNetProgrammerTest method testReadCvSequence.

public void testReadCvSequence() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation());
    jmri.ProgListenerScaffold l = new jmri.ProgListenerScaffold();
    LI100XNetProgrammer p = new LI100XNetProgrammer(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", "22 15 1D 2A", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x61);
    mr1.setElement(1, 0x02);
    mr1.setElement(2, 0x63);
    t.sendTestMessage(mr1);
    Assert.assertEquals("inquire message sent", 2, t.outbound.size());
    Assert.assertEquals("inquire message contents", "21 10 31", t.outbound.elementAt(1).toString());
    // send a result string
    XNetReply mr2 = new XNetReply();
    mr2.setElement(0, 0x63);
    mr2.setElement(1, 0x14);
    mr2.setElement(2, 0x1D);
    mr2.setElement(3, 0x22);
    mr2.setElement(4, 0x48);
    t.sendTestMessage(mr2);
    // At this point, the LI100 XPressNet programmer
    // deviates from the standard XPressNet programmer.  
    // the LI100 version requests an exit from service 
    // before sending a result to the registered listeners.
    Assert.assertEquals("mode message sent", 3, t.outbound.size());
    Assert.assertEquals("exit service mode message contents", "21 81 A0", t.outbound.elementAt(2).toString());
    // send reply stating service mode has exited       
    XNetReply mr3 = new XNetReply();
    mr3.setElement(0, 0x61);
    mr3.setElement(1, 0x01);
    mr3.setElement(2, 0x60);
    t.sendTestMessage(mr3);
    jmri.util.JUnitUtil.releaseThread(this);
    //failure in this test occurs with the next line.
    Assert.assertFalse("Receive Called by Programmer", l.getRcvdInvoked() == 0);
    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 2 with XNetReply

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

the class EliteXNetProgrammerTest method testReadRegisterSequenceString.

public void testReadRegisterSequenceString() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new HornbyEliteCommandStation());
    EliteXNetListenerScaffold l = new EliteXNetListenerScaffold();
    EliteXNetProgrammer p = new EliteXNetProgrammer(t);
    // set register mode
    p.setMode(DefaultProgrammerManager.REGISTERMODE);
    // and do the read
    p.readCV("29", l);
    // check "prog mode" message sent
    Assert.assertEquals("mode message sent", 2, t.outbound.size());
    Assert.assertEquals("read message contents", "22 11 05 36", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x61);
    mr1.setElement(1, 0x02);
    mr1.setElement(2, 0x63);
    t.sendTestMessage(mr1);
    Assert.assertEquals("enquire message sent", 2, t.outbound.size());
    Assert.assertEquals("enquire message contents", "21 10 31", t.outbound.elementAt(1).toString());
}
Also used : XNetInterfaceScaffold(jmri.jmrix.lenz.XNetInterfaceScaffold) XNetReply(jmri.jmrix.lenz.XNetReply)

Example 3 with XNetReply

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

the class EliteXNetTurnoutTest method testXNetTurnoutMsgSequence.

// Test the XNetTurnout message sequence.
@Test
@Override
@Ignore("causes a hang, probably incorrect sequence in test")
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", "52 05 8A DD", lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
    // notify that the command station received the reply
    XNetReply m = new XNetReply();
    m.setElement(0, 0x42);
    m.setElement(1, 0x05);
    // set CLOSED
    m.setElement(2, 0x04);
    m.setElement(3, 0x43);
    int n = lnis.outbound.size();
    ((jmri.jmrix.lenz.XNetTurnout) t).message(m);
    while (n == lnis.outbound.size()) {
    }
    // busy loop.  Wait for
    // outbound size to change.
    Assert.assertEquals("off message sent", "52 05 80 D7", lnis.outbound.elementAt(n).toString());
    // the turnout will not set its state until it sees an OK message.
    m = new XNetReply();
    m.setElement(0, 0x01);
    m.setElement(1, 0x04);
    m.setElement(2, 0x05);
    n = lnis.outbound.size();
    ((jmri.jmrix.lenz.XNetTurnout) t).message(m);
    while (n == lnis.outbound.size()) {
    }
    // busy loop.  Wait for
    // outbound size to change.
    Assert.assertEquals("off message sent", "52 05 80 D7", lnis.outbound.elementAt(n).toString());
    m = new XNetReply();
    m.setElement(0, 0x01);
    m.setElement(1, 0x04);
    m.setElement(2, 0x05);
    ((jmri.jmrix.lenz.XNetTurnout) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with XNetReply

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

the class LI100XNetProgrammerTest method testReadHighCvSequence.

// this test is the same as the testReadCvSequence test, but
// it checks the sequence for CVs greater than 256, which use
// different XPressNet commands.
public void testReadHighCvSequence() throws JmriException {
    // infrastructure objects
    XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation());
    jmri.ProgListenerScaffold l = new jmri.ProgListenerScaffold();
    LI100XNetProgrammer p = new LI100XNetProgrammer(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", "22 19 2C 17", t.outbound.elementAt(0).toString());
    // send reply
    XNetReply mr1 = new XNetReply();
    mr1.setElement(0, 0x61);
    mr1.setElement(1, 0x02);
    mr1.setElement(2, 0x63);
    t.sendTestMessage(mr1);
    Assert.assertEquals("inquire message sent", 2, t.outbound.size());
    Assert.assertEquals("inquire message contents", "21 10 31", t.outbound.elementAt(1).toString());
    // send a result string
    XNetReply mr2 = new XNetReply();
    mr2.setElement(0, 0x63);
    mr2.setElement(1, 0x15);
    mr2.setElement(2, 0x2C);
    mr2.setElement(3, 0x22);
    mr2.setElement(4, 0x78);
    t.sendTestMessage(mr2);
    // At this point, the LI100 XPressNet programmer
    // deviates from the standard XPressNet programmer.  
    // the LI100 version requests an exit from service 
    // before sending a result to the registered listeners.
    Assert.assertEquals("mode message sent", 3, t.outbound.size());
    Assert.assertEquals("exit service mode message contents", "21 81 A0", t.outbound.elementAt(2).toString());
    // send reply stating service mode has exited       
    XNetReply mr3 = new XNetReply();
    mr3.setElement(0, 0x61);
    mr3.setElement(1, 0x01);
    mr3.setElement(2, 0x60);
    t.sendTestMessage(mr3);
    jmri.util.JUnitUtil.releaseThread(this);
    //failure in this test occurs with the next line.
    Assert.assertFalse("Receive Called by Programmer", l.getRcvdInvoked() == 0);
    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 5 with XNetReply

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

the class Z21XNetProgrammerTest method testWriteCvSequence.

@Override
public void testWriteCvSequence() 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(29, 34, l);
    // check "prog mode" message sent
    Assert.assertEquals("mode message sent", 1, t.outbound.size());
    Assert.assertEquals("write message contents", "24 12 00 1C 22 08", 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)

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