Search in sources :

Example 1 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createSetUr92GroupIDPacket.

/**
     * Create a LocoNet packet to set the Duplex group ID number.
     * <p>
     * If s provides anything other than a numeric value between 0 and 127, a
     * bogus LocoNet message is returned.
     * <p>
     * @param s The desired group ID number as a string
     * @return The packet which writes the Group ID Number to the UR92 device(s)
     */
public static final LocoNetMessage createSetUr92GroupIDPacket(String s) throws jmri.jmrix.loconet.LocoNetException {
    int gr_id = Integer.parseInt(s, 10);
    if ((gr_id >= LnDplxGrpInfoImplConstants.DPLX_MIN_ID) && (gr_id <= LnDplxGrpInfoImplConstants.DPLX_MAX_ID)) {
        // format packet
        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);
        // Group ID Operation
        m.setElement(i++, LnConstants.RE_DPLX_GP_ID_TYPE);
        // Write Operation
        m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_WRITE);
        // always 0 for duplex group ID write
        m.setElement(i++, 0);
        // Group ID Number
        m.setElement(i++, gr_id);
        for (; i < (LnConstants.RE_DPLX_OP_LEN - 1); i++) {
            // always 0 for duplex group ID write
            m.setElement(i, 0);
        }
        // Note: LocoNet send process will compute and add checksum byte in correct location
        return m;
    } else {
        // NOI18N
        throw new jmri.jmrix.loconet.LocoNetException("Illegal Duplex Group ID number");
    }
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 2 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createUr92GroupIdReportPacket.

// 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 Id query
// LocoNet message.
public static final LocoNetMessage createUr92GroupIdReportPacket(int dupId) {
    // 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 Id Operation
    m.setElement(i++, LnConstants.RE_DPLX_GP_ID_TYPE);
    // Report Operation
    m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_REPORT);
    m.setElement(i++, (dupId & 0x80) >> 7);
    m.setElement(i++, dupId & 0x7f);
    for (; i < LnConstants.RE_DPLX_OP_LEN; i++) {
        m.setElement(i, 0);
    }
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 3 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createUr92GroupIdentityQueryPacket.

/**
     * Creates a LocoNet packet which queries UR92(s) for Duplex group
     * identification information. The invoking method is responsible for
     * sending the message to LocoNet.
     *
     * @return LocoNetMessage containing IPL query of UR92s
     */
public static final LocoNetMessage createUr92GroupIdentityQueryPacket() {
    // format packet
    LocoNetMessage m = new LocoNetMessage(LnConstants.RE_DPLX_OP_LEN);
    Integer i;
    i = 0;
    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);
    // Query Operation
    m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_QUERY);
    for (; i < (LnConstants.RE_DPLX_OP_LEN - 1); i++) {
        // always 0 for duplex group name write
        m.setElement(i, 0);
    }
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 4 with LocoNetMessage

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

the class LnDplxGrpInfoImpl method createSetUr92GroupPasswordPacket.

/**
     * Create a LocoNet packet to set the Duplex group password.
     * <p>
     * If s provides anything other than a 4 character length group password
     * which uses only valid group ID characters (0-9, A-C), a bogus
     * LocoNet message is returned.
     * <p>
     * @param sGroupPassword The desired group password as a string
     * @return The packet which writes the Group Password to the UR92 device(s)
     * @throws jmri.jmrix.loconet.LocoNetException in case of invalid sGrooupPassword
     */
public static final LocoNetMessage createSetUr92GroupPasswordPacket(String sGroupPassword) throws jmri.jmrix.loconet.LocoNetException {
    int gr_p1 = sGroupPassword.toUpperCase().charAt(0);
    int gr_p2 = sGroupPassword.toUpperCase().charAt(1);
    int gr_p3 = sGroupPassword.toUpperCase().charAt(2);
    int gr_p4 = sGroupPassword.toUpperCase().charAt(3);
    int i;
    if (validateGroupPassword(sGroupPassword) == false) {
        if (getLimitPasswordToNumericOnly() == true) {
            // NOI18N
            throw new jmri.jmrix.loconet.LocoNetException("Invalid Duplex Group Password - must be a 4 digit number between 0000 and 9999, inclusive");
        } else {
            // NOI18N
            throw new jmri.jmrix.loconet.LocoNetException("Invalid Duplex Group Password - must be a 4 character value using only digits, 'A', 'B', and/or 'C'");
        }
    }
    // 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;
    // format packet
    LocoNetMessage m = new LocoNetMessage(LnConstants.RE_DPLX_OP_LEN);
    i = 0;
    m.setElement(i++, LnConstants.OPC_PEER_XFER);
    // 20-byte message
    m.setElement(i++, LnConstants.RE_DPLX_OP_LEN);
    // Group password Operation
    m.setElement(i++, LnConstants.RE_DPLX_GP_PW_TYPE);
    // Write Operation
    m.setElement(i++, LnConstants.RE_DPLX_OP_TYPE_WRITE);
    // always 0 for duplex group password write
    m.setElement(i++, 0);
    // Group password leftmost value + 0x30
    m.setElement(i++, gr_p1);
    // Group password next value + 0x30
    m.setElement(i++, gr_p2);
    // Group password next value + 0x30
    m.setElement(i++, gr_p3);
    // Group password rightmost value + 0x30
    m.setElement(i++, gr_p4);
    for (; i < (LnConstants.RE_DPLX_OP_LEN - 1); i++) {
        // always 0 for duplex group password write
        m.setElement(i, 0);
    }
    return m;
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 5 with LocoNetMessage

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

the class LnIPLImplementation method createIplSpecificHostQueryPacket.

/**
     * Creates a LocoNet packet which queries IPL devices by specific host
     * manufacturer and specific host device type. The invoking method is
     * responsible for sending the message to LocoNet.
     * <p>
     * Note: Different devices may only respond to IPL Identity requests if the
     * host manufacturer and host type are defined. Others devices will respond
     * when host manufacturer and host type are left as zero.
     * <p>
     * @param hostMfr    defines the host manufacturer number
     * @param hostDevice defines the host device type number
     * @return a LocoNetMessage containing the packet required to request IPL
     *         identity information from devices of the specified host
     *         manufacturer and host device type.
     */
public static final LocoNetMessage createIplSpecificHostQueryPacket(Integer hostMfr, Integer hostDevice) {
    LocoNetMessage m = createQueryAllIplDevicesPacket();
    m.setElement(4, hostMfr);
    m.setElement(5, hostDevice);
    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