use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.
the class LoaderEngine method getInitMessage.
/**
* Get a message to initialize the load sequence
*/
LocoNetMessage getInitMessage() {
LocoNetMessage m = new LocoNetMessage(new int[] { 0xD3, 0x01, 0x00, 0x00, 0x00, 0x2D });
m.setParity();
return m;
}
use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.
the class LoaderEngine method sendSDF.
void sendSDF() throws DelayException {
notify(res.getString("EngineSendSdf"));
// get control info, data
SpjFile.Header header = spjFile.findSdfHeader();
int handle = header.getHandle();
String name = header.getName();
byte[] contents = header.getByteArray();
// transfer
LocoNetMessage m;
m = initTransfer(TYPE_SDF, handle, name, contents);
controller.sendLocoNetMessage(m);
throttleOutbound(m);
while ((m = nextTransfer()) != null) {
controller.sendLocoNetMessage(m);
throttleOutbound(m);
}
}
use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.
the class SlotMonDataModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
int status = 0;
if (col == ESTOPCOLUMN) {
log.debug("Start estop in slot " + row);
// check for in use
LocoNetSlot s = memo.getSlotManager().slot(slotNum(row));
if (s == null) {
log.error("slot pointer was null for slot row: " + row + " col: " + col);
return;
}
if ((s.consistStatus() == LnConstants.CONSIST_SUB) || (s.consistStatus() == LnConstants.CONSIST_MID)) {
Object[] options = { "OK", "Cancel" };
int result = JOptionPane.showOptionDialog(null, "E-Stopping a consist MID or SUB will mess up the consist.\n\nAre you sure you want to do that?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
if (result == 1) {
return;
}
}
LocoNetMessage msg = new LocoNetMessage(4);
msg.setOpCode(LnConstants.OPC_LOCO_SPD);
msg.setElement(1, s.getSlot());
// 1 here is estop
msg.setElement(2, 1);
memo.getLnTrafficController().sendLocoNetMessage(msg);
fireTableRowsUpdated(row, row);
} else if ((col == F0COLUMN) || (col == F1COLUMN) || (col == F2COLUMN) || (col == F3COLUMN) || (col == F4COLUMN)) {
log.debug("F0-F4 change requested " + row);
LocoNetSlot s = memo.getSlotManager().slot(slotNum(row));
if (s == null) {
log.error("slot pointer was null for slot row: " + row + " col: " + col);
return;
}
boolean tempF0 = (col == F0COLUMN) ? !s.isF0() : s.isF0();
boolean tempF1 = (col == F1COLUMN) ? !s.isF1() : s.isF1();
boolean tempF2 = (col == F2COLUMN) ? !s.isF2() : s.isF2();
boolean tempF3 = (col == F3COLUMN) ? !s.isF3() : s.isF3();
boolean tempF4 = (col == F4COLUMN) ? !s.isF4() : s.isF4();
int new_dirf = ((s.isForward() ? 0 : LnConstants.DIRF_DIR) | (tempF0 ? LnConstants.DIRF_F0 : 0) | (tempF1 ? LnConstants.DIRF_F1 : 0) | (tempF2 ? LnConstants.DIRF_F2 : 0) | (tempF3 ? LnConstants.DIRF_F3 : 0) | (tempF4 ? LnConstants.DIRF_F4 : 0));
// set status to 'In Use' if other
status = s.slotStatus();
if (status != LnConstants.LOCO_IN_USE) {
memo.getLnTrafficController().sendLocoNetMessage(s.writeStatus(LnConstants.LOCO_IN_USE));
}
LocoNetMessage msg = new LocoNetMessage(4);
msg.setOpCode(LnConstants.OPC_LOCO_DIRF);
msg.setElement(1, s.getSlot());
// 1 here is estop
msg.setElement(2, new_dirf);
memo.getLnTrafficController().sendLocoNetMessage(msg);
// Delay here allows command station time to xmit on the rails.
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
log.error(null, ex);
}
// reset status to original value if not previously 'in use'
if (status != LnConstants.LOCO_IN_USE) {
memo.getLnTrafficController().sendLocoNetMessage(s.writeStatus(status));
}
fireTableRowsUpdated(row, row);
} else if ((col == F5COLUMN) || (col == F6COLUMN) || (col == F7COLUMN) || (col == F8COLUMN)) {
log.debug("F5-F8 change requested " + row);
LocoNetSlot s = memo.getSlotManager().slot(slotNum(row));
if (s == null) {
log.error("slot pointer was null for slot row: " + row + " col: " + col);
return;
}
boolean tempF5 = (col == F5COLUMN) ? !s.isF5() : s.isF5();
boolean tempF6 = (col == F6COLUMN) ? !s.isF6() : s.isF6();
boolean tempF7 = (col == F7COLUMN) ? !s.isF7() : s.isF7();
boolean tempF8 = (col == F8COLUMN) ? !s.isF8() : s.isF8();
int new_snd = ((tempF8 ? LnConstants.SND_F8 : 0) | (tempF7 ? LnConstants.SND_F7 : 0) | (tempF6 ? LnConstants.SND_F6 : 0) | (tempF5 ? LnConstants.SND_F5 : 0));
// set status to 'In Use' if other
status = s.slotStatus();
if (status != LnConstants.LOCO_IN_USE) {
memo.getLnTrafficController().sendLocoNetMessage(s.writeStatus(LnConstants.LOCO_IN_USE));
}
LocoNetMessage msg = new LocoNetMessage(4);
msg.setOpCode(LnConstants.OPC_LOCO_SND);
msg.setElement(1, s.getSlot());
// 1 here is estop
msg.setElement(2, new_snd);
memo.getLnTrafficController().sendLocoNetMessage(msg);
// Delay here allows command station time to xmit on the rails.
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
log.error(null, ex);
}
// reset status to original value if not previously 'in use'
if (status != LnConstants.LOCO_IN_USE) {
memo.getLnTrafficController().sendLocoNetMessage(s.writeStatus(status));
}
fireTableRowsUpdated(row, row);
} else if (col == DISPCOLUMN) {
log.debug("Start freeing slot " + row);
// check for in use
LocoNetSlot s = memo.getSlotManager().slot(slotNum(row));
if (s == null) {
log.error("slot pointer was null for slot row: " + row + " col: " + col);
return;
}
if (s.slotStatus() != LnConstants.LOCO_FREE) {
if (s.consistStatus() != LnConstants.CONSIST_NO) {
// Freeing a member takes it out of the consist
// entirely (i.e., while the slot is LOCO_FREE, it
// still reads the former consist information, but
// the next time that loco is selected, it comes
// back as CONSIST_NO). Freeing the CONSIST_TOP
// will kill the entire consist.
Object[] options = { "OK", "Cancel" };
int result = JOptionPane.showOptionDialog(null, "Freeing a consist member will destroy the consist.\n\nAre you sure you want to do that?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
if (result == 1) {
return;
}
}
// send status to free
memo.getLnTrafficController().sendLocoNetMessage(s.writeStatus(LnConstants.LOCO_FREE));
} else {
log.debug("Slot not in use");
}
fireTableRowsUpdated(row, row);
}
}
use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.
the class LoaderEngine method getStartDataMessage.
/**
* Get a message to start the download of data
*
* @param handle Handle number for the following data
* @param length Total length of the WAV data to load
*/
LocoNetMessage getStartDataMessage(int type, int handle, int length) {
int pagecount = length / SENDPAGESIZE;
int remainder = length - pagecount * SENDPAGESIZE;
if (remainder != 0) {
pagecount++;
}
if (log.isDebugEnabled()) {
log.debug("getStartDataMessage: " + type + "," + handle + "," + length + ";" + pagecount + "," + remainder);
}
LocoNetMessage m = new LocoNetMessage(new int[] { 0xD3, (type | CMD_START), handle, pagecount & 0x7F, (pagecount / 128), 0 });
m.setParity();
return m;
}
use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.
the class SlotMonDataModel method estopAll.
/**
* This is a convenience method that makes it easier for classes using this
* model to set all in-use slots to emergency stop
*/
public void estopAll() {
for (int slotNum = 0; slotNum < 120; slotNum++) {
LocoNetSlot s = memo.getSlotManager().slot(slotNum);
if (s.slotStatus() != LnConstants.LOCO_FREE && (s.consistStatus() == LnConstants.CONSIST_NO || s.consistStatus() == LnConstants.CONSIST_TOP) && s.speed() != 1) {
// send message to estop this loco
LocoNetMessage msg = new LocoNetMessage(4);
msg.setOpCode(LnConstants.OPC_LOCO_SPD);
msg.setElement(1, s.getSlot());
// emergency stop
msg.setElement(2, 1);
memo.getLnTrafficController().sendLocoNetMessage(msg);
}
}
}
Aggregations