use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class OlcbSensorTest method testMomentarySensor.
public void testMomentarySensor() throws Exception {
Assert.assertNotNull("exists", t);
OlcbSensor s = new OlcbSensor("MS", "1.2.3.4.5.6.7.8", t.iface);
// message for Active and Inactive
CanMessage mActive = new CanMessage(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0x195B4123);
mActive.setExtended(true);
// check states
Assert.assertTrue(s.getKnownState() == Sensor.UNKNOWN);
t.sendMessage(mActive);
Assert.assertTrue(s.getKnownState() == Sensor.ACTIVE);
// wait for twice timeout to make sure
try {
Thread.sleep(2 * OlcbSensor.ON_TIME);
} catch (Exception e) {
}
Assert.assertEquals(Sensor.INACTIVE, s.getKnownState());
// local flip
s.setKnownState(Sensor.ACTIVE);
Assert.assertTrue(s.getKnownState() == Sensor.ACTIVE);
// wait for twice timeout to make sure
try {
Thread.sleep(2 * OlcbSensor.ON_TIME);
} catch (Exception e) {
}
Assert.assertEquals(Sensor.INACTIVE, s.getKnownState());
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class OlcbAddressTest method testCbusIdParseMatchMessage.
public void testCbusIdParseMatchMessage() {
CanMessage c = new CanMessage(new int[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 }, 0x195B4123);
assertTrue(!new OlcbAddress("x123456789ABCDEF0").match(c));
c.setExtended(true);
assertTrue(new OlcbAddress("x123456789ABCDEF0").match(c));
c = new CanMessage(new int[] { 0x01, 0x34, 0x05, 0x00, 0x9A, 0x0B, 0x0E, 0x00 }, 0x195B4123);
assertTrue(!new OlcbAddress("1.34.5.0.9A.B.E.0").match(c));
c.setExtended(true);
assertTrue(new OlcbAddress("1.34.5.0.9A.B.E.0").match(c));
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class OlcbTurnoutTest method testNameFormatXupper.
public void testNameFormatXupper() {
// load dummy TrafficController
OlcbTurnout s = new OlcbTurnout("MT", "X0501010114FF2000;X0501010114FF2001", t.iface);
s.finishLoad();
Assert.assertNotNull("to exists", s);
// message for Active and Inactive
CanMessage mActive = new CanMessage(new int[] { 0x05, 0x01, 0x01, 0x01, 0x14, 0xFF, 0x20, 0x00 }, 0x195B4000);
mActive.setExtended(true);
CanMessage mInactive = new CanMessage(new int[] { 0x05, 0x01, 0x01, 0x01, 0x14, 0xFF, 0x20, 0x01 }, 0x195B4000);
mInactive.setExtended(true);
// check states
Assert.assertTrue(s.getCommandedState() == Turnout.UNKNOWN);
t.sendMessage(mActive);
Assert.assertTrue(s.getCommandedState() == Turnout.THROWN);
t.sendMessage(mInactive);
Assert.assertTrue(s.getCommandedState() == Turnout.CLOSED);
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class CbusCommandStation method setSpeedDir.
/**
* Set loco speed and direction
*
* @param handle The handle of the session to which it applies
* @param speed_dir Bit 7 is direction (1 = forward) 6:0 are speed
*/
public void setSpeedDir(int handle, int speed_dir) {
CanMessage msg = new CanMessage(3, tc.getCanid());
msg.setOpCode(CbusConstants.CBUS_DSPD);
msg.setElement(1, handle);
msg.setElement(2, speed_dir);
log.debug("setSpeedDir session handle " + handle + " speedDir " + speed_dir);
tc.sendCanMessage(msg, null);
}
use of jmri.jmrix.can.CanMessage in project JMRI by JMRI.
the class LoopbackTrafficController method newMessage.
// New message for hardware protocol
@Override
protected AbstractMRMessage newMessage() {
log.debug("New CanMessage created");
CanMessage msg = new CanMessage(getCanid());
return msg;
}
Aggregations