Search in sources :

Example 6 with ZigBeeApsFrame

use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZdoIeeeAddress method create.

public static ZigBeeApsFrame create(ZToolPacket packet) {
    ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
    apsFrame.setCluster(ZdoCommandType.IEEE_ADDRESS_RESPONSE.getClusterId());
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSourceAddress(packet.getPacket()[13] + (packet.getPacket()[14] << 8));
    apsFrame.setSourceEndpoint(0);
    apsFrame.setProfile(0);
    int[] temp = Arrays.copyOfRange(packet.getPacket(), 3, packet.getPacket().length - 1);
    int a = temp[12];
    temp[12] = temp[13];
    temp[13] = a;
    temp[0] = 0;
    apsFrame.setPayload(temp);
    return apsFrame;
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame)

Example 7 with ZigBeeApsFrame

use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZdoManagementLqi method create.

public static ZigBeeApsFrame create(ZToolPacket packet) {
    ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
    apsFrame.setCluster(ZdoCommandType.MANAGEMENT_LQI_RESPONSE.getClusterId());
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSourceAddress(packet.getPacket()[4] + (packet.getPacket()[5] << 8));
    apsFrame.setSourceEndpoint(0);
    apsFrame.setProfile(0);
    apsFrame.setPayload(Arrays.copyOfRange(packet.getPacket(), 5, packet.getPacket().length - 1));
    return apsFrame;
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame)

Example 8 with ZigBeeApsFrame

use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZdoNodeDescriptor method create.

public static ZigBeeApsFrame create(ZToolPacket packet) {
    ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
    apsFrame.setCluster(ZdoCommandType.NODE_DESCRIPTOR_RESPONSE.getClusterId());
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSourceAddress(packet.getPacket()[4] + (packet.getPacket()[5] << 8));
    apsFrame.setSourceEndpoint(0);
    apsFrame.setProfile(0);
    apsFrame.setPayload(Arrays.copyOfRange(packet.getPacket(), 5, packet.getPacket().length - 1));
    return apsFrame;
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame)

Example 9 with ZigBeeApsFrame

use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleXBee method xbeeEventReceived.

@Override
public void xbeeEventReceived(XBeeEvent event) {
    if (event instanceof XBeeReceivePacketExplicitEvent) {
        XBeeReceivePacketExplicitEvent rxMessage = (XBeeReceivePacketExplicitEvent) event;
        ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
        apsFrame.setCluster(rxMessage.getClusterId());
        apsFrame.setDestinationEndpoint(rxMessage.getDestinationEndpoint());
        apsFrame.setProfile(rxMessage.getProfileId());
        apsFrame.setSourceEndpoint(rxMessage.getSourceEndpoint());
        apsFrame.setSourceAddress(rxMessage.getNetworkAddress());
        apsFrame.setPayload(rxMessage.getData());
        zigbeeTransportReceive.receiveCommand(apsFrame);
        return;
    }
    // Handle devices joining and leaving
    if (event instanceof XBeeModemStatusEvent) {
        XBeeModemStatusEvent modemStatus = (XBeeModemStatusEvent) event;
        switch(modemStatus.getStatus()) {
            case COORDINATOR_STARTED:
                coordinatorStarted = true;
                if (initialisationComplete) {
                    zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.ONLINE);
                }
                break;
            case DISASSOCIATED:
                zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
                break;
            case HARDWARE_RESET:
                break;
            case JOINED_NETWORK:
                break;
            case NETWORK_SECURITY_KEY_UPDATED:
                break;
            case WATCHDOG_TIMER_RESET:
                break;
            default:
                break;
        }
        return;
    }
    // if (event instanceof TelegesisDeviceLeftNetworkEvent) {
    // TelegesisDeviceLeftNetworkEvent deviceLeftEvent = (TelegesisDeviceLeftNetworkEvent) event;
    // zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, deviceLeftEvent.getNetworkAddress(),
    // deviceLeftEvent.getIeeeAddress());
    // return;
    // }
    // Handle link changes and notify framework or just reset link with dongle?
    // if (event instanceof TelegesisNetworkLeftEvent | event instanceof TelegesisNetworkLostEvent) {
    // zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
    // return;
    // }
    // if (event instanceof TelegesisNetworkJoinedEvent) {
    // zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.ONLINE);
    // return;
    // }
    logger.debug("Unhandled XBee Frame: {}", event.toString());
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) XBeeModemStatusEvent(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeModemStatusEvent) XBeeReceivePacketExplicitEvent(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeReceivePacketExplicitEvent)

Example 10 with ZigBeeApsFrame

use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleXBeeTest method sendCommand.

@Test
public void sendCommand() {
    XBeeFrameHandler frameHandler = Mockito.mock(XBeeFrameHandler.class);
    ArgumentCaptor<XBeeCommand> commandCapture = ArgumentCaptor.forClass(XBeeCommand.class);
    Mockito.when(frameHandler.sendRequestAsync(commandCapture.capture())).thenReturn(null);
    ZigBeeDongleXBee dongle = new ZigBeeDongleXBee(null);
    Field field;
    try {
        field = dongle.getClass().getDeclaredField("frameHandler");
        field.setAccessible(true);
        field.set(dongle, frameHandler);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
    MatchDescriptorResponse command = new MatchDescriptorResponse();
    command.setDestinationAddress(new ZigBeeEndpointAddress(46946));
    command.setNwkAddrOfInterest(46946);
    command.setStatus(ZdoStatus.SUCCESS);
    command.setTransactionId(0x2A);
    List<Integer> matchList = new ArrayList<>();
    matchList.add(1);
    command.setMatchList(matchList);
    ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
    apsFrame.setDestinationAddress(46946);
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setDestinationIeeeAddress(new IeeeAddress("000D6F00057CF7C6"));
    apsFrame.setCluster(32774);
    apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE);
    apsFrame.setRadius(31);
    apsFrame.setSequence(42);
    apsFrame.setPayload(new int[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 });
    System.out.println(command);
    System.out.println(apsFrame);
    dongle.sendCommand(apsFrame);
    assertEquals(1, commandCapture.getAllValues().size());
    XBeeTransmitRequestExplicitCommand sentCommand = (XBeeTransmitRequestExplicitCommand) commandCapture.getValue();
    sentCommand.setFrameId(32);
    System.out.println(sentCommand);
    int[] payload = new int[] { 0, 26, 17, 32, 0, 13, 111, 0, 5, 124, 247, 198, 183, 98, 0, 0, 128, 6, 0, 0, 0, 32, 0, 0, 46, 91, 1, 1, 202 };
    int[] output = sentCommand.serialize();
    assertTrue(Arrays.equals(payload, output));
}
Also used : XBeeCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeCommand) ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) XBeeFrameHandler(com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler) MatchDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse) ArrayList(java.util.ArrayList) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Field(java.lang.reflect.Field) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) XBeeTransmitRequestExplicitCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand) Test(org.junit.Test)

Aggregations

ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)29 Test (org.junit.Test)14 ZToolPacket (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket)12 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 ZigBeeNodeStatus (com.zsmartsystems.zigbee.ZigBeeNodeStatus)1 ConBeeDeviceState (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceState)1 ConBeeDeviceStateChanged (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceStateChanged)1 ConBeeDeviceStateResponse (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceStateResponse)1 ConBeeReadReceivedDataResponse (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeReadReceivedDataResponse)1 ZigBeeDongleEzsp (com.zsmartsystems.zigbee.dongle.ember.ZigBeeDongleEzsp)1 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)1 EzspChildJoinHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspChildJoinHandler)1 EzspIncomingMessageHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspIncomingMessageHandler)1 EzspStackStatusHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspStackStatusHandler)1 EzspTrustCenterJoinHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspTrustCenterJoinHandler)1 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)1 TelegesisDeviceJoinedNetworkEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceJoinedNetworkEvent)1 TelegesisDeviceLeftNetworkEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceLeftNetworkEvent)1 TelegesisNetworkJoinedEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkJoinedEvent)1