Search in sources :

Example 1 with XBeeResponse

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class XBeeResponseFactoryTest method testGetResponse1.

@Test
public void testGetResponse1() {
    int[] data = getPacketData("00 07 8B 8F F7 7B 00 00 40 33");
    XBeeResponse frame = XBeeResponseFactory.getXBeeFrame(data);
    assertTrue(frame instanceof XBeeTransmitStatusResponse);
    System.out.println(frame);
    XBeeTransmitStatusResponse event = (XBeeTransmitStatusResponse) frame;
    assertEquals(Integer.valueOf(143), event.getFrameId());
    assertEquals(Integer.valueOf(0), event.getTransmitRetryCount());
    assertEquals(DeliveryStatus.SUCCESS, event.getDeliveryStatus());
    assertEquals(DiscoveryStatus.EXTENDED_TIMEOUT_DISCOVERY, event.getDiscoveryStatus());
}
Also used : XBeeResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse) XBeeTransmitStatusResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitStatusResponse) Test(org.junit.Test)

Example 2 with XBeeResponse

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class XBeeResponseFactoryTest method testGetResponse2.

@Test
public void testGetResponse2() {
    int[] data = getPacketData("00 05 88 10 4F 49 02 CD");
    XBeeResponse frame = XBeeResponseFactory.getXBeeFrame(data);
    assertTrue(frame instanceof XBeePanIdResponse);
    System.out.println(frame);
    XBeePanIdResponse event = (XBeePanIdResponse) frame;
    assertEquals(CommandStatus.INVALID_COMMAND, event.getCommandStatus());
}
Also used : XBeeResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse) XBeePanIdResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeePanIdResponse) Test(org.junit.Test)

Example 3 with XBeeResponse

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class XBeeResponseFactory method getXBeeFrame.

public static XBeeResponse getXBeeFrame(int[] data) {
    Class<?> xbeeClass = null;
    // Try and correlate any AT command responses first
    if (data[2] == 0x88) {
        xbeeClass = atCommands.get((data[4] << 8) + data[5]);
    }
    // If not found, then use the API commands
    if (xbeeClass == null) {
        xbeeClass = events.get(data[2]);
    }
    // No handler found
    if (xbeeClass == null) {
        return null;
    }
    Constructor<?> ctor;
    try {
        ctor = xbeeClass.getConstructor();
        XBeeResponse xbeeFrame = (XBeeResponse) ctor.newInstance();
        xbeeFrame.deserialize(data);
        return xbeeFrame;
    } catch (Exception e) {
        logger.debug("Error creating instance of XBeeResponse", e);
    }
    return null;
}
Also used : XBeeResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse)

Aggregations

XBeeResponse (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeResponse)3 Test (org.junit.Test)2 XBeePanIdResponse (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeePanIdResponse)1 XBeeTransmitStatusResponse (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitStatusResponse)1