Search in sources :

Example 6 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent in project openhab1-addons by openhab.

the class AssignReturnRouteMessageClass method handleRequest.

@Override
public boolean handleRequest(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) {
    int nodeId = lastSentMessage.getMessagePayloadByte(0);
    logger.debug("NODE {}: Got AssignReturnRoute request.", nodeId);
    if (incomingMessage.getMessagePayloadByte(1) != 0x00) {
        logger.error("NODE {}: Assign return routes failed.", nodeId);
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignReturnRoute, nodeId, ZWaveNetworkEvent.State.Failure));
    } else {
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignReturnRoute, nodeId, ZWaveNetworkEvent.State.Success));
    }
    checkTransactionComplete(lastSentMessage, incomingMessage);
    return true;
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)

Example 7 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent in project openhab1-addons by openhab.

the class AssignReturnRouteMessageClass method handleResponse.

@Override
public boolean handleResponse(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) {
    int nodeId = lastSentMessage.getMessagePayloadByte(0);
    logger.debug("NODE {}: Got AssignReturnRoute response.", nodeId);
    if (incomingMessage.getMessagePayloadByte(0) != 0x00) {
        logger.debug("NODE {}: AssignReturnRoute command in progress.", nodeId);
    } else {
        logger.error("NODE {}: AssignReturnRoute command failed.", nodeId);
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignReturnRoute, nodeId, ZWaveNetworkEvent.State.Failure));
        incomingMessage.setTransactionCanceled();
    }
    return true;
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)

Example 8 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent in project openhab1-addons by openhab.

the class AssignSucReturnRouteMessageClass method handleResponse.

@Override
public boolean handleResponse(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) {
    int nodeId = lastSentMessage.getMessagePayloadByte(0);
    logger.debug("NODE {}: Got AssignSucReturnRoute response.", nodeId);
    if (incomingMessage.getMessagePayloadByte(0) != 0x00) {
        logger.debug("NODE {}: AssignSucReturnRoute operation started.", nodeId);
    } else {
        logger.error("NODE {}: AssignSucReturnRoute command failed.", nodeId);
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignSucReturnRoute, nodeId, ZWaveNetworkEvent.State.Failure));
    }
    checkTransactionComplete(lastSentMessage, incomingMessage);
    return true;
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)

Example 9 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent in project openhab1-addons by openhab.

the class AssignSucReturnRouteMessageClass method handleRequest.

@Override
public boolean handleRequest(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) {
    int nodeId = lastSentMessage.getMessagePayloadByte(0);
    logger.debug("NODE {}: Got AssignSucReturnRoute request.", nodeId);
    if (incomingMessage.getMessagePayloadByte(1) != 0x00) {
        logger.error("NODE {}: Assign SUC return routes failed with error 0x{}.", nodeId, Integer.toHexString(incomingMessage.getMessagePayloadByte(1)));
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignSucReturnRoute, nodeId, ZWaveNetworkEvent.State.Failure));
        return false;
    } else {
        zController.notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssignSucReturnRoute, nodeId, ZWaveNetworkEvent.State.Success));
        return true;
    }
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)

Example 10 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent in project openhab1-addons by openhab.

the class ZWaveNetworkMonitor method ZWaveIncomingEvent.

/**
     * Capture events that might be useful during the heal process We need to
     * know when a network event happens - these are specific events that are
     * used in the heal process (routing etc). We need to know if a device wakes
     * up so we can heal it (if needed) We need to know when a PING transaction
     * completes.
     */
@Override
public void ZWaveIncomingEvent(ZWaveEvent event) {
    // Handle network events
    if (event instanceof ZWaveNetworkEvent) {
        ZWaveNetworkEvent nwEvent = (ZWaveNetworkEvent) event;
        // Get the heal class for this notification
        HealNode node = healNodes.get(nwEvent.getNodeId());
        if (node == null) {
            return;
        }
        // Is this the event we're waiting for
        if (nwEvent.getEvent() != node.event) {
            return;
        }
        switch(nwEvent.getState()) {
            case Success:
                node.retryCnt = 0;
                node.state = node.stateNext;
                break;
            case Failure:
                logger.debug("NODE {}: Network heal received FAILURE event", node.nodeId);
                break;
        }
        // been a successful route set - remove this node
        if (node.retryCnt == 0 && node.routeList != null && node.routeList.size() > 0) {
            node.routeList.remove(0);
        }
        // Continue....
        nextHealStage(node);
    } else if (event instanceof ZWaveTransactionCompletedEvent) {
        SerialMessage serialMessage = ((ZWaveTransactionCompletedEvent) event).getCompletedMessage();
        if (serialMessage.getMessageClass() != SerialMessageClass.SendData && serialMessage.getMessageType() != SerialMessageType.Request) {
            return;
        }
        byte[] payload = serialMessage.getMessagePayload();
        if (payload.length < 3) {
            return;
        }
        HealNode node = healNodes.get(payload[0] & 0xFF);
        if (node == null) {
            return;
        }
        // See if this node is waiting for a PING
        if (node.state == HealState.PING && payload.length >= 3 && (payload[2] & 0xFF) == ZWaveCommandClass.CommandClass.NO_OPERATION.getKey()) {
            node.state = node.stateNext;
            node.retryCnt = 0;
            nextHealStage(node);
            return;
        }
    } else if (event instanceof ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) {
        // We only care about the wake-up notification
        if (((ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) event).getEvent() != ZWaveWakeUpCommandClass.WAKE_UP_NOTIFICATION) {
            return;
        }
        // A wakeup event is received. Find the node in the node list
        HealNode node = healNodes.get(event.getNodeId());
        if (node == null) {
            return;
        }
        // and only process if there's something to do
        if (!node.state.isActive()) {
            return;
        }
        logger.debug("NODE {}: Heal WakeUp EVENT {}", node.nodeId, node.state);
        nextHealStage(node);
    } else if (event instanceof ZWaveNodeStatusEvent) {
        ZWaveNodeStatusEvent statusEvent = (ZWaveNodeStatusEvent) event;
        logger.debug("NODE {}: Node Status event - Node is {}", statusEvent.getNodeId(), statusEvent.getState());
        switch(statusEvent.getState()) {
            case DEAD:
            case FAILED:
                ZWaveNode node = zController.getNode(statusEvent.getNodeId());
                if (node == null) {
                    logger.error("NODE {}: Status event received, but node not found.", statusEvent.getNodeId());
                    return;
                }
                // If this is a DEAD notification, then ask the controller if it's really FAILED
                if (statusEvent.getState() == ZWaveNodeState.DEAD) {
                    zController.requestIsFailedNode(node.getNodeId());
                }
                // The node is dead, but we may have already started a Heal
                // If so, it won't be started again!
                startNodeHeal(node.getNodeId());
                break;
            case ALIVE:
                break;
        }
    } else if (event instanceof ZWaveInitializationCompletedEvent) {
        logger.debug("Network initialised - starting network monitor.");
        // Remember that we've initialised the binding.
        initialised = true;
        // Calculate the next heal time
        networkHealNightlyTime = calculateNextHeal();
        networkHealNextTime = networkHealNightlyTime;
        // Set the next PING time
        pingNodeTime = System.currentTimeMillis() + pollPeriod;
    }
}
Also used : ZWaveNodeStatusEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent) ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent) ZWaveTransactionCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveInitializationCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveInitializationCompletedEvent) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)

Aggregations

ZWaveNetworkEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)12 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)2 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)2 ZWaveNodeStatusEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent)2 ArrayList (java.util.ArrayList)1 AssociationGroup (org.openhab.binding.zwave.internal.protocol.AssociationGroup)1 ZWaveEndpoint (org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)1 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)1 ZWaveInclusionEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveInclusionEvent)1 ZWaveInitializationCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveInitializationCompletedEvent)1 ZWaveTransactionCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent)1 ZWaveNodeSerializer (org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer)1