Search in sources :

Example 41 with XNetMessage

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

the class Z21XNetMessage method getZ21LocomotiveFunctionOperationMsg.

/*
     * Given a locomotive address, a function number, and it's value, 
     * generate a message to change the state. 
     * @param address is the locomotive address
     * @param functionno is the function to change
     * @param newstate is boolean representing whether the function is to be on or off.
     */
public static XNetMessage getZ21LocomotiveFunctionOperationMsg(int address, int functionno, boolean state) {
    XNetMessage msg = new XNetMessage(6);
    int functionbyte = functionno;
    msg.setElement(0, XNetConstants.LOCO_OPER_REQ);
    msg.setElement(1, Z21Constants.LAN_X_SET_LOCO_FUNCTION);
    msg.setElement(2, jmri.jmrix.lenz.LenzCommandStation.getDCCAddressHigh(address));
    msg.setElement(3, jmri.jmrix.lenz.LenzCommandStation.getDCCAddressLow(address));
    if (state) {
        //This function is on
        // clear the 2 most significant bits.
        functionbyte = functionbyte & 0x3F;
        // set the 2 msb to 01.
        functionbyte = functionbyte | 0x40;
    } else {
        //This function is off.
        // clear the 2 most significant bits.
        functionbyte = functionbyte & 0x3F;
    }
    msg.setElement(4, functionbyte);
    msg.setParity();
    return (msg);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 42 with XNetMessage

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

the class Z21XNetMessage method getZ21SetTurnoutRequestMessage.

/*
     * Given a turnout address and whether or not it is thrown, generate 
     * a message to operate the turnout. 
     * @param address is the turnout address
     * @param thrown boolean value representing whether the turnout is thrown.
     * @param active boolean value representing whether the output is being set
     * to active.
     * @param queue boolean value representing whehter or not the message is 
     * added to the queue.
     */
public static XNetMessage getZ21SetTurnoutRequestMessage(int address, boolean thrown, boolean active, boolean queue) {
    // refer to section 5.2 of the z21 lan protocol manual.
    XNetMessage msg = new XNetMessage(5);
    msg.setElement(0, Z21Constants.LAN_X_SET_TURNOUT);
    msg.setElement(1, (address & 0xff00) >> 8);
    msg.setElement(2, (address & 0x00ff));
    int element3 = 0x80;
    if (active) {
        element3 |= 0x08;
    }
    if (thrown) {
        element3 |= 0x01;
    }
    if (queue) {
        element3 |= 0x20;
    }
    msg.setElement(3, element3);
    msg.setParity();
    return (msg);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 43 with XNetMessage

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

the class Z21XNetMessage method getZ21LocomotiveInfoRequestMsg.

/*
     * Given a locomotive address, request its status 
     * @param address is the locomotive address
     */
public static XNetMessage getZ21LocomotiveInfoRequestMsg(int address) {
    XNetMessage msg = new XNetMessage(5);
    msg.setElement(0, XNetConstants.LOCO_STATUS_REQ);
    msg.setElement(1, Z21Constants.LAN_X_LOCO_INFO_REQUEST_Z21);
    msg.setElement(2, jmri.jmrix.lenz.LenzCommandStation.getDCCAddressHigh(address));
    msg.setElement(3, jmri.jmrix.lenz.LenzCommandStation.getDCCAddressLow(address));
    msg.setParity();
    return (msg);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 44 with XNetMessage

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

the class Z21XNetMessage method getZ21ReadDirectCVMsg.

// create messages of a particular form
public static XNetMessage getZ21ReadDirectCVMsg(int cv) {
    XNetMessage m = new XNetMessage(5);
    m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
    m.setTimeout(XNetProgrammingTimeout);
    m.setElement(0, Z21Constants.LAN_X_CV_READ_XHEADER);
    m.setElement(1, Z21Constants.LAN_X_CV_READ_DB0);
    m.setElement(2, ((0xff00 & (cv - 1)) >> 8));
    m.setElement(3, (0xff & (cv - 1)));
    // Set the parity bit
    m.setParity();
    return m;
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 45 with XNetMessage

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

the class Z21XNetMessage method getZ21TurnoutInfoRequestMessage.

/*
     * Given a turnout address, generate a message to request the state. 
     * @param address is the turnout address
     */
public static XNetMessage getZ21TurnoutInfoRequestMessage(int address) {
    // refer to section 5.1 of the z21 lan protocol manual.
    XNetMessage msg = new XNetMessage(4);
    msg.setElement(0, Z21Constants.LAN_X_GET_TURNOUT_INFO);
    msg.setElement(1, (address & 0xff00) >> 8);
    msg.setElement(2, (address & 0x00ff));
    msg.setParity();
    return (msg);
}
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