Search in sources :

Example 1 with SerialMessage

use of jmri.jmrix.cmri.serial.SerialMessage in project JMRI by JMRI.

the class DiagnosticFrame method runOutputTest.

/**
     * Local Method to run an Output Test
     */
@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION")
protected // though it would be good to fix it if you're working in this area
void runOutputTest() {
    // Set up timer to update output pattern periodically
    outTimer = new Timer(obsDelay, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evnt) {
            if (testRunning && outTest) {
                short[] outBitPattern = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
                String[] portID = { "A", "B", "C", "D" };
                // set new pattern
                outBytes[curOutByte] = (byte) outBitPattern[curOutBit];
                // send new pattern
                SerialMessage m = createOutPacket();
                m.setTimeout(50);
                _memo.getTrafficController().sendSerialMessage(m, curFrame);
                // update status panel to show bit that is on
                statusText1.setText("Port " + portID[curOutByte - begOutByte] + " Bit " + Integer.toString(curOutBit) + " is on - Compare LED's with the pattern below");
                statusText1.setVisible(true);
                StringBuilder st = new StringBuilder();
                for (int i = begOutByte; i <= endOutByte; i++) {
                    st.append("  ");
                    for (int j = 0; j < 8; j++) {
                        if ((i == curOutByte) && (j == curOutBit)) {
                            st.append("X ");
                        } else {
                            st.append("O ");
                        }
                    }
                }
                statusText2.setText(new String(st));
                statusText2.setVisible(true);
                // update bit pattern for next entry
                curOutBit++;
                if (curOutBit > 7) {
                    // Move to the next byte
                    curOutBit = 0;
                    outBytes[curOutByte] = 0;
                    curOutByte++;
                    if (curOutByte > endOutByte) {
                        // Pattern complete, recycle to first byte
                        curOutByte = begOutByte;
                        numIterations++;
                    }
                }
            }
        }
    });
    // start timer        
    outTimer.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) SerialMessage(jmri.jmrix.cmri.serial.SerialMessage) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with SerialMessage

use of jmri.jmrix.cmri.serial.SerialMessage in project JMRI by JMRI.

the class DiagnosticFrame method createOutPacket.

/**
     * Local Method to create an Transmit packet (SerialMessage)
     */
SerialMessage createOutPacket() {
    // Count the number of DLE's to be inserted
    int nDLE = 0;
    for (int i = 0; i < nOutBytes; i++) {
        if ((outBytes[i] == 2) || (outBytes[i] == 3) || (outBytes[i] == 16)) {
            nDLE++;
        }
    }
    // Create a Serial message and add initial bytes
    SerialMessage m = new SerialMessage(nOutBytes + nDLE + 2);
    // node address
    m.setElement(0, ua + 65);
    // 'T'
    m.setElement(1, 84);
    // Add output bytes
    int k = 2;
    for (int i = 0; i < nOutBytes; i++) {
        // perform C/MRI required DLE processing
        if ((outBytes[i] == 2) || (outBytes[i] == 3) || (outBytes[i] == 16)) {
            // DLE
            m.setElement(k, 16);
            k++;
        }
        // add output byte
        m.setElement(k, outBytes[i]);
        k++;
    }
    return m;
}
Also used : SerialMessage(jmri.jmrix.cmri.serial.SerialMessage)

Example 3 with SerialMessage

use of jmri.jmrix.cmri.serial.SerialMessage in project JMRI by JMRI.

the class SerialPacketGenFrame method createPacket.

SerialMessage createPacket(String s) {
    // gather bytes in result
    byte[] b = StringUtil.bytesFromHexString(s);
    if (b.length == 0) {
        // no such thing as a zero-length message
        return null;
    }
    SerialMessage m = new SerialMessage(b.length);
    for (int i = 0; i < b.length; i++) {
        m.setElement(i, b[i]);
    }
    return m;
}
Also used : SerialMessage(jmri.jmrix.cmri.serial.SerialMessage)

Example 4 with SerialMessage

use of jmri.jmrix.cmri.serial.SerialMessage in project JMRI by JMRI.

the class SerialPacketGenFrame method pollButtonActionPerformed.

public void pollButtonActionPerformed(java.awt.event.ActionEvent e) {
    SerialMessage msg = SerialMessage.getPoll(Integer.valueOf(uaAddrField.getText()).intValue());
    _memo.getTrafficController().sendSerialMessage(msg, this);
}
Also used : SerialMessage(jmri.jmrix.cmri.serial.SerialMessage)

Example 5 with SerialMessage

use of jmri.jmrix.cmri.serial.SerialMessage in project JMRI by JMRI.

the class DiagnosticFrame method runWraparoundTest.

/**
     * Local Method to run a Wraparound Test
     */
@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION")
protected // though it would be good to fix it if you're working in this area
void runWraparoundTest() {
    // Display Status Message
    statusText1.setText("Running Wraparound Test");
    statusText1.setVisible(true);
    // Set up timer to update output pattern periodically
    wrapTimer = new Timer(100, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evnt) {
            if (testRunning && !testSuspended) {
                if (waitingOnInput) {
                    count--;
                    if (count == 0) {
                        statusText2.setText("Time Out Error - no response after 5 seconds.");
                        statusText2.setVisible(true);
                    }
                } else {
                    // compare input with previous output if needed
                    if (needInputTest) {
                        needInputTest = false;
                        boolean comparisonError = false;
                        // compare input and output bytes
                        int j = 0;
                        for (int i = begInByte; i <= endInByte; i++, j++) {
                            if (inBytes[i] != wrapBytes[j]) {
                                comparisonError = true;
                            }
                        }
                        if (comparisonError) {
                            // report error and suspend test
                            statusText1.setText("Test Suspended for Error - Stop or Continue?");
                            statusText1.setVisible(true);
                            StringBuilder st = new StringBuilder("Compare Error - Out Bytes (hex):");
                            for (int i = begOutByte; i <= endOutByte; i++) {
                                st.append(" ");
                                st.append(Integer.toHexString((outBytes[i]) & 0x000000ff));
                            }
                            st.append("    In Bytes (hex):");
                            for (int i = begInByte; i <= endInByte; i++) {
                                st.append(" ");
                                st.append(Integer.toHexString((inBytes[i]) & 0x000000ff));
                            }
                            statusText2.setText(new String(st));
                            statusText2.setVisible(true);
                            numErrors++;
                            testSuspended = true;
                            return;
                        }
                    }
                    // send next output pattern
                    outBytes[curOutByte] = (byte) curOutValue;
                    if (isSMINI) {
                        // If SMINI, send same pattern to both output cards
                        if (curOutByte > 2) {
                            outBytes[curOutByte - 3] = (byte) curOutValue;
                        } else {
                            outBytes[curOutByte + 3] = (byte) curOutValue;
                        }
                    }
                    SerialMessage m = createOutPacket();
                    // wait for signal to settle down if filter delay
                    m.setTimeout(50 + filterDelay);
                    _memo.getTrafficController().sendSerialMessage(m, curFrame);
                    // update Status area
                    short[] outBitPattern = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
                    String[] portID = { "A", "B", "C", "D" };
                    StringBuilder st = new StringBuilder("Port: ");
                    st.append(portID[curOutByte - begOutByte]);
                    st.append(",  Pattern: ");
                    for (int j = 0; j < 8; j++) {
                        if ((curOutValue & outBitPattern[j]) != 0) {
                            st.append("X ");
                        } else {
                            st.append("O ");
                        }
                    }
                    statusText2.setText(new String(st));
                    statusText2.setVisible(true);
                    // set up for testing input returned
                    int k = 0;
                    for (int i = begOutByte; i <= endOutByte; i++, k++) {
                        wrapBytes[k] = outBytes[i];
                    }
                    waitingOnInput = true;
                    needInputTest = true;
                    count = 50;
                    // send poll
                    _memo.getTrafficController().sendSerialMessage(SerialMessage.getPoll(ua), curFrame);
                    // update output pattern for next entry
                    curOutValue++;
                    if (curOutValue > 255) {
                        // Move to the next byte
                        curOutValue = 0;
                        outBytes[curOutByte] = 0;
                        if (isSMINI) {
                            // If SMINI, clear ports of both output cards
                            if (curOutByte > 2) {
                                outBytes[curOutByte - 3] = 0;
                            } else {
                                outBytes[curOutByte + 3] = 0;
                            }
                        }
                        curOutByte++;
                        if (curOutByte > endOutByte) {
                            // Pattern complete, recycle to first port (byte)
                            curOutByte = begOutByte;
                            numIterations++;
                        }
                    }
                }
            }
        }
    });
    // start timer        
    wrapTimer.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) SerialMessage(jmri.jmrix.cmri.serial.SerialMessage) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SerialMessage (jmri.jmrix.cmri.serial.SerialMessage)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Timer (javax.swing.Timer)2