use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialTrafficControllerTest method testSerialOutput.
@Test
public void testSerialOutput() {
SerialTrafficController c = (SerialTrafficController) tc;
SerialNode a = new SerialNode();
SerialNode g = new SerialNode(5, SerialNode.NODE2002V1);
Assert.assertTrue("must Send", g.mustSend());
g.resetMustSend();
Assert.assertNotNull("exists", a);
Assert.assertTrue("must Send off", !(g.mustSend()));
c.setSerialOutput("GL5B2", false);
c.setSerialOutput("GL5B1", false);
c.setSerialOutput("GL5B7", false);
c.setSerialOutput("GL5B3", false);
c.setSerialOutput("GL5B5", false);
c.setSerialOutput("GL5B8", true);
c.setSerialOutput("GL5B11", false);
c.setSerialOutput("GL5B5", false);
c.setSerialOutput("GL5B10", false);
c.setSerialOutput("GL5B9", false);
Assert.assertTrue("must Send on", g.mustSend());
AbstractMRMessage m = g.createOutPacket();
Assert.assertEquals("packet size", 4, m.getNumDataElements());
Assert.assertEquals("node address", 5, m.getElement(0));
// 'T'
Assert.assertEquals("packet type", 17, m.getElement(1));
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialNodeTest method testInitialization1.
public void testInitialization1() {
// no initialization in this protocol
AbstractMRMessage m = b.createInitPacket();
Assert.assertEquals("initpacket null", null, m);
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class SerialTrafficControllerTest method testSerialOutput.
public void testSerialOutput() {
SerialTrafficController c = (SerialTrafficController) tc;
SerialNode a = new SerialNode();
Assert.assertNotNull("exists", a);
SerialNode g = new SerialNode(5, SerialNode.DAUGHTER);
Assert.assertTrue("must Send", g.mustSend());
g.resetMustSend();
Assert.assertTrue("must Send off", !(g.mustSend()));
c.setSerialOutput("VL5B2", false);
c.setSerialOutput("VL5B1", false);
c.setSerialOutput("VL5B23", false);
c.setSerialOutput("VL5B22", false);
c.setSerialOutput("VL5B21", false);
c.setSerialOutput("VL5B2", true);
c.setSerialOutput("VL5B19", false);
c.setSerialOutput("VL5B5", false);
c.setSerialOutput("VL5B20", false);
c.setSerialOutput("VL5B17", true);
Assert.assertTrue("must Send on", g.mustSend());
AbstractMRMessage m = g.createOutPacket();
Assert.assertEquals("packet size", 9, m.getNumDataElements());
Assert.assertEquals("node address", 5, m.getElement(0));
Assert.assertEquals("byte 1 lo nibble", 0x02, m.getElement(1));
Assert.assertEquals("byte 1 hi nibble", 0x10, m.getElement(2));
Assert.assertEquals("byte 2 lo nibble", 0x20, m.getElement(3));
Assert.assertEquals("byte 2 hi nibble", 0x30, m.getElement(4));
Assert.assertEquals("byte 3 lo nibble", 0x41, m.getElement(5));
Assert.assertEquals("byte 3 hi nibble", 0x50, m.getElement(6));
Assert.assertEquals("byte 4 lo nibble", 0x60, m.getElement(7));
Assert.assertEquals("byte 4 hi nibble", 0x70, m.getElement(8));
}
use of jmri.jmrix.AbstractMRMessage in project JMRI by JMRI.
the class AcelaTrafficController method pollMessage.
/**
* Handles initialization, output and polling for Acela Nodes from within
* the running thread
*/
@Override
protected synchronized AbstractMRMessage pollMessage() {
// Need to wait until we have read config file
if (!reallyReadyToPoll) {
return null;
}
if (needToInitAcelaNetwork) {
if (needToCreateNodesState == 0) {
if (needToPollNodes) {
new AcelaNode(0, AcelaNode.AC, this);
log.info("Created a new Acela Node [0] in order to poll Acela network: " + AcelaNode.AC);
}
curAcelaNodeIndex = SPECIALNODE;
AcelaMessage m = AcelaMessage.getAcelaResetMsg();
log.debug("send Acela reset (init step 1) message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(1000);
mCurrentMode = NORMALMODE;
needToCreateNodesState++;
return m;
}
if (needToCreateNodesState == 1) {
AcelaMessage m = AcelaMessage.getAcelaOnlineMsg();
log.debug("send Acela Online (init step 2) message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(1000);
mCurrentMode = NORMALMODE;
needToCreateNodesState++;
return m;
}
if (needToPollNodes) {
if (needToCreateNodesState == 2) {
AcelaMessage m = AcelaMessage.getAcelaPollNodesMsg();
log.debug("send Acela poll nodes message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(100);
mCurrentMode = NORMALMODE;
needToInitAcelaNetwork = false;
needToPollNodes = false;
return m;
}
} else {
needToInitAcelaNetwork = false;
setAcelaTrafficControllerState(true);
}
}
// ensure validity of call
if (getNumNodes() <= 0) {
return null;
}
// move to a new node
curAcelaNodeIndex++;
if (curAcelaNodeIndex >= getNumNodes()) {
curAcelaNodeIndex = 0;
}
// ensure that each node is initialized
AcelaNode node = (AcelaNode) getNode(curAcelaNodeIndex);
if (node.hasActiveSensors) {
for (int s = 0; s < node.sensorbitsPerCard; s++) {
if (node.sensorNeedInit[s] && !node.sensorHasBeenInit[s]) {
AcelaMessage m = AcelaMessage.getAcelaConfigSensorMsg();
int tempiaddr = s + node.getStartingSensorAddress();
byte tempbaddr = (byte) (tempiaddr);
m.setElement(2, tempbaddr);
m.setElement(3, node.sensorConfigArray[s]);
log.debug("send Aclea Config Sensor message: " + m);
incrementAcelaSensorInitCount();
// wait for init to finish (milliseconds)
m.setTimeout(100);
mCurrentMode = NORMALMODE;
node.sensorHasBeenInit[s] = true;
node.sensorNeedInit[s] = false;
return m;
}
}
}
// send Output packet if needed
if (getNode(curAcelaNodeIndex).mustSend()) {
getNode(curAcelaNodeIndex).resetMustSend();
AbstractMRMessage m = getNode(curAcelaNodeIndex).createOutPacket();
// no need to wait for output to answer
m.setTimeout(100);
log.debug("request write command to send: " + m);
mCurrentMode = NORMALMODE;
return m;
}
// during a cold system startup.
if ((currentSensorAddress == 0) || (currentSensorAddress != getAcelaSensorInitCount())) {
return null;
}
if (acelaSensorsState) {
// Flag to indicate whether we have an active sensor and therefore need to poll
AcelaMessage m = AcelaMessage.getAcelaPollSensorsMsg();
log.debug("send Acela poll sensors message: " + m);
// wait for init to finish (milliseconds)
m.setTimeout(100);
mCurrentMode = NORMALMODE;
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 EcosTrafficController method terminate.
@Override
protected void terminate() {
if (log.isDebugEnabled()) {
log.debug("Cleanup Starts");
}
if (ostream == null) {
// no connection established
return;
}
EcosPreferences p = adaptermemo.getPreferenceManager();
if (p.getAdhocLocoFromEcos() == 0x01) {
//Just a double check that we can delete locos
return;
}
//AbstractMRMessage modeMsg=enterNormalMode();
AbstractMRMessage modeMsg;
List<String> en;
String ecosObject;
modeMsg = new EcosMessage("release(10, view)");
modeMsg.setTimeout(50);
modeMsg.setRetries(10);
synchronized (this) {
forwardToPort(modeMsg, null);
// wait for reply
try {
if (xmtRunnable != null) {
synchronized (xmtRunnable) {
xmtRunnable.wait(modeMsg.getTimeout());
}
}
} catch (InterruptedException e) {
// retain if needed later
Thread.currentThread().interrupt();
log.error("transmit interrupted");
}
}
EcosTurnoutManager objEcosTurnManager = adaptermemo.getTurnoutManager();
en = objEcosTurnManager.getEcosObjectList();
for (int i = 0; i < en.size(); i++) {
ecosObject = en.get(i);
modeMsg = new EcosMessage("release(" + ecosObject + ", view)");
modeMsg.setTimeout(50);
modeMsg.setRetries(10);
synchronized (this) {
forwardToPort(modeMsg, null);
// wait for reply
try {
if (xmtRunnable != null) {
synchronized (xmtRunnable) {
xmtRunnable.wait(modeMsg.getTimeout());
}
}
} catch (InterruptedException e) {
// retain if needed later
Thread.currentThread().interrupt();
log.error("transmit interrupted");
}
}
}
EcosLocoAddressManager objEcosLocoManager = adaptermemo.getLocoAddressManager();
en = objEcosLocoManager.getEcosObjectList();
for (int i = 0; i < en.size(); i++) {
ecosObject = en.get(i);
//we only delete locos if they were a temp entry.
if (objEcosLocoManager.getByEcosObject(ecosObject).getEcosTempEntry()) {
/*The ecos can be funny in not providing control on the first request, plus we have no way to determine if we have
therefore we send the request twice and hope we have control, failure not to have control isn't a problem as the loco
will simply be left on the ecos.*/
for (int x = 0; x < 4; x++) {
switch(x) {
case 3:
modeMsg = new EcosMessage("delete(" + ecosObject + ")");
break;
case 2:
modeMsg = new EcosMessage("set(" + ecosObject + ", stop)");
break;
default:
modeMsg = new EcosMessage("request(" + ecosObject + ",control)");
break;
}
modeMsg.setTimeout(50);
modeMsg.setRetries(10);
synchronized (this) {
forwardToPort(modeMsg, null);
// wait for reply
try {
if (xmtRunnable != null) {
synchronized (xmtRunnable) {
xmtRunnable.wait(modeMsg.getTimeout());
}
}
} catch (InterruptedException e) {
// retain if needed later
Thread.currentThread().interrupt();
log.error("transmit interrupted");
}
}
}
}
}
}
Aggregations