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;
}
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();
}
}
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);
}
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);
}
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);
}
}
Aggregations