Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZWave add network update method #1162

Merged
merged 1 commit into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
</options>
</parameter>

<parameter name="controller_sync" type="integer" groupName="actions">
<label>Synchronize network</label>
<description>Download the network with the SUC</description>
<advanced>true</advanced>
<default>0</default>
<options>
<option value="-232323">send</option>
</options>
</parameter>

<parameter name="inclusion_mode" type="integer" groupName="network">
<label>Inclusion Mode</label>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public void handleConfigurationUpdate(Map<String, Object> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -1205,7 +1215,7 @@ public boolean hasApiCapability(SerialMessageClass capability) {

/**
* Returns the secure inclusion mode
*
*
* @return
* 0 ENTRY_CONTROL
* 1 All Devices
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down