Search in sources :

Example 11 with CanMessage

use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.

the class CbusCommandStation method setSpeedSteps.

/**
     * Send a CBUS message to change the session speed step mode
     *
     * @param mode the speed step mode
     */
protected void setSpeedSteps(int handle, int mode) {
    log.debug("Set speed step mode " + mode + " for session handle" + handle);
    CanMessage msg = new CanMessage(3, tc.getCanid());
    msg.setOpCode(CbusConstants.CBUS_STMOD);
    msg.setElement(1, handle);
    msg.setElement(2, mode);
    tc.sendCanMessage(msg, this);
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 12 with CanMessage

use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.

the class CanSendPane method createPacket.

/**
     * Create a well-formed message from a String String is expected to be space
     * seperated hex bytes or CbusAddress, e.g.: 12 34 56 +n4e1
     *
     * @return The packet, with contents filled-in
     */
CanMessage createPacket(String s) {
    CanMessage m;
    // Try to convert using CbusAddress class
    CbusAddress a = new CbusAddress(s);
    if (a.check()) {
        m = a.makeMessage(tc.getCanid());
    } else {
        m = new CanMessage(tc.getCanid());
        // check for header
        if (s.charAt(0) == '[') {
            // extended header
            m.setExtended(true);
            int i = s.indexOf(']');
            String h = s.substring(1, i);
            m.setHeader(Integer.parseInt(h, 16));
            s = s.substring(i + 1, s.length());
        } else if (s.charAt(0) == '(') {
            // standard header
            int i = s.indexOf(')');
            String h = s.substring(1, i);
            m.setHeader(Integer.parseInt(h, 16));
            s = s.substring(i + 1, s.length());
        }
        // Try to get hex bytes
        byte[] b = StringUtil.bytesFromHexString(s);
        m.setNumDataElements(b.length);
        // Use &0xff to ensure signed bytes are stored as unsigned ints
        for (int i = 0; i < b.length; i++) {
            m.setElement(i, b[i] & 0xff);
        }
    }
    return m;
}
Also used : CbusAddress(jmri.jmrix.can.cbus.CbusAddress) CanMessage(jmri.jmrix.can.CanMessage)

Example 13 with CanMessage

use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.

the class OpenLcbCanSendPane method createPacket.

/**
     * Create a well-formed message from a String String is expected to be space
     * seperated hex bytes or CbusAddress, e.g.: 12 34 56 +n4e1
     * @param s string of spaced hex byte codes
     * @return The packet, with contents filled-in
     */
CanMessage createPacket(String s) {
    CanMessage m;
    // Try to convert using CbusAddress class to reuse a little code
    CbusAddress a = new CbusAddress(s);
    if (a.check()) {
        m = a.makeMessage(tc.getCanid());
    } else {
        m = new CanMessage(tc.getCanid());
        // check for header
        if (s.charAt(0) == '[') {
            // NOI18N
            // extended header
            m.setExtended(true);
            // NOI18N
            int i = s.indexOf(']');
            String h = s.substring(1, i);
            m.setHeader(Integer.parseInt(h, 16));
            s = s.substring(i + 1, s.length());
        } else if (s.charAt(0) == '(') {
            // NOI18N
            // standard header
            // NOI18N
            int i = s.indexOf(')');
            String h = s.substring(1, i);
            m.setHeader(Integer.parseInt(h, 16));
            s = s.substring(i + 1, s.length());
        }
        // Try to get hex bytes
        byte[] b = StringUtil.bytesFromHexString(s);
        m.setNumDataElements(b.length);
        // Use &0xff to ensure signed bytes are stored as unsigned ints
        for (int i = 0; i < b.length; i++) {
            m.setElement(i, b[i] & 0xff);
        }
    }
    return m;
}
Also used : CbusAddress(jmri.jmrix.can.cbus.CbusAddress) CanMessage(jmri.jmrix.can.CanMessage)

Example 14 with CanMessage

use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.

the class HubPane method startHubThread.

void startHubThread(int port) {
    t = new Thread() {

        @Override
        public void run() {
            hub.start();
        }
    };
    t.setDaemon(true);
    // add forwarder for internal JMRI traffic
    hub.addForwarder(new Hub.Forwarding() {

        @Override
        public void forward(Hub.Memo m) {
            if (m.source == null) {
                // was from this
                return;
            }
            // process and forward m.line;
            GridConnectReply msg = new GridConnectReply();
            byte[] bytes;
            try {
                // GC adapters use ASCII // NOI18N
                bytes = m.line.getBytes("US-ASCII");
            } catch (java.io.UnsupportedEncodingException e) {
                log.error("Cannot proceed with GC input message since US-ASCII not supported");
                return;
            }
            for (int i = 0; i < m.line.length(); i++) {
                msg.setElement(i, bytes[i]);
            }
            workingReply = msg.createReply();
            CanMessage result = new CanMessage(workingReply.getNumDataElements(), workingReply.getHeader());
            for (int i = 0; i < workingReply.getNumDataElements(); i++) {
                result.setElement(i, workingReply.getElement(i));
            }
            result.setExtended(workingReply.isExtended());
            // Send over outbound link
            memo.getTrafficController().sendCanMessage(result, HubPane.this);
            // And send into JMRI
            memo.getTrafficController().distributeOneReply(workingReply, HubPane.this);
        }
    });
    t.start();
    advertise(port);
}
Also used : Hub(org.openlcb.hub.Hub) GridConnectReply(jmri.jmrix.can.adapters.gridconnect.GridConnectReply) CanMessage(jmri.jmrix.can.CanMessage)

Example 15 with CanMessage

use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.

the class HubPane method reply.

@Override
public synchronized void reply(CanReply reply) {
    if (reply != workingReply) {
        GridConnectMessage gm = new GridConnectMessage(new CanMessage(reply));
        if (log.isDebugEnabled()) {
            log.debug("reply " + gm.toString());
        }
        hub.putLine(gm.toString());
    }
}
Also used : GridConnectMessage(jmri.jmrix.can.adapters.gridconnect.GridConnectMessage) CanMessage(jmri.jmrix.can.CanMessage)

Aggregations

CanMessage (jmri.jmrix.can.CanMessage)63 Test (org.junit.Test)4 CanReply (jmri.jmrix.can.CanReply)3 CanListener (jmri.jmrix.can.CanListener)2 CbusAddress (jmri.jmrix.can.cbus.CbusAddress)2 DccLocoAddress (jmri.DccLocoAddress)1 AbstractMRMessage (jmri.jmrix.AbstractMRMessage)1 CanSystemConnectionMemo (jmri.jmrix.can.CanSystemConnectionMemo)1 TestTrafficController (jmri.jmrix.can.TestTrafficController)1 TrafficControllerScaffold (jmri.jmrix.can.TrafficControllerScaffold)1 GridConnectMessage (jmri.jmrix.can.adapters.gridconnect.GridConnectMessage)1 GridConnectReply (jmri.jmrix.can.adapters.gridconnect.GridConnectReply)1 LoaderClient (org.openlcb.LoaderClient)1 OlcbInterface (org.openlcb.OlcbInterface)1 AliasMap (org.openlcb.can.AliasMap)1 CanInterface (org.openlcb.can.CanInterface)1 MessageBuilder (org.openlcb.can.MessageBuilder)1 Hub (org.openlcb.hub.Hub)1