Search in sources :

Example 1 with ZToolPacket

use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.

the class CommandInterfaceImpl method handlePacket.

/**
 * Handle parsed packet.
 *
 * @param packet the packet
 */
@Override
public void handlePacket(final ZToolPacket packet) {
    final DoubleByte cmdId = packet.getCMD();
    switch(cmdId.getMsb() & 0xE0) {
        // Received incoming message which can be either message from dongle or remote device.
        case 0x40:
            logger.debug("<-- {} ({})", packet.getClass().getSimpleName(), ByteUtils.toBase16(packet.getPacket()));
            notifyAsynchronousCommand(packet);
            break;
        // Received synchronous command response.
        case 0x60:
            logger.debug("<-  {} ({})", packet.getClass().getSimpleName(), ByteUtils.toBase16(packet.getPacket()));
            notifySynchronousCommand(packet);
            break;
        default:
            logger.error("Received unknown packet. {}", packet.getClass().getSimpleName());
            break;
    }
}
Also used : DoubleByte(com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util.DoubleByte)

Example 2 with ZToolPacket

use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.

the class Cc2351TestPacket method getPacket.

protected ZToolPacket getPacket(String stringData) {
    int[] packet = getPacketData(stringData);
    byte[] byteArray = new byte[packet.length - 1];
    for (int c = 1; c < packet.length; c++) {
        byteArray[c - 1] = (byte) packet[c];
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(byteArray);
    ZigBeePort port = new TestPort(stream, null);
    try {
        ZToolPacket ztoolPacket = new ZToolPacketStream(port).parsePacket();
        assertFalse(ztoolPacket.isError());
        return ztoolPacket;
    } catch (IOException e) {
        return null;
    }
}
Also used : ZToolPacket(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket) ZToolPacketStream(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort)

Example 3 with ZToolPacket

use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZDO_ACTIVE_EP_RSP_Test method testReceive.

@Test
public void testReceive() {
    String packetString = "FE 08 45 85 00 00 00 00 00 02 02 01 C9";
    ZToolPacket data = getPacket(packetString);
    assertEquals(packetString, data.getPacketString());
    ZigBeeApsFrame apsFrame = ZdoActiveEndpoint.create(data);
    assertEquals(0x0000, apsFrame.getSourceAddress());
    assertEquals(0, apsFrame.getProfile());
    assertEquals(0, apsFrame.getDestinationEndpoint());
    assertTrue(Arrays.equals(getPacketData("00 00 00 00 02 02 01"), apsFrame.getPayload()));
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) ZToolPacket(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket) Test(org.junit.Test)

Example 4 with ZToolPacket

use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZDO_MSG_CB_INCOMING_Test method testReceive.

@Test
public void testReceive() {
    ZToolPacket data = getPacket("FE 15 45 FF 00 00 00 01 80 00 00 00 1B 00 5B 23 EB 09 00 4B 12 00 00 00 00 F6");
    ZigBeeApsFrame apsFrame = ZdoCallbackIncoming.create(data);
    assertEquals(0x8001, apsFrame.getCluster());
    assertEquals(0x0000, apsFrame.getSourceAddress());
    assertEquals(0, apsFrame.getProfile());
    assertEquals(0, apsFrame.getDestinationEndpoint());
    assertTrue(Arrays.equals(getPacketData("1B 00 5B 23 EB 09 00 4B 12 00 00 00 00"), apsFrame.getPayload()));
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) ZToolPacket(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket) Test(org.junit.Test)

Example 5 with ZToolPacket

use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZDO_NODE_DESC_RSP_Test method testReceive.

@Test
public void testReceive() {
    ZToolPacket data = getPacket("FE 12 45 82 00 00 00 00 00 00 40 0F 00 00 50 A0 00 01 00 A0 00 00 CB");
    ZigBeeApsFrame apsFrame = ZdoNodeDescriptor.create(data);
    assertEquals(0x0000, apsFrame.getSourceAddress());
    assertEquals(0, apsFrame.getProfile());
    assertEquals(0, apsFrame.getDestinationEndpoint());
    assertTrue(Arrays.equals(getPacketData("00 00 00 00 00 40 0F 00 00 50 A0 00 01 00 A0 00 00"), apsFrame.getPayload()));
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) ZToolPacket(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket) Test(org.junit.Test)

Aggregations

ZToolPacket (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket)16 Test (org.junit.Test)13 ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)12 DoubleByte (com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util.DoubleByte)4 AsynchronousCommandListener (com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener)2 IOException (java.io.IOException)2 SynchronousCommandListener (com.zsmartsystems.zigbee.dongle.cc2531.network.SynchronousCommandListener)1 BlockingCommandReceiver (com.zsmartsystems.zigbee.dongle.cc2531.network.impl.BlockingCommandReceiver)1 ZToolPacketStream (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream)1 SYS_RESET_RESPONSE (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.system.SYS_RESET_RESPONSE)1 SYS_VERSION_RESPONSE (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.system.SYS_VERSION_RESPONSE)1 ZigBeePort (com.zsmartsystems.zigbee.transport.ZigBeePort)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1