From 5db0da6582afb2a02bb1f5d9e4323d0b67b8701d Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Thu, 28 Jul 2016 22:50:18 +0100 Subject: [PATCH] ZWave add network update method Signed-off-by: Chris Jackson --- .../RequestNetworkUpdateMessageClassTest.java | 22 +++++ .../ESH-INF/thing/_controller_serial.xml | 10 ++ .../zwave/handler/ZWaveControllerHandler.java | 4 + .../internal/protocol/ZWaveController.java | 12 ++- .../RequestNetworkUpdateMessageClass.java | 95 +++++++++++++++++++ .../serialmessage/ZWaveCommandProcessor.java | 2 + 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 addons/binding/org.openhab.binding.zwave.test/src/test/java/org/openhab/binding/zwave/test/internal/protocol/serialmessage/RequestNetworkUpdateMessageClassTest.java create mode 100644 addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/RequestNetworkUpdateMessageClass.java diff --git a/addons/binding/org.openhab.binding.zwave.test/src/test/java/org/openhab/binding/zwave/test/internal/protocol/serialmessage/RequestNetworkUpdateMessageClassTest.java b/addons/binding/org.openhab.binding.zwave.test/src/test/java/org/openhab/binding/zwave/test/internal/protocol/serialmessage/RequestNetworkUpdateMessageClassTest.java new file mode 100644 index 0000000000000..dd0aa96169b0c --- /dev/null +++ b/addons/binding/org.openhab.binding.zwave.test/src/test/java/org/openhab/binding/zwave/test/internal/protocol/serialmessage/RequestNetworkUpdateMessageClassTest.java @@ -0,0 +1,22 @@ +package org.openhab.binding.zwave.test.internal.protocol.serialmessage; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; +import org.openhab.binding.zwave.internal.protocol.SerialMessage; +import org.openhab.binding.zwave.internal.protocol.serialmessage.RequestNetworkUpdateMessageClass; + +public class RequestNetworkUpdateMessageClassTest { + @Test + public void doRequest() { + byte[] expectedResponse = { 0x01, 0x04, 0x00, 0x53, 0x01, (byte) 0xA9 }; + + RequestNetworkUpdateMessageClass handler = new RequestNetworkUpdateMessageClass(); + SerialMessage msg = handler.doRequest(); + msg.setCallbackId(1); + + assertTrue(Arrays.equals(msg.getMessageBuffer(), expectedResponse)); + } +} diff --git a/addons/binding/org.openhab.binding.zwave/ESH-INF/thing/_controller_serial.xml b/addons/binding/org.openhab.binding.zwave/ESH-INF/thing/_controller_serial.xml index cf4a5fc76c612..8ea677d75c677 100644 --- a/addons/binding/org.openhab.binding.zwave/ESH-INF/thing/_controller_serial.xml +++ b/addons/binding/org.openhab.binding.zwave/ESH-INF/thing/_controller_serial.xml @@ -135,6 +135,16 @@ + + + Download the network with the SUC + true + 0 + + + + + diff --git a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/handler/ZWaveControllerHandler.java b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/handler/ZWaveControllerHandler.java index f4ad5707bf7eb..7f23dc00805c5 100644 --- a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/handler/ZWaveControllerHandler.java +++ b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/handler/ZWaveControllerHandler.java @@ -227,6 +227,10 @@ public void handleConfigurationUpdate(Map configurationParameter && ((BigDecimal) value).intValue() == ZWaveBindingConstants.ACTION_CHECK_VALUE) { controller.requestRemoveNodesStart(); value = ""; + } else if (cfg[1].equals("sync") && value instanceof BigDecimal + && ((BigDecimal) value).intValue() == ZWaveBindingConstants.ACTION_CHECK_VALUE) { + controller.requestRequestNetworkUpdate(); + value = ""; } else if (cfg[1].equals("suc") && value instanceof Boolean) { // TODO: Do we need to set this immediately } diff --git a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/ZWaveController.java b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/ZWaveController.java index c28e879253a48..fbfc3365d10d3 100644 --- a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/ZWaveController.java +++ b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/ZWaveController.java @@ -57,6 +57,7 @@ import org.openhab.binding.zwave.internal.protocol.serialmessage.RemoveFailedNodeMessageClass; import org.openhab.binding.zwave.internal.protocol.serialmessage.RemoveNodeMessageClass; import org.openhab.binding.zwave.internal.protocol.serialmessage.ReplaceFailedNodeMessageClass; +import org.openhab.binding.zwave.internal.protocol.serialmessage.RequestNetworkUpdateMessageClass; import org.openhab.binding.zwave.internal.protocol.serialmessage.RequestNodeInfoMessageClass; import org.openhab.binding.zwave.internal.protocol.serialmessage.RequestNodeNeighborUpdateMessageClass; import org.openhab.binding.zwave.internal.protocol.serialmessage.SendDataMessageClass; @@ -863,6 +864,15 @@ public void requestRemoveNodesStart() { logger.debug("ZWave controller start exclusion"); } + /** + * Requests a network update + * + */ + public void requestRequestNetworkUpdate() { + enqueue(new RequestNetworkUpdateMessageClass().doRequest()); + logger.debug("ZWave controller request network update"); + } + /** * Terminates the exclusion mode * @@ -1205,7 +1215,7 @@ public boolean hasApiCapability(SerialMessageClass capability) { /** * Returns the secure inclusion mode - * + * * @return * 0 ENTRY_CONTROL * 1 All Devices diff --git a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/RequestNetworkUpdateMessageClass.java b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/RequestNetworkUpdateMessageClass.java new file mode 100644 index 0000000000000..d5c1c564707c3 --- /dev/null +++ b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/RequestNetworkUpdateMessageClass.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2014-2016 by the respective copyright holders. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.openhab.binding.zwave.internal.protocol.serialmessage; + +import org.openhab.binding.zwave.internal.protocol.SerialMessage; +import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageClass; +import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessagePriority; +import org.openhab.binding.zwave.internal.protocol.SerialMessage.SerialMessageType; +import org.openhab.binding.zwave.internal.protocol.ZWaveController; +import org.openhab.binding.zwave.internal.protocol.ZWaveSerialMessageException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class processes a serial message from the zwave controller + * + * @author Chris Jackson + */ +public class RequestNetworkUpdateMessageClass extends ZWaveCommandProcessor { + private static final Logger logger = LoggerFactory.getLogger(RequestNetworkUpdateMessageClass.class); + + private final int ZW_SUC_UPDATE_DONE = 0x00; + private final int ZW_SUC_UPDATE_ABORT = 0x01; + private final int ZW_SUC_UPDATE_WAIT = 0x02; + private final int ZW_SUC_UPDATE_DISABLED = 0x03; + private final int ZW_SUC_UPDATE_OVERFLOW = 0x04; + + public SerialMessage doRequest() { + logger.debug("Request network update."); + + // Queue the request + SerialMessage newMessage = new SerialMessage(SerialMessageClass.RequestNetworkUpdate, SerialMessageType.Request, + SerialMessageClass.RequestNetworkUpdate, SerialMessagePriority.High); + byte[] newPayload = { (byte) 0x01 }; + newMessage.setMessagePayload(newPayload); + return newMessage; + } + + @Override + public boolean handleResponse(ZWaveController zController, SerialMessage lastSentMessage, + SerialMessage incomingMessage) throws ZWaveSerialMessageException { + logger.debug("Got RequestNetworkUpdate response."); + + if (incomingMessage.getMessagePayloadByte(0) == 0x01) { + logger.debug("RequestNetworkUpdate started."); + } else { + logger.warn("RequestNetworkUpdate not placed on stack."); + transactionComplete = true; + } + + return true; + } + + @Override + public boolean handleRequest(ZWaveController zController, SerialMessage lastSentMessage, + SerialMessage incomingMessage) throws ZWaveSerialMessageException { + + logger.debug("Got ReplaceFailedNode request."); + switch (incomingMessage.getMessagePayloadByte(1)) { + case ZW_SUC_UPDATE_DONE: + // The node is working properly (removed from the failed nodes list). Replace process is stopped. + logger.debug("Network updated."); + transactionComplete = true; + break; + case ZW_SUC_UPDATE_ABORT: + logger.error("The update process aborted because of an error."); + transactionComplete = true; + break; + case ZW_SUC_UPDATE_WAIT: + logger.error("The SUC node is busy."); + transactionComplete = true; + break; + case ZW_SUC_UPDATE_DISABLED: + logger.error("The SUC functionality is disabled."); + transactionComplete = true; + break; + case ZW_SUC_UPDATE_OVERFLOW: + logger.error("The SUC node is busy."); + transactionComplete = true; + break; + default: + logger.info("The controller requested an update after more than 64 changes"); + transactionComplete = true; + break; + } + + return true; + } +} diff --git a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/ZWaveCommandProcessor.java b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/ZWaveCommandProcessor.java index 89d9f404a858a..951be5445b236 100644 --- a/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/ZWaveCommandProcessor.java +++ b/addons/binding/org.openhab.binding.zwave/src/main/java/org/openhab/binding/zwave/internal/protocol/serialmessage/ZWaveCommandProcessor.java @@ -176,6 +176,8 @@ public static ZWaveCommandProcessor getMessageDispatcher(SerialMessage.SerialMes messageMap.put(SerialMessage.SerialMessageClass.IsFailedNodeID, IsFailedNodeMessageClass.class); messageMap.put(SerialMessage.SerialMessageClass.RemoveNodeFromNetwork, RemoveNodeMessageClass.class); messageMap.put(SerialMessage.SerialMessageClass.ReplaceFailedNode, ReplaceFailedNodeMessageClass.class); + messageMap.put(SerialMessage.SerialMessageClass.RequestNetworkUpdate, + RequestNetworkUpdateMessageClass.class); messageMap.put(SerialMessage.SerialMessageClass.RequestNodeInfo, RequestNodeInfoMessageClass.class); messageMap.put(SerialMessage.SerialMessageClass.RequestNodeNeighborUpdate, RequestNodeNeighborUpdateMessageClass.class);