Search in sources :

Example 1 with EnableSucMessageClass

use of org.openhab.binding.zwave.internal.protocol.serialmessage.EnableSucMessageClass in project openhab1-addons by openhab.

the class ZWaveController method handleIncomingResponseMessage.

/**
     * Handles an incoming response message.
     * An incoming response message is a response, based one of our own requests.
     *
     * @param incomingMessage the response message to process.
     */
private void handleIncomingResponseMessage(SerialMessage incomingMessage) {
    logger.trace("Incoming Message type = RESPONSE");
    ZWaveCommandProcessor processor = ZWaveCommandProcessor.getMessageDispatcher(incomingMessage.getMessageClass());
    if (processor == null) {
        logger.warn(String.format("TODO: Implement processing of Response Message = %s (0x%02X)", incomingMessage.getMessageClass().getLabel(), incomingMessage.getMessageClass().getKey()));
        return;
    }
    boolean result = processor.handleResponse(this, lastSentMessage, incomingMessage);
    if (processor.isTransactionComplete()) {
        notifyEventListeners(new ZWaveTransactionCompletedEvent(this.lastSentMessage, result));
        transactionCompleted.release();
        logger.trace("Released. Transaction completed permit count -> {}", transactionCompleted.availablePermits());
    }
    switch(incomingMessage.getMessageClass()) {
        case GetVersion:
            this.zWaveVersion = ((GetVersionMessageClass) processor).getVersion();
            this.ZWaveLibraryType = ((GetVersionMessageClass) processor).getLibraryType();
            break;
        case MemoryGetId:
            this.ownNodeId = ((MemoryGetIdMessageClass) processor).getNodeId();
            this.homeId = ((MemoryGetIdMessageClass) processor).getHomeId();
            break;
        case SerialApiGetInitData:
            this.isConnected = true;
            for (Integer nodeId : ((SerialApiGetInitDataMessageClass) processor).getNodes()) {
                addNode(nodeId);
            }
            break;
        case GetSucNodeId:
            // Remember the SUC ID
            this.sucID = ((GetSucNodeIdMessageClass) processor).getSucNodeId();
            // If we want to be the SUC, enable it here
            if (this.setSUC == true && this.sucID == 0) {
                // We want to be SUC
                this.enqueue(new EnableSucMessageClass().doRequest(EnableSucMessageClass.SUCType.SERVER));
                this.enqueue(new SetSucNodeMessageClass().doRequest(this.ownNodeId, SetSucNodeMessageClass.SUCType.SERVER));
            } else if (this.setSUC == false && this.sucID == this.ownNodeId) {
                // We don't want to be SUC, but we currently are!
                // Disable SERVER functionality, and set the node to 0
                this.enqueue(new EnableSucMessageClass().doRequest(EnableSucMessageClass.SUCType.NONE));
                this.enqueue(new SetSucNodeMessageClass().doRequest(this.ownNodeId, SetSucNodeMessageClass.SUCType.NONE));
            }
            this.enqueue(new GetControllerCapabilitiesMessageClass().doRequest());
            break;
        case SerialApiGetCapabilities:
            this.serialAPIVersion = ((SerialApiGetCapabilitiesMessageClass) processor).getSerialAPIVersion();
            this.manufactureId = ((SerialApiGetCapabilitiesMessageClass) processor).getManufactureId();
            this.deviceId = ((SerialApiGetCapabilitiesMessageClass) processor).getDeviceId();
            this.deviceType = ((SerialApiGetCapabilitiesMessageClass) processor).getDeviceType();
            this.enqueue(new SerialApiGetInitDataMessageClass().doRequest());
            break;
        case GetControllerCapabilities:
            this.controllerType = ((GetControllerCapabilitiesMessageClass) processor).getDeviceType();
            break;
        default:
            break;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SetSucNodeMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.SetSucNodeMessageClass) SerialApiGetInitDataMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass) ZWaveTransactionCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent) GetControllerCapabilitiesMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.GetControllerCapabilitiesMessageClass) ZWaveCommandProcessor(org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor) EnableSucMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.EnableSucMessageClass)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ZWaveTransactionCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent)1 EnableSucMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.EnableSucMessageClass)1 GetControllerCapabilitiesMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.GetControllerCapabilitiesMessageClass)1 SerialApiGetInitDataMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass)1 SetSucNodeMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.SetSucNodeMessageClass)1 ZWaveCommandProcessor (org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor)1