Search in sources :

Example 1 with ConBeeDeviceState

use of com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceState in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleConBee method receiveIncomingFrame.

/**
 * @param frame the received {@link ConBeeFrame}
 */
public void receiveIncomingFrame(ConBeeFrame frame) {
    if (frame instanceof ConBeeReadReceivedDataResponse) {
        ConBeeReadReceivedDataResponse receivedData = (ConBeeReadReceivedDataResponse) frame;
        if (receivedData.getStatus() != ConBeeStatus.SUCCESS) {
            return;
        }
        ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
        // apsFrame.setApsCounter(emberApsFrame.getSequence());
        apsFrame.setCluster(receivedData.getClusterId());
        apsFrame.setDestinationEndpoint(receivedData.getDestinationEndpoint());
        apsFrame.setProfile(receivedData.getProfileId());
        apsFrame.setSourceEndpoint(receivedData.getSourceEndpoint());
        // receivedData.getSourceAddressMode()
        // apsFrame.sets
        apsFrame.setSourceAddress(receivedData.getSourceNetworkAddress());
        apsFrame.setPayload(receivedData.getAdsuData());
        zigbeeNetworkReceive.receiveCommand(apsFrame);
        return;
    }
    if (frame instanceof ConBeeDeviceStateChanged || frame instanceof ConBeeDeviceStateResponse) {
        ConBeeDeviceState deviceState;
        if (frame instanceof ConBeeDeviceStateChanged) {
            deviceState = ((ConBeeDeviceStateChanged) frame).getDeviceState();
        } else {
            deviceState = ((ConBeeDeviceStateResponse) frame).getDeviceState();
        }
        if (!initialisationComplete || deviceState.getNetworkState() == currentNetworkState) {
            return;
        }
        currentNetworkState = deviceState.getNetworkState();
        switch(deviceState.getNetworkState()) {
            case NET_CONNECTED:
                zigbeeNetworkReceive.setNetworkState(ZigBeeTransportState.ONLINE);
                break;
            case NET_JOINING:
            case NET_LEAVING:
            case NET_OFFLINE:
                zigbeeNetworkReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
                break;
            default:
                break;
        }
    }
}
Also used : ConBeeDeviceState(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceState) ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) ConBeeDeviceStateChanged(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceStateChanged) ConBeeReadReceivedDataResponse(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeReadReceivedDataResponse) ConBeeDeviceStateResponse(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeDeviceStateResponse)

Aggregations

ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)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