Search in sources :

Example 1 with XBeeModemStatusEvent

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeModemStatusEvent 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)

Aggregations

ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)1 XBeeModemStatusEvent (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeModemStatusEvent)1 XBeeReceivePacketExplicitEvent (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeReceivePacketExplicitEvent)1