use of org.openhab.binding.zwave.internal.protocol.SerialMessage in project openhab1-addons by openhab.
the class ZWaveClockCommandClass method getValueMessage.
/**
* Gets a SerialMessage with the CLOCK_GET command
*
* @return the serial message.
*/
@Override
public SerialMessage getValueMessage() {
logger.debug("NODE {}: Creating new message for command CLOCK_GET", getNode().getNodeId());
SerialMessage result = new SerialMessage(getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Get);
ByteArrayOutputStream outputData = new ByteArrayOutputStream();
outputData.write(getNode().getNodeId());
outputData.write(2);
outputData.write(getCommandClass().getKey());
outputData.write(CLOCK_GET);
result.setMessagePayload(outputData.toByteArray());
return result;
}
use of org.openhab.binding.zwave.internal.protocol.SerialMessage in project openhab1-addons by openhab.
the class ZWaveConfigurationCommandClass method getConfigMessage.
/**
* Gets a SerialMessage with the CONFIGURATIONCMD_GET command
*
* @return the serial message
*/
public SerialMessage getConfigMessage(int parameter) {
// Check if the parameter exists in our list
ConfigurationParameter configurationParameter = this.configParameters.get(parameter);
if (configurationParameter != null && configurationParameter.getWriteOnly() == true) {
logger.debug("NODE {}: CONFIGURATIONCMD_GET ignored for parameter {} - parameter is write only", this.getNode().getNodeId(), parameter);
return null;
}
logger.debug("NODE {}: Creating new message for application command CONFIGURATIONCMD_GET", this.getNode().getNodeId());
SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Config);
byte[] newPayload = { (byte) this.getNode().getNodeId(), 3, (byte) getCommandClass().getKey(), (byte) CONFIGURATIONCMD_GET, (byte) (parameter & 0xff) };
result.setMessagePayload(newPayload);
return result;
}
use of org.openhab.binding.zwave.internal.protocol.SerialMessage in project openhab1-addons by openhab.
the class ZWaveNodeStageAdvancer method ZWaveIncomingEvent.
@Override
public void ZWaveIncomingEvent(ZWaveEvent event) {
// If we've already completed initialisation, then we're done!
if (currentStage == ZWaveNodeInitStage.DONE) {
return;
}
// Process transaction complete events
if (event instanceof ZWaveTransactionCompletedEvent) {
ZWaveTransactionCompletedEvent completeEvent = (ZWaveTransactionCompletedEvent) event;
SerialMessage serialMessage = completeEvent.getCompletedMessage();
byte[] payload = serialMessage.getMessagePayload();
// Make sure this is addressed to us
if (payload.length == 0 || node.getNodeId() != (payload[0] & 0xFF)) {
// This will allow battery devices stuck in WAIT state to get moving.
if (controller.getSendQueueLength() < 2 && currentStage == ZWaveNodeInitStage.WAIT) {
logger.debug("NODE {}: Node advancer - WAIT: The WAIT is over!", node.getNodeId());
currentStage = currentStage.getNextStage();
handleNodeQueue(null);
}
return;
}
switch(serialMessage.getMessageClass()) {
case SendData:
case IdentifyNode:
case RequestNodeInfo:
case GetRoutingInfo:
case IsFailedNodeID:
logger.debug("NODE {}: Node advancer - {}: Transaction complete ({}:{}) success({})", node.getNodeId(), currentStage.toString(), serialMessage.getMessageClass(), serialMessage.getMessageType(), completeEvent.getState());
// If this frame was successfully sent, then handle the stage advancer
if (((ZWaveTransactionCompletedEvent) event).getState() == true) {
handleNodeQueue(serialMessage);
}
break;
default:
break;
}
} else if (event instanceof ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) {
// WAKEUP EVENT - only act if this is a wakeup notification
if (((ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) event).getEvent() != ZWaveWakeUpCommandClass.WAKE_UP_NOTIFICATION) {
return;
}
// A wakeup event is received. Make sure it's for this node
if (node.getNodeId() != event.getNodeId()) {
return;
}
logger.debug("NODE {}: Wakeup during initialisation.", node.getNodeId());
wakeupCount++;
advanceNodeStage(null);
} else if (event instanceof ZWaveNodeStatusEvent) {
ZWaveNodeStatusEvent statusEvent = (ZWaveNodeStatusEvent) event;
// A network status event is received. Make sure it's for this node.
if (node.getNodeId() != event.getNodeId()) {
return;
}
logger.debug("NODE {}: Node Status event during initialisation - Node is {}", statusEvent.getNodeId(), statusEvent.getState());
switch(statusEvent.getState()) {
case DEAD:
case FAILED:
break;
case ALIVE:
advanceNodeStage(null);
break;
}
logger.trace("NODE {}: Node Status event during initialisation processed", statusEvent.getNodeId());
} else if (event instanceof ZWaveNodeInfoEvent) {
logger.debug("NODE {}: {} NIF event during initialisation stage {}", event.getNodeId(), node.getNodeId(), currentStage);
if (node.getNodeId() != event.getNodeId()) {
return;
}
if (currentStage == ZWaveNodeInitStage.PING) {
logger.debug("NODE {}: NIF event during initialisation stage PING - advancing", event.getNodeId());
setCurrentStage(currentStage.getNextStage());
}
logger.debug("NODE {}: NIF event during initialisation stage {}", event.getNodeId(), currentStage);
advanceNodeStage(null);
/*
* } else if (event instanceof ZWaveCommandClassValueEvent) {
* // This code is used to detect an event during the IDLE stage.
* // This is used to kick start the initialisation for battery nodes that do not support
* // the WAKE_UP class and don't send the ApplicationUpdateMessage when they are initialised.
* logger.debug("NODE {}: {} CC event during initialisation stage {}", event.getNodeId(), node.getNodeId(),
* currentStage);
* // A command class event is received. Make sure it's for this node.
* if (node.getNodeId() != event.getNodeId() || currentStage != ZWaveNodeInitStage.PING) {
* return;
* }
* logger.debug("NODE {}: CC event during initialisation stage PING - advancing", event.getNodeId());
* setCurrentStage(currentStage.getNextStage());
* logger.debug("NODE {}: CC event during initialisation stage PING - now {} - next", event.getNodeId(),
* currentStage);
* advanceNodeStage(null);
*/
}
}
use of org.openhab.binding.zwave.internal.protocol.SerialMessage in project openhab1-addons by openhab.
the class AddNodeMessageClass method doRequestStop.
public SerialMessage doRequestStop() {
logger.debug("Ending INCLUSION mode.");
// Queue the request
SerialMessage newMessage = new SerialMessage(SerialMessage.SerialMessageClass.AddNodeToNetwork, SerialMessage.SerialMessageType.Request, SerialMessage.SerialMessageClass.AddNodeToNetwork, SerialMessage.SerialMessagePriority.High);
byte[] newPayload = { (byte) ADD_NODE_STOP };
newMessage.setMessagePayload(newPayload);
return newMessage;
}
use of org.openhab.binding.zwave.internal.protocol.SerialMessage in project openhab1-addons by openhab.
the class AddNodeMessageClass method doRequestStart.
public SerialMessage doRequestStart(boolean highPower) {
logger.debug("Setting controller into INCLUSION mode.");
// Queue the request
SerialMessage newMessage = new SerialMessage(SerialMessage.SerialMessageClass.AddNodeToNetwork, SerialMessage.SerialMessageType.Request, SerialMessage.SerialMessageClass.AddNodeToNetwork, SerialMessage.SerialMessagePriority.High);
byte[] newPayload = { (byte) ADD_NODE_ANY, (byte) 255 };
if (highPower == true) {
newPayload[0] |= OPTION_HIGH_POWER;
}
newMessage.setMessagePayload(newPayload);
return newMessage;
}
Aggregations