Search in sources :

Example 26 with XNetReply

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

the class LIUSBServerAdapter method startCommThread.

/**
     * Start the Communication port thread.
     */
private void startCommThread() {
    commThread = new Thread(new Runnable() {

        @Override
        public void run() {
            // received to the output pipe. 
            if (log.isDebugEnabled()) {
                log.debug("Communication Adapter Thread Started");
            }
            XNetReply r;
            BufferedReader bufferedin = new BufferedReader(new InputStreamReader(commAdapter.getInputStream(), java.nio.charset.Charset.forName("UTF-8")));
            for (; ; ) {
                try {
                    synchronized (commAdapter) {
                        r = loadChars(bufferedin);
                    }
                } catch (java.io.IOException e) {
                    // continue;
                    // start the process of trying to recover from
                    // a failed connection.
                    commAdapter.recover();
                    // then exit the for loop.
                    break;
                }
                if (log.isDebugEnabled()) {
                    log.debug("Network Adapter Received Reply: " + r.toString());
                }
                writeReply(r);
            }
        }
    });
    commThread.start();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) XNetReply(jmri.jmrix.lenz.XNetReply) IOException(java.io.IOException)

Example 27 with XNetReply

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

the class LIUSBServerAdapter method startBCastThread.

/**
     * Start the Broadcast Port thread.
     */
private void startBCastThread() {
    bcastThread = new Thread(new Runnable() {

        @Override
        public void run() {
            // to the output pipe. 
            if (log.isDebugEnabled()) {
                log.debug("Broadcast Adapter Thread Started");
            }
            XNetReply r;
            BufferedReader bufferedin = new BufferedReader(new InputStreamReader(bcastAdapter.getInputStream(), java.nio.charset.Charset.forName("UTF-8")));
            for (; ; ) {
                try {
                    synchronized (bcastAdapter) {
                        r = loadChars(bufferedin);
                    }
                } catch (java.io.IOException e) {
                    //continue;
                    // start the process of trying to recover from
                    // a failed connection.
                    bcastAdapter.recover();
                    // then exit the for loop.
                    break;
                }
                if (log.isDebugEnabled()) {
                    log.debug("Network Adapter Received Reply: " + r.toString());
                }
                // Anything coming through the 
                r.setUnsolicited();
                // broadcast port is an 
                // unsolicited message.
                writeReply(r);
            }
        }
    });
    bcastThread.start();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) XNetReply(jmri.jmrix.lenz.XNetReply) IOException(java.io.IOException)

Example 28 with XNetReply

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

the class Z21XPressNetTunnel method reply.

// Z21Listener interface methods.
/**
     * Member function that will be invoked by a z21Interface implementation to
     * forward a z21 message from the layout.
     *
     * @param msg The received z21 message. Note that this same object may be
     *            presented to multiple users. It should not be modified here.
     */
@Override
public void reply(Z21Reply msg) {
    // implementation's input stream.
    if (msg.isXPressNetTunnelMessage()) {
        XNetReply reply = msg.getXNetReply();
        log.debug("Z21 Reply {} forwarded to XPressNet implementation as {}", msg, reply);
        for (int i = 0; i < reply.getNumDataElements(); i++) {
            try {
                outpipe.writeByte(reply.getElement(i));
            } catch (java.io.IOException ioe) {
                log.error("Error writing XPressNet Reply to XPressNet input stream.");
            }
        }
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) IOException(java.io.IOException)

Example 29 with XNetReply

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

the class Z21XNetSimulatorAdapter method normalOpsReply.

// Create a "Normal Operations Resumed" message
private XNetReply normalOpsReply() {
    XNetReply r = new XNetReply();
    r.setOpCode(XNetConstants.CS_INFO);
    r.setElement(1, XNetConstants.BC_NORMAL_OPERATIONS);
    // set the parity byte to 0
    r.setElement(2, 0x00);
    r.setParity();
    return r;
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply)

Example 30 with XNetReply

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

the class Z21XNetSimulatorAdapter method everythingOffReply.

// Create a broadcast "Everything Off" reply
private XNetReply everythingOffReply() {
    XNetReply r = new XNetReply();
    r.setOpCode(XNetConstants.CS_INFO);
    r.setElement(1, XNetConstants.BC_EVERYTHING_OFF);
    // set the parity byte to 0
    r.setElement(2, 0x00);
    r.setParity();
    return r;
}
Also used : 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