use of org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor 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;
}
}
use of org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor in project openhab1-addons by openhab.
the class ZWaveController method handleIncomingRequestMessage.
/**
* Handles an incoming request message.
* An incoming request message is a message initiated by a node or the controller.
*
* @param incomingMessage the incoming message to process.
*/
private void handleIncomingRequestMessage(SerialMessage incomingMessage) {
logger.trace("Incoming Message type = REQUEST");
ZWaveCommandProcessor processor = ZWaveCommandProcessor.getMessageDispatcher(incomingMessage.getMessageClass());
if (processor == null) {
logger.warn(String.format("TODO: Implement processing of Request Message = %s (0x%02X)", incomingMessage.getMessageClass().getLabel(), incomingMessage.getMessageClass().getKey()));
return;
}
boolean result = processor.handleRequest(this, lastSentMessage, incomingMessage);
if (processor.isTransactionComplete()) {
notifyEventListeners(new ZWaveTransactionCompletedEvent(this.lastSentMessage, result));
transactionCompleted.release();
logger.trace("Released. Transaction completed permit count -> {}", transactionCompleted.availablePermits());
}
}
Aggregations