Search in sources :

Example 1 with AsynchronousCommandListener

use of com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener in project com.zsmartsystems.zigbee by zsmartsystems.

the class CommandInterfaceImpl method notifySynchronousCommand.

/**
 * Notifies listeners about synchronous command response.
 *
 * @param packet the received packet
 */
private void notifySynchronousCommand(final ZToolPacket packet) {
    final DoubleByte cmdId = packet.getCMD();
    synchronized (synchronousCommandListeners) {
        final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
        final SynchronousCommandListener listener = synchronousCommandListeners.get(id);
        if (listener != null) {
            listener.receivedCommandResponse(packet);
            synchronousCommandListeners.remove(id);
            synchronousCommandListeners.notifyAll();
        } else {
            // Notify asynchronous command listeners of unclaimed asynchronous command responses.
            final AsynchronousCommandListener[] listeners;
            synchronized (asynchrounsCommandListeners) {
                listeners = asynchrounsCommandListeners.toArray(new AsynchronousCommandListener[] {});
            }
            for (final AsynchronousCommandListener asynchronousCommandListener : listeners) {
                try {
                    asynchronousCommandListener.receivedUnclaimedSynchronousCommandResponse(packet);
                } catch (Throwable e) {
                    logger.error("Error in incoming asynchronous message processing: ", e);
                }
            }
        }
    }
}
Also used : SynchronousCommandListener(com.zsmartsystems.zigbee.dongle.cc2531.network.SynchronousCommandListener) AsynchronousCommandListener(com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener) DoubleByte(com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util.DoubleByte)

Example 2 with AsynchronousCommandListener

use of com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener in project com.zsmartsystems.zigbee by zsmartsystems.

the class CommandInterfaceImpl method notifyAsynchronousCommand.

/**
 * Notifies listeners about asynchronous message.
 *
 * @param packet the packet containing the message
 */
private void notifyAsynchronousCommand(final ZToolPacket packet) {
    final AsynchronousCommandListener[] listeners;
    synchronized (asynchrounsCommandListeners) {
        listeners = asynchrounsCommandListeners.toArray(new AsynchronousCommandListener[] {});
    }
    logger.debug("Received Async Cmd: {}", packet);
    for (final AsynchronousCommandListener listener : listeners) {
        try {
            listener.receivedAsynchronousCommand(packet);
        } catch (Throwable e) {
            logger.error("Error in incoming asynchronous message processing: ", e);
        }
    }
}
Also used : AsynchronousCommandListener(com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener)

Aggregations

AsynchronousCommandListener (com.zsmartsystems.zigbee.dongle.cc2531.network.AsynchronousCommandListener)2 SynchronousCommandListener (com.zsmartsystems.zigbee.dongle.cc2531.network.SynchronousCommandListener)1 DoubleByte (com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util.DoubleByte)1