Search in sources :

Example 1 with TelegesisNetworkLostEvent

use of com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleTelegesis method telegesisEventReceived.

@Override
public void telegesisEventReceived(TelegesisEvent event) {
    if (event instanceof TelegesisReceiveMessageEvent) {
        TelegesisReceiveMessageEvent rxMessage = (TelegesisReceiveMessageEvent) event;
        ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
        // apsFrame.setApsCounter(emberApsFrame.getSequence());
        apsFrame.setCluster(rxMessage.getClusterId());
        apsFrame.setDestinationEndpoint(rxMessage.getDestinationEp());
        apsFrame.setProfile(rxMessage.getProfileId());
        apsFrame.setSourceEndpoint(rxMessage.getSourceEp());
        apsFrame.setSourceAddress(rxMessage.getNetworkAddress());
        apsFrame.setPayload(rxMessage.getMessageData());
        zigbeeTransportReceive.receiveCommand(apsFrame);
        return;
    }
    // Handle devices joining and leaving
    if (event instanceof TelegesisDeviceJoinedNetworkEvent) {
        TelegesisDeviceJoinedNetworkEvent deviceJoinedEvent = (TelegesisDeviceJoinedNetworkEvent) event;
        zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.UNSECURED_JOIN, deviceJoinedEvent.getNetworkAddress(), deviceJoinedEvent.getIeeeAddress());
        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 Telegesis Frame: {}", event.toString());
}
Also used : TelegesisDeviceJoinedNetworkEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceJoinedNetworkEvent) ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) TelegesisReceiveMessageEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisReceiveMessageEvent) TelegesisNetworkLostEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent) TelegesisNetworkLeftEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLeftEvent) TelegesisNetworkJoinedEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkJoinedEvent) TelegesisDeviceLeftNetworkEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceLeftNetworkEvent)

Example 2 with TelegesisNetworkLostEvent

use of com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent in project com.zsmartsystems.zigbee by zsmartsystems.

the class TelegesisFrameHandlerTest method testEventWait.

@Ignore
@Test
public void testEventWait() {
    final TelegesisFrameHandler frameHandler = new TelegesisFrameHandler();
    final List<TelegesisEvent> eventCapture = new ArrayList<TelegesisEvent>();
    Thread waitThread = new Thread() {

        @Override
        public void run() {
            // Send the transaction and wait for the response
            eventCapture.add(frameHandler.eventWait(TelegesisSleepyDeviceAnnounceEvent.class));
            synchronized (eventCapture) {
                eventCapture.notify();
            }
        }
    };
    waitThread.start();
    TelegesisEvent eventOk = new TelegesisSleepyDeviceAnnounceEvent();
    TelegesisEvent eventNOk = new TelegesisNetworkLostEvent();
    try {
        Method privateMethod;
        try {
            privateMethod = TelegesisFrameHandler.class.getDeclaredMethod("notifyEventReceived", new Class[] { TelegesisEvent.class });
            privateMethod.setAccessible(true);
            privateMethod.invoke(frameHandler, eventNOk);
            privateMethod.invoke(frameHandler, eventOk);
        } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        synchronized (eventCapture) {
            eventCapture.wait(1000);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(1, eventCapture.size());
}
Also used : TelegesisEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TelegesisNetworkLostEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent) TelegesisSleepyDeviceAnnounceEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisSleepyDeviceAnnounceEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TelegesisNetworkLostEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent)2 ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)1 TelegesisDeviceJoinedNetworkEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceJoinedNetworkEvent)1 TelegesisDeviceLeftNetworkEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceLeftNetworkEvent)1 TelegesisEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent)1 TelegesisNetworkJoinedEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkJoinedEvent)1 TelegesisNetworkLeftEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLeftEvent)1 TelegesisReceiveMessageEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisReceiveMessageEvent)1 TelegesisSleepyDeviceAnnounceEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisSleepyDeviceAnnounceEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1