Search in sources :

Example 31 with XNetMessage

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

the class Z21XNetSimulatorAdapterTest method testGenerateEmergencyStopLocoReply.

@Test
public void testGenerateEmergencyStopLocoReply() {
    Z21XNetSimulatorAdapter a = new Z21XNetSimulatorAdapter();
    Assert.assertEquals("CS Emergeny Stop Specific Loco (XNetV4)", new XNetReply("01 04 05"), a.generateReply(new XNetMessage("92 00 02 90")));
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 32 with XNetMessage

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

the class XNetSimulatorAdapterTest method testGenerateCSVersionReply.

@Test
public void testGenerateCSVersionReply() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("21 21 00"));
        Assert.assertEquals("CS Version Reply", new XNetReply("63 21 36 00 74"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 33 with XNetMessage

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

the class XNetSimulatorAdapterTest method testEmergencyStopLocoReplyV1V2.

@Test
public void testEmergencyStopLocoReplyV1V2() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("91 02 93"));
        Assert.assertEquals("CS Emergency Specific Loco (XNetV1,V2) Reply ", new XNetReply("01 04 05"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 34 with XNetMessage

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

the class XNetSimulatorAdapterTest method testEmergencyStopAllReply.

@Test
public void testEmergencyStopAllReply() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("80 80"));
        Assert.assertEquals("CS Emergency Stop All Reply ", new XNetReply("81 00 81"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 35 with XNetMessage

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

the class EliteXNetProgrammer method readCV.

@Override
public synchronized void readCV(int CV, jmri.ProgListener p) throws jmri.ProgrammerException {
    if (log.isDebugEnabled()) {
        log.debug("readCV " + CV + " listens " + p);
    }
    if (!getCanRead()) {
        // should not invoke this if cant read, but if done anyway set NotImplemented error
        p.programmingOpReply(CV, jmri.ProgListener.NotImplemented);
        return;
    }
    useProgrammer(p);
    _progRead = true;
    // set new state
    progState = REQUESTSENT;
    _cv = 0xffff & CV;
    try {
        // start the error timer
        restartTimer(EliteXNetProgrammerTimeout);
        // format and send message to go to program mode
        if (getMode().equals(DefaultProgrammerManager.PAGEMODE)) {
            XNetMessage msg = XNetMessage.getReadPagedCVMsg(CV);
            msg.setNeededMode(jmri.jmrix.AbstractMRTrafficController.NORMALMODE);
            msg.setTimeout(ELITEMESSAGETIMEOUT);
            controller().sendXNetMessage(msg, this);
        } else if (getMode().equals(DefaultProgrammerManager.DIRECTBITMODE) || getMode().equals(DefaultProgrammerManager.DIRECTBYTEMODE)) {
            XNetMessage msg = XNetMessage.getReadDirectCVMsg(CV);
            msg.setNeededMode(jmri.jmrix.AbstractMRTrafficController.NORMALMODE);
            msg.setTimeout(ELITEMESSAGETIMEOUT);
            controller().sendXNetMessage(msg, this);
        } else {
            // register mode by elimination
            XNetMessage msg = XNetMessage.getReadRegisterMsg(registerFromCV(CV));
            msg.setNeededMode(jmri.jmrix.AbstractMRTrafficController.NORMALMODE);
            msg.setTimeout(ELITEMESSAGETIMEOUT);
            controller().sendXNetMessage(msg, this);
        }
    } catch (jmri.ProgrammerException e) {
        progState = NOTPROGRAMMING;
        throw e;
    }
    // On the Elite, we're not getting a broadcast message
    // saying we're in service mode, so go ahead and request
    // the results.
    progState = INQUIRESENT;
    //start the error timer
    restartTimer(EliteXNetProgrammerTimeout);
    XNetMessage resultMsg = XNetMessage.getServiceModeResultsMsg();
    resultMsg.setNeededMode(jmri.jmrix.AbstractMRTrafficController.NORMALMODE);
    resultMsg.setTimeout(ELITEMESSAGETIMEOUT);
    controller().sendXNetMessage(resultMsg, this);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Aggregations

XNetMessage (jmri.jmrix.lenz.XNetMessage)55 XNetReply (jmri.jmrix.lenz.XNetReply)14 Test (org.junit.Test)14 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 IOException (java.io.IOException)1 XNetListenerScaffold (jmri.jmrix.lenz.XNetListenerScaffold)1 Z21Reply (jmri.jmrix.roco.z21.Z21Reply)1