Search in sources :

Example 1 with TelegesisEvent

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

the class TelegesisEventFactory method getTelegesisFrame.

public static TelegesisEvent getTelegesisFrame(int[] data) {
    // Create the hash of the prompt
    int hash = 0;
    int multiplier = 1;
    for (int value : data) {
        if (value == '\n' || value == ':' || value == '=') {
            break;
        }
        hash += (value & 0xff) * multiplier;
        int shifted = multiplier << 5;
        multiplier = shifted - multiplier;
    }
    Class<?> telegesisClass = events.get(hash);
    if (telegesisClass == null) {
        return null;
    }
    Constructor<?> ctor;
    try {
        ctor = telegesisClass.getConstructor();
        TelegesisEvent telegesisEvent = (TelegesisEvent) ctor.newInstance();
        telegesisEvent.deserialize(data);
        return telegesisEvent;
    } catch (Exception e) {
        logger.debug("Error creating instance of Telegesis event", e);
    }
    return null;
}
Also used : TelegesisEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent)

Example 2 with TelegesisEvent

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

the class TelegesisEventFactoryTest method testCorruptMessage1.

@Test
public void testCorruptMessage1() {
    TelegesisEvent event = TelegesisEventFactory.getTelegesisFrame(new int[] { 0x52, 0x58, 0x3A, 0x33, 0x44, 0x45, 0x42, 0x2C, 0x30, 0x93, 0x05, 0x00, 0xEA, 0x11 });
    assertNull(event);
}
Also used : TelegesisEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent) TelegesisFrameBaseTest(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisFrameBaseTest) Test(org.junit.Test)

Example 3 with TelegesisEvent

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

the class TelegesisEventFactoryTest method testCorruptMessage2.

@Test
public void testCorruptMessage2() {
    TelegesisEvent event = TelegesisEventFactory.getTelegesisFrame(stringToIntArray("SR:00,001788011"));
    assertNull(event);
}
Also used : TelegesisEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent) TelegesisFrameBaseTest(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisFrameBaseTest) Test(org.junit.Test)

Example 4 with TelegesisEvent

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

the class TelegesisEventFactoryTest method testGetEvent.

@Test
public void testGetEvent() {
    TelegesisEvent event = TelegesisEventFactory.getTelegesisFrame(stringToIntArray("NODELEFT:1234,1234567890ABCDEF"));
    assertTrue(event instanceof TelegesisDeviceLeftNetworkEvent);
}
Also used : TelegesisEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent) TelegesisDeviceLeftNetworkEvent(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceLeftNetworkEvent) TelegesisFrameBaseTest(com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisFrameBaseTest) Test(org.junit.Test)

Example 5 with TelegesisEvent

use of com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent 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

TelegesisEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisEvent)7 Test (org.junit.Test)6 TelegesisFrameBaseTest (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisFrameBaseTest)5 TelegesisDeviceLeftNetworkEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisDeviceLeftNetworkEvent)1 TelegesisNetworkLostEvent (com.zsmartsystems.zigbee.dongle.telegesis.internal.protocol.TelegesisNetworkLostEvent)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