Search in sources :

Example 56 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createUr92GroupNameReportPacket.

// the following code may be used to create a LocoNet message that follows the
// form of the message sent by a UR92 in response to a Duplex Group Name query
// LocoNet message.
public static final LocoNetMessage createUr92GroupNameReportPacket(String dupName, String dupPass, int dupChan, int dupId) {
    // format packet
    LocoNetMessage m = new LocoNetMessage(LnConstants.RE_DPLX_OP_LEN);
    int i = 0;
    dupName += "        ";
    // get first 8 chars of space-padded name
    dupName = dupName.substring(0, 8);
    m.setElement(i++, LnConstants.OPC_PEER_XFER);
    // 20-byte message
    m.setElement(i++, LnConstants.RE_DPLX_OP_LEN);
    // Group Name Operation
    m.setElement(i++, LnConstants.RE_DPLX_GP_NAME_TYPE);
    // Report Operation
    m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_REPORT);
    m.setElement(i++, (((dupName.charAt(0) & 0x80) == 0x80) ? 1 : 0) + (((dupName.charAt(1) & 0x80) == 0x80) ? 2 : 0) + (((dupName.charAt(2) & 0x80) == 0x80) ? 4 : 0) + (((dupName.charAt(3) & 0x80) == 0x80) ? 8 : 0));
    m.setElement(i++, dupName.charAt(0) & 0x7f);
    m.setElement(i++, dupName.charAt(1) & 0x7f);
    m.setElement(i++, dupName.charAt(2) & 0x7f);
    m.setElement(i++, dupName.charAt(3) & 0x7f);
    m.setElement(i++, (((dupName.charAt(4) & 0x80) == 0x80) ? 1 : 0) + (((dupName.charAt(5) & 0x80) == 0x80) ? 2 : 0) + (((dupName.charAt(6) & 0x80) == 0x80) ? 4 : 0) + (((dupName.charAt(7) & 0x80) == 0x80) ? 8 : 0));
    m.setElement(i++, dupName.charAt(4) & 0x7f);
    m.setElement(i++, dupName.charAt(5) & 0x7f);
    m.setElement(i++, dupName.charAt(6) & 0x7f);
    m.setElement(i++, dupName.charAt(7) & 0x7f);
    // NOI18N
    dupPass += "0000";
    dupPass = dupPass.substring(0, 4);
    int gr_p1 = dupPass.charAt(0);
    int gr_p2 = dupPass.charAt(1);
    int gr_p3 = dupPass.charAt(2);
    int gr_p4 = dupPass.charAt(3);
    // re-code individual characters when an alphabetic character is used
    gr_p1 -= (gr_p1 > '9') ? ('A' - '9' - 1) : 0;
    gr_p2 -= (gr_p2 > '9') ? ('A' - '9' - 1) : 0;
    gr_p3 -= (gr_p3 > '9') ? ('A' - '9' - 1) : 0;
    gr_p4 -= (gr_p4 > '9') ? ('A' - '9' - 1) : 0;
    int passLo = ((gr_p1 & 0x0f) << 4) + (gr_p2 & 0x0f);
    int passHi = ((gr_p3 & 0x0f) << 4) + (gr_p4 & 0x0f);
    m.setElement(i++, (((passLo & 0x80) == 0x80) ? 1 : 0) + (((passHi & 0x80) == 0x80) ? 2 : 0) + (((dupChan & 0x80) == 0x80) ? 4 : 0) + (((dupId & 0x80) == 0x80) ? 8 : 0));
    m.setElement(i++, passLo & 0x7f);
    m.setElement(i++, passHi & 0x7f);
    m.setElement(i++, dupChan & 0x7f);
    m.setElement(i++, dupId & 0x7f);
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 57 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createUr92GroupChannelReportPacket.

// the following code may be used to create a LocoNet message that follows the
// form of the message sent by a UR92 in response to a Duplex Group Channel query
// LocoNet message.
public static final LocoNetMessage createUr92GroupChannelReportPacket(int dupChan) {
    // format packet
    LocoNetMessage m = new LocoNetMessage(LnConstants.RE_DPLX_OP_LEN);
    int i = 0;
    m.setElement(i++, LnConstants.OPC_PEER_XFER);
    // 20-byte message
    m.setElement(i++, LnConstants.RE_DPLX_OP_LEN);
    // Group Channel Operation
    m.setElement(i++, LnConstants.RE_DPLX_GP_CHAN_TYPE);
    // Report Operation
    m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_REPORT);
    m.setElement(i++, (dupChan & 0x80) >> 7);
    m.setElement(i++, dupChan & 0x7f);
    for (; i < LnConstants.RE_DPLX_OP_LEN; i++) {
        m.setElement(i, 0);
    }
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 58 with LocoNetMessage

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

the class LoaderPane method sendOne.

void sendOne(int pxct2, int d1, int d2, int d3, int d4, int d5, int d6, int d7, int d8) {
    LocoNetMessage m = new LocoNetMessage(16);
    m.setOpCode(LnConstants.OPC_PEER_XFER);
    m.setElement(1, 0x10);
    m.setElement(2, 0x7F);
    m.setElement(3, 0x7F);
    m.setElement(4, 0x7F);
    int d1u = (d1 & 0x80) / 0x80;
    int d2u = (d2 & 0x80) / 0x40;
    int d3u = (d3 & 0x80) / 0x20;
    int d4u = (d4 & 0x80) / 0x10;
    int lowbits = d1u | d2u | d3u | d4u;
    // PXCT1
    m.setElement(5, (lowbits | PXCT1DOWNLOAD) & 0x7F);
    // D1
    m.setElement(6, d1 & 0x7F);
    // D2
    m.setElement(7, d2 & 0x7F);
    // D3
    m.setElement(8, d3 & 0x7F);
    // D4
    m.setElement(9, d4 & 0x7F);
    int d5u = (d5 & 0x80) / 0x80;
    int d6u = (d6 & 0x80) / 0x40;
    int d7u = (d7 & 0x80) / 0x20;
    int d8u = (d8 & 0x80) / 0x10;
    lowbits = d5u | d6u | d7u | d8u;
    // PXCT2
    m.setElement(10, (lowbits | pxct2) & 0x7F);
    // D5
    m.setElement(11, d5 & 0x7F);
    // D6
    m.setElement(12, d6 & 0x7F);
    // D7
    m.setElement(13, d7 & 0x7F);
    // D8
    m.setElement(14, d8 & 0x7F);
    memo.getLnTrafficController().sendLocoNetMessage(m);
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 59 with LocoNetMessage

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

the class LoaderEngine method getEraseMessage.

/**
     * Get a message to erase the non-volatile sound memory
     */
LocoNetMessage getEraseMessage() {
    LocoNetMessage m = new LocoNetMessage(new int[] { 0xD3, 0x02, 0x01, 0x7F, 0x00, 0x50 });
    m.setParity();
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 60 with LocoNetMessage

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

the class LoaderEngine method getSendDataMessage.

/**
     * Get a message to tell the PR2 to store length bytes of data (following)
     *
     * @param handle   Handle number for the following data
     * @param contents Data to download
     */
LocoNetMessage getSendDataMessage(int type, int handle, byte[] contents) {
    int length = contents.length;
    LocoNetMessage m = new LocoNetMessage(length + 7);
    m.setElement(0, 0xD3);
    m.setElement(1, type | CMD_ADD);
    m.setElement(2, handle);
    m.setElement(3, length & 0x7F);
    m.setElement(4, (length / 128));
    // 1st checksum
    m.setElement(5, 0x00);
    for (int i = 0; i < length; i++) {
        m.setElement(6 + i, contents[i]);
    }
    m.setParity();
    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