Search in sources :

Example 11 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class LocoIdPanel method createSetPacket.

/**
     * Create a LocoNet packet to set the LocoNet ID.
     *
     * @param s The desired value as a string in decimal
     * @return The packet, with contents filled-in
     */
LocoNetMessage createSetPacket(String s) {
    // convert to int value
    int data = Integer.parseInt(s);
    // format packet
    LocoNetMessage m = new LocoNetMessage(6);
    m.setElement(0, 0xDF);
    m.setElement(1, 0x40);
    m.setElement(2, 0x1F);
    m.setElement(3, data);
    m.setElement(4, 0x00);
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 12 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class LnMessageClientPollThread method run.

@Override
public void run() {
    try {
        Object[] lnMessages = null;
        while (!Thread.interrupted()) {
            lnMessages = parent.lnMessageBuffer.getMessages(parent.pollTimeout);
            if (lnMessages != null) {
                log.debug("Recieved Message Array Size: " + lnMessages.length);
                for (int lnMessageIndex = 0; lnMessageIndex < lnMessages.length; lnMessageIndex++) {
                    LocoNetMessage message = (LocoNetMessage) lnMessages[lnMessageIndex];
                    parent.message(message);
                }
            }
        }
    } catch (Exception ex) {
        log.warn("Exception: " + ex);
    }
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 13 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class CmdStnConfigPane method writeButtonActionPerformed.

public void writeButtonActionPerformed(java.awt.event.ActionEvent e) {
    LocoNetMessage msg = new LocoNetMessage(14);
    msg.setElement(0, LnConstants.OPC_WR_SL_DATA);
    msg.setElement(1, 0x0E);
    msg.setElement(2, CONFIG_SLOT);
    // load last seen contents into message
    for (int i = 0; i < 10; i++) {
        msg.setElement(3 + i, oldcontent[i]);
    }
    // load contents to message
    for (int i = 0; i <= (MAX_OPTION - MIN_OPTION); i++) {
        // i indexes over closed buttons
        // byteIndex = 0 is the first payload byte
        int byteIndex = i / 8;
        if (byteIndex > 3) {
            // Skip the 4th payload byte for some reason
            byteIndex++;
        }
        // Add base offset into slot message to first data byte
        byteIndex += 3;
        int bitIndex = i % 8;
        int bitMask = 0x01 << bitIndex;
        if (closedButtons[i].isSelected()) {
            msg.setElement(byteIndex, msg.getElement(byteIndex) | bitMask);
        } else {
            msg.setElement(byteIndex, msg.getElement(byteIndex) & ~bitMask);
        }
    }
    // send message
    memo.getLnTrafficController().sendLocoNetMessage(msg);
    return;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 14 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class CmdStnConfigPane method start.

/**
     *
     * Start the Frame operating by asking for a read
     */
public void start() {
    // format and send request for slot contents
    LocoNetMessage l = new LocoNetMessage(4);
    l.setElement(0, LnConstants.OPC_RQ_SL_DATA);
    l.setElement(1, CONFIG_SLOT);
    l.setElement(2, 0);
    l.setElement(3, 0);
    memo.getLnTrafficController().sendLocoNetMessage(l);
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 15 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class DuplexGroupScanPanel method createDuplexScanQueryPacket.

/**
     * Creates a LocoNet message containing a channel-specific query for signal
     * information from UR92 device(s).
     * <p>
     * @param channelNum - integer between 11 and 26, inclusive
     * @return LocoNetMessage - query for Dulpex Channel Scan information
     */
private LocoNetMessage createDuplexScanQueryPacket(int channelNum) {
    int i = 0;
    LocoNetMessage m = new LocoNetMessage(LnConstants.RE_DPLX_OP_LEN);
    m.setElement(i++, LnConstants.OPC_PEER_XFER);
    // 20-byte message
    m.setElement(i++, LnConstants.RE_DPLX_OP_LEN);
    // Duplex Group Scan Query type
    m.setElement(i++, LnConstants.RE_DPLX_SCAN_QUERY_B2);
    // Query Operation
    m.setElement(i++, LnConstants.RE_DPLX_SCAN_QUERY_B3);
    m.setElement(i++, LnConstants.RE_DPLX_SCAN_QUERY_B4);
    // Duplex Channel Number
    m.setElement(i++, channelNum);
    for (; i < (LnConstants.RE_DPLX_OP_LEN - 1); i++) {
        // always 0 for duplex group ID write
        m.setElement(i, 0);
    }
    // LocoNet send process will compute and add checksum byte in correct location
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Aggregations

LocoNetMessage (jmri.jmrix.loconet.LocoNetMessage)103 Test (org.junit.Test)8 JFrame (javax.swing.JFrame)3 LocoNetInterfaceScaffold (jmri.jmrix.loconet.LocoNetInterfaceScaffold)3 LocoNetSystemConnectionMemo (jmri.jmrix.loconet.LocoNetSystemConnectionMemo)3 LocoStatsPanel (jmri.jmrix.loconet.locostats.swing.LocoStatsPanel)3 JmriJFrame (jmri.util.JmriJFrame)3 LocoNetSlot (jmri.jmrix.loconet.LocoNetSlot)2 SpjFile (jmri.jmrix.loconet.spjfile.SpjFile)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StringTokenizer (java.util.StringTokenizer)1 LnPacketizer (jmri.jmrix.loconet.LnPacketizer)1 LnReporter (jmri.jmrix.loconet.LnReporter)1 LnTrafficController (jmri.jmrix.loconet.LnTrafficController)1 LnTurnout (jmri.jmrix.loconet.LnTurnout)1