Search in sources :

Example 6 with CanMessage

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());
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 7 with CanMessage

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));
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 8 with CanMessage

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);
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 9 with CanMessage

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);
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Example 10 with CanMessage

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;
}
Also used : CanMessage(jmri.jmrix.can.CanMessage)

Aggregations

CanMessage (jmri.jmrix.can.CanMessage)63 Test (org.junit.Test)4 CanReply (jmri.jmrix.can.CanReply)3 CanListener (jmri.jmrix.can.CanListener)2 CbusAddress (jmri.jmrix.can.cbus.CbusAddress)2 DccLocoAddress (jmri.DccLocoAddress)1 AbstractMRMessage (jmri.jmrix.AbstractMRMessage)1 CanSystemConnectionMemo (jmri.jmrix.can.CanSystemConnectionMemo)1 TestTrafficController (jmri.jmrix.can.TestTrafficController)1 TrafficControllerScaffold (jmri.jmrix.can.TrafficControllerScaffold)1 GridConnectMessage (jmri.jmrix.can.adapters.gridconnect.GridConnectMessage)1 GridConnectReply (jmri.jmrix.can.adapters.gridconnect.GridConnectReply)1 LoaderClient (org.openlcb.LoaderClient)1 OlcbInterface (org.openlcb.OlcbInterface)1 AliasMap (org.openlcb.can.AliasMap)1 CanInterface (org.openlcb.can.CanInterface)1 MessageBuilder (org.openlcb.can.MessageBuilder)1 Hub (org.openlcb.hub.Hub)1