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);
}
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class CbusMessage method getBootInitialise.
/**
* Microchip AN247 format message to initialise the bootloader and set the
* start address
*/
public static CanMessage getBootInitialise(int a, int header) {
CanMessage m = new CanMessage(8, header);
m.setExtended(true);
m.setHeader(0x4);
m.setElement(0, (a / 65536) & 0xFF);
m.setElement(1, (a / 256) & 0xFF);
m.setElement(2, a & 0xFF);
m.setElement(3, 0);
m.setElement(4, 0x0D);
m.setElement(5, 2);
m.setElement(6, 0);
m.setElement(7, 0);
setPri(m, 0xb);
return m;
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class CbusMessage method getBootWriteData.
/**
* Microchip AN247 format message to write 8 bytes of data
*/
public static CanMessage getBootWriteData(int[] d, int header) {
CanMessage m = new CanMessage(8, header);
m.setExtended(true);
m.setHeader(0x5);
try {
m.setElement(0, d[0] & 0xff);
m.setElement(1, d[1] & 0xff);
m.setElement(2, d[2] & 0xff);
m.setElement(3, d[3] & 0xff);
m.setElement(4, d[4] & 0xff);
m.setElement(5, d[5] & 0xff);
m.setElement(6, d[6] & 0xff);
m.setElement(7, d[7] & 0xff);
} catch (Exception e) {
log.error("Exception in bootloader data" + e);
}
setPri(m, 0xb);
return m;
}
Aggregations