use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialTrafficController method pollMessage.
/**
* Handles initialization, output and polling for Oak Tree from within the
* running thread
*/
@Override
protected synchronized AbstractMRMessage pollMessage() {
// ensure validity of call
if (getNumNodes() <= 0) {
return null;
}
// move to a new node
curSerialNodeIndex++;
if (curSerialNodeIndex >= getNumNodes()) {
curSerialNodeIndex = 0;
}
// ensure that each node is initialized
if (getMustInit(curSerialNodeIndex)) {
setMustInit(curSerialNodeIndex, false);
AbstractMRMessage m = getNode(curSerialNodeIndex).createInitPacket();
if (m != null) {
// Oak Tree boards don't need this yet
log.debug("send init message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(2000);
return m;
}
// else fall through to continue
}
// send Output packet if needed
if (getNode(curSerialNodeIndex).mustSend()) {
log.debug("request write command to send");
AbstractMRMessage m = getNode(curSerialNodeIndex).createOutPacket();
getNode(curSerialNodeIndex).resetMustSend();
m.setTimeout(500);
return m;
}
// poll for Sensor input
if (getNode(curSerialNodeIndex).getSensorsActive()) {
// Some sensors are active for this node, issue poll
SerialMessage m = SerialMessage.getPoll(getNode(curSerialNodeIndex).getNodeAddress());
if (curSerialNodeIndex >= getNumNodes()) {
curSerialNodeIndex = 0;
}
return m;
} else {
// no Sensors (inputs) are active for this node
return null;
}
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialTrafficController method pollMessage.
/**
* Handles initialization, output and polling from within the running thread
*/
@Override
protected synchronized AbstractMRMessage pollMessage() {
// ensure validity of call
if (getNumNodes() <= 0) {
return null;
}
// move to a new node
curSerialNodeIndex++;
if (curSerialNodeIndex >= getNumNodes()) {
curSerialNodeIndex = 0;
}
// ensure that each node is initialized
if (getMustInit(curSerialNodeIndex)) {
setMustInit(curSerialNodeIndex, false);
AbstractMRMessage m = getNode(curSerialNodeIndex).createInitPacket();
if (m != null) {
// SECSI boards don't need this yet
log.debug("send init message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(2000);
return m;
}
// else fall through to continue
}
// send Output packet if needed
if (getNode(curSerialNodeIndex).mustSend()) {
log.debug("request write command to send");
AbstractMRMessage m = getNode(curSerialNodeIndex).createOutPacket();
getNode(curSerialNodeIndex).resetMustSend();
m.setTimeout(500);
return m;
}
// poll for Sensor input
if (getNode(curSerialNodeIndex).getSensorsActive()) {
// Some sensors are active for this node, issue poll
SerialMessage m = SerialMessage.getPoll(getNode(curSerialNodeIndex).getNodeAddress());
if (curSerialNodeIndex >= getNumNodes()) {
curSerialNodeIndex = 0;
}
return m;
} else {
// no Sensors (inputs) are active for this node
return null;
}
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class PacketGenFrameTest method testPacketCreate.
@Test
public void testPacketCreate() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
PacketGenFrame t = new PacketGenFrame();
AbstractMRMessage m = t.createPacket("12 34 AB 3 19 6 B B1");
Assert.assertEquals("length", 8, m.getNumDataElements());
Assert.assertEquals("0th byte", 0x12, m.getElement(0) & 0xFF);
Assert.assertEquals("1st byte", 0x34, m.getElement(1) & 0xFF);
Assert.assertEquals("2nd byte", 0xAB, m.getElement(2) & 0xFF);
Assert.assertEquals("3rd byte", 0x03, m.getElement(3) & 0xFF);
Assert.assertEquals("4th byte", 0x19, m.getElement(4) & 0xFF);
Assert.assertEquals("5th byte", 0x06, m.getElement(5) & 0xFF);
Assert.assertEquals("6th byte", 0x0B, m.getElement(6) & 0xFF);
Assert.assertEquals("7th byte", 0xB1, m.getElement(7) & 0xFF);
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialNodeTest method testInitialization3.
public void testInitialization3() {
// USIC_SUSIC with delay and 6 32-bit cards
SerialNode p = new SerialNode(10, SerialNode.USIC_SUSIC, stcs);
p.setNumBitsPerCard(32);
p.setTransmissionDelay(2000);
p.setCardTypeByAddress(0, SerialNode.INPUT_CARD);
p.setCardTypeByAddress(1, SerialNode.OUTPUT_CARD);
p.setCardTypeByAddress(2, SerialNode.OUTPUT_CARD);
p.setCardTypeByAddress(3, SerialNode.OUTPUT_CARD);
p.setCardTypeByAddress(4, SerialNode.INPUT_CARD);
p.setCardTypeByAddress(5, SerialNode.OUTPUT_CARD);
AbstractMRMessage m = p.createInitPacket();
Assert.assertEquals("packet size", 9, m.getNumDataElements());
Assert.assertEquals("node address", 75, m.getElement(0));
// 'I'
Assert.assertEquals("packet type", 73, m.getElement(1));
// 'X'
Assert.assertEquals("node type", 88, m.getElement(2));
Assert.assertEquals("delay high", 7, (m.getElement(3) & 0xff));
Assert.assertEquals("delay low", 208, (m.getElement(4) & 0xff));
// DLE because 2 is next
Assert.assertEquals("DLE", 16, m.getElement(5));
// 2 groups of 4
Assert.assertEquals("NS", 2, m.getElement(6));
// IOOO
Assert.assertEquals("1st group", 169, (m.getElement(7) & 0xff));
// IOXX
Assert.assertEquals("2nd group", 9, (m.getElement(8) & 0xff));
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialNodeTest method testInitialization2.
public void testInitialization2() {
// SMINI with searchlights - similar to CMRI User Manual, page B10
SerialNode e = new SerialNode(9, SerialNode.SMINI, stcs);
e.set2LeadSearchLight(0);
e.set2LeadSearchLight(2);
e.set2LeadSearchLight(4);
e.set2LeadSearchLight(6);
e.set2LeadSearchLight(10);
e.set2LeadSearchLight(16);
e.set2LeadSearchLight(19);
e.set2LeadSearchLight(22);
e.set2LeadSearchLight(46);
e.set2LeadSearchLight(33);
e.set2LeadSearchLight(37);
e.set2LeadSearchLight(44);
e.clear2LeadSearchLight(10);
e.clear2LeadSearchLight(46);
Assert.assertTrue("check searchlight bit", e.isSearchLightBit(7));
Assert.assertTrue("check not searchlight bit", !(e.isSearchLightBit(35)));
AbstractMRMessage m = e.createInitPacket();
Assert.assertEquals("packet size", 12, m.getNumDataElements());
Assert.assertEquals("node address", 74, m.getElement(0));
// 'I'
Assert.assertEquals("packet type", 73, m.getElement(1));
// 'M'
Assert.assertEquals("node type", 77, m.getElement(2));
Assert.assertEquals("delay high", 0, m.getElement(3));
Assert.assertEquals("delay low", 0, m.getElement(4));
// Num Searchlights
Assert.assertEquals("NS", 10, m.getElement(5));
Assert.assertEquals("sl code 1", 255, (m.getElement(6) & 0xff));
Assert.assertEquals("sl code 2", 0, (m.getElement(7) & 0xff));
Assert.assertEquals("sl code 3", 219, (m.getElement(8) & 0xff));
Assert.assertEquals("sl code 4", 0, (m.getElement(9) & 0xff));
Assert.assertEquals("sl code 5", 102, (m.getElement(10) & 0xff));
Assert.assertEquals("sl code 6", 48, (m.getElement(11) & 0xff));
}
Aggregations