Search in sources :

Example 16 with CanMessage

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

the class OlcbConfigurationManager method createOlcbCanInterface.

public static CanInterface createOlcbCanInterface(NodeID nodeID, TrafficController tc) {
    final CanInterface olcbIf = new CanInterface(nodeID, frame -> tc.sendCanMessage(convertToCan(frame), null));
    tc.addCanListener(new CanListener() {

        @Override
        public void message(CanMessage m) {
        // ignored -- loopback is handled by the olcbInterface.
        }

        @Override
        public void reply(CanReply m) {
            if (!m.isExtended() || m.isRtr()) {
                return;
            }
            olcbIf.frameInput().send(convertFromCan(m));
        }
    });
    return olcbIf;
}
Also used : CanInterface(org.openlcb.can.CanInterface) CanListener(jmri.jmrix.can.CanListener) CanReply(jmri.jmrix.can.CanReply) CanMessage(jmri.jmrix.can.CanMessage)

Example 17 with CanMessage

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

the class OpenLcbCanSendPane method sendNextItem.

/**
     * Send next item; may be used for the first item or when a delay has
     * elapsed.
     */
void sendNextItem() {
    // check if still running
    if (!mRunButton.isSelected()) {
        return;
    }
    // have we run off the end?
    if (mNextSequenceElement >= MAXSEQUENCE) {
        // past the end, go back
        mNextSequenceElement = 0;
    }
    // is this one enabled?
    if (mUseField[mNextSequenceElement].isSelected()) {
        // make the packet
        CanMessage m = createPacket(mPacketField[mNextSequenceElement].getText());
        // send it
        tc.sendCanMessage(m, this);
        startSequenceDelay();
    } else {
        // ask for the next one
        mNextSequenceElement++;
        sendNextItem();
    }
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 18 with CanMessage

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

the class CbusConsolePane method sendEvButtonActionPerformed.

public void sendEvButtonActionPerformed(java.awt.event.ActionEvent e) {
    int nn, ev;
    CanMessage m = new CanMessage(tc.getCanid());
    nn = parseBinDecHexByte(nnField.getText(), 65535, _decimal, "CBUS Console", "Invalid Node Number");
    if (nn == -1) {
        return;
    }
    ev = parseBinDecHexByte(evField.getText(), 65535, _decimal, "CBUS Console", "Invalid Event");
    if (ev == -1) {
        return;
    }
    CbusMessage.setPri(m, CbusConstants.DEFAULT_DYNAMIC_PRIORITY * 4 + CbusConstants.DEFAULT_MINOR_PRIORITY);
    if (onButton.isSelected()) {
        if (nn > 0) {
            m.setElement(0, CbusConstants.CBUS_ACON);
        } else {
            m.setElement(0, CbusConstants.CBUS_ASON);
        }
    } else {
        if (nn > 0) {
            m.setElement(0, CbusConstants.CBUS_ACOF);
        } else {
            m.setElement(0, CbusConstants.CBUS_ASOF);
        }
    }
    m.setElement(1, nn >> 8);
    m.setElement(2, nn & 0xff);
    m.setElement(3, ev >> 8);
    m.setElement(4, ev & 0xff);
    m.setNumDataElements(5);
    // Messages sent by us will not be forwarded back so add to display manually
    message(m);
    tc.sendCanMessage(m, this);
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 19 with CanMessage

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

the class CbusConsolePane method sendButtonActionPerformed.

public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    int j;
    int data, data2;
    CanMessage m = new CanMessage(tc.getCanid());
    data = parseBinDecHexByte(dynPriField.getText(), 2, _decimal, "CBUS Console", "Invalid Dynamic Priority Value");
    if (data == -1) {
        return;
    }
    data2 = parseBinDecHexByte(minPriField.getText(), 3, _decimal, "CBUS Console", "Invalid Minor Priority Value");
    if (data2 == -1) {
        return;
    }
    m.setHeader(data * 4 + data2);
    for (j = 0; j < 8; j++) {
        if (!dataFields[j].getText().equals("")) {
            data = parseBinDecHexByte(dataFields[j].getText(), 255, _decimal, "CBUS Console", "Invalid Data Value in d" + j);
            if (data == -1) {
                return;
            }
            m.setElement(j, data);
            if (j == 0) {
                data2 = data;
            }
        // save OPC(d0) for later
        } else {
            break;
        }
    }
    if (j == 0) {
        JOptionPane.showMessageDialog(null, "You must enter at least an opcode", "CBUS Console", JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Subtract one as loop variable will have incremented
    if ((j - 1) != (data2 >> 5)) {
        JOptionPane.showMessageDialog(null, "Number of data bytes entered\n" + "does not match count in d0(OPC):" + (data2 >> 5), "CBUS Console", JOptionPane.ERROR_MESSAGE);
        return;
    }
    m.setNumDataElements(j);
    // Messages sent by us will not be forwarded back so add to display manually
    message(m);
    tc.sendCanMessage(m, this);
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 20 with CanMessage

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

the class CbusSensor method setKnownState.

/**
     * User request to set the state, which means that we broadcast that to all
     * listeners by putting it out on CBUS. In turn, the code in this class
     * should use setOwnState to handle internal sets and bean notifies.
     *
     */
@Override
public void setKnownState(int s) throws jmri.JmriException {
    CanMessage m;
    if (s == Sensor.ACTIVE) {
        m = addrActive.makeMessage(tc.getCanid());
        tc.sendCanMessage(m, this);
        setOwnState(Sensor.ACTIVE);
    } else if (s == Sensor.INACTIVE) {
        m = addrInactive.makeMessage(tc.getCanid());
        tc.sendCanMessage(m, this);
        setOwnState(Sensor.INACTIVE);
    }
}
Also used : 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