Search in sources :

Example 36 with XNetMessage

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

the class EliteXNetProgrammer method writeCV.

// programming interface
@Override
public synchronized void writeCV(int CV, int val, jmri.ProgListener p) throws jmri.ProgrammerException {
    if (log.isDebugEnabled()) {
        log.debug("writeCV " + CV + " listens " + p);
    }
    useProgrammer(p);
    _progRead = false;
    // set new state & save values
    progState = REQUESTSENT;
    _val = val;
    _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.getWritePagedCVMsg(CV, val);
            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.getWriteDirectCVMsg(CV, val);
            msg.setNeededMode(jmri.jmrix.AbstractMRTrafficController.NORMALMODE);
            msg.setTimeout(ELITEMESSAGETIMEOUT);
            controller().sendXNetMessage(msg, this);
        } else {
            // register mode by elimination
            XNetMessage msg = XNetMessage.getWriteRegisterMsg(registerFromCV(CV), val);
            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)

Example 37 with XNetMessage

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

the class Z21XNetThrottle method sendFunctionGroup3.

/**
     * Send the XpressNet message to set the state of functions F9, F10, F11,
     * F12
     */
@Override
protected void sendFunctionGroup3() {
    // because of the way the z21 wants to see the functions, we
    // send all the functions when there is a change in the group.
    XNetMessage msg = Z21XNetMessage.getZ21LocomotiveFunctionOperationMsg(this.getDccAddress(), 9, f9);
    // now, queue the message for sending to the command station
    queueMessage(msg, THROTTLEFUNCSENT);
    XNetMessage msg1 = Z21XNetMessage.getZ21LocomotiveFunctionOperationMsg(this.getDccAddress(), 10, f10);
    // now, queue the message for sending to the command station
    queueMessage(msg1, THROTTLEFUNCSENT);
    XNetMessage msg2 = Z21XNetMessage.getZ21LocomotiveFunctionOperationMsg(this.getDccAddress(), 11, f11);
    // now, queue the message for sending to the command station
    queueMessage(msg2, THROTTLEFUNCSENT);
    XNetMessage msg3 = Z21XNetMessage.getZ21LocomotiveFunctionOperationMsg(this.getDccAddress(), 12, f12);
    // now, queue the message for sending to the command station
    queueMessage(msg3, THROTTLEFUNCSENT);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 38 with XNetMessage

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

the class Z21XNetTurnout method requestUpdateFromLayout.

/**
     * request an update on status by sending an XPressNet message
     */
@Override
public void requestUpdateFromLayout() {
    // On the z21, we send a LAN_X_GET_TURNOUT_INFO message 
    // (see section 5.1 of the protocol documenation ).
    XNetMessage msg = Z21XNetMessage.getZ21TurnoutInfoRequestMessage(mNumber);
    synchronized (this) {
        internalState = STATUSREQUESTSENT;
    }
    //status is returned via the manager.
    tc.sendXNetMessage(msg, null);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 39 with XNetMessage

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

the class Z21XNetTurnout method forwardCommandChangeToLayout.

// Handle a request to change state by sending an XPressNet command
@Override
protected synchronized void forwardCommandChangeToLayout(int s) {
    if (s != _mClosed && s != _mThrown) {
        log.warn("Turnout " + mNumber + ": state " + s + " not forwarded to layout.");
        return;
    }
    // get the right packet
    XNetMessage msg = Z21XNetMessage.getZ21SetTurnoutRequestMessage(mNumber, (s & _mThrown) != 0, true, // for now always active and not queued.
    false);
    if (getFeedbackMode() == SIGNAL) {
        // Set the timeout to 0, so the off message can
        msg.setTimeout(0);
        // be sent imediately.
        // leave the next line commented out for now.
        // it may be enabled later to allow SIGNAL mode to ignore
        // directed replies, which lets the traffic controller move on
        // to the next message without waiting.
        //msg.setBroadcastReply();
        tc.sendXNetMessage(msg, null);
        sendOffMessage();
    } else {
        tc.sendXNetMessage(msg, this);
        internalState = COMMANDSENT;
    }
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage)

Example 40 with XNetMessage

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

the class Z21XNetMessage method getZ21WriteDirectCVMsg.

public static XNetMessage getZ21WriteDirectCVMsg(int cv, int val) {
    XNetMessage m = new XNetMessage(6);
    m.setNeededMode(jmri.jmrix.AbstractMRTrafficController.PROGRAMINGMODE);
    m.setTimeout(XNetProgrammingTimeout);
    m.setElement(0, Z21Constants.LAN_X_CV_WRITE_XHEADER);
    m.setElement(1, Z21Constants.LAN_X_CV_WRITE_DB0);
    m.setElement(2, (0xff00 & (cv - 1)) >> 8);
    m.setElement(3, (0xff & (cv - 1)));
    m.setElement(4, val);
    // Set the parity bit
    m.setParity();
    return m;
}
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