Search in sources :

Example 1 with ZigBeeDeserializer

use of com.zsmartsystems.zigbee.serialization.ZigBeeDeserializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNetworkManager method receiveCommand.

@Override
public void receiveCommand(final ZigBeeApsFrame apsFrame) {
    logger.debug("RX APS: {}", apsFrame);
    // Create the deserialiser
    Constructor<? extends ZigBeeDeserializer> constructor;
    ZigBeeDeserializer deserializer;
    try {
        constructor = deserializerClass.getConstructor(int[].class);
        deserializer = constructor.newInstance(new Object[] { apsFrame.getPayload() });
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.debug("Error creating deserializer", e);
        return;
    }
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZigBeeCommand command = null;
    switch(// TODO: Use ZigBeeProfileType
    apsFrame.getProfile()) {
        case 0x0000:
            command = receiveZdoCommand(fieldDeserializer, apsFrame);
            break;
        case 0x0104:
        case 0xC05E:
            command = receiveZclCommand(fieldDeserializer, apsFrame);
            break;
        default:
            logger.debug("Received message with unknown profile {}", String.format("%04X", apsFrame.getProfile()));
            break;
    }
    if (command == null) {
        logger.debug("Incoming message did not translate to command.");
        return;
    }
    // Create an address from the sourceAddress and endpoint
    command.setSourceAddress(new ZigBeeEndpointAddress(apsFrame.getSourceAddress(), apsFrame.getSourceEndpoint()));
    command.setDestinationAddress(new ZigBeeEndpointAddress(apsFrame.getDestinationAddress(), apsFrame.getDestinationEndpoint()));
    logger.debug("RX CMD: {}", command);
    // Notify the listeners
    commandNotifier.notifyCommandListeners(command);
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) ZigBeeDeserializer(com.zsmartsystems.zigbee.serialization.ZigBeeDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)

Aggregations

ZigBeeDeserializer (com.zsmartsystems.zigbee.serialization.ZigBeeDeserializer)1 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1