-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZWave add network update method (#1162)
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ding/zwave/test/internal/protocol/serialmessage/RequestNetworkUpdateMessageClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...enhab/binding/zwave/internal/protocol/serialmessage/RequestNetworkUpdateMessageClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters