Search in sources :

Example 1 with SerialApiGetInitDataMessageClass

use of org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass 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;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SetSucNodeMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.SetSucNodeMessageClass) SerialApiGetInitDataMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass) ZWaveTransactionCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent) GetControllerCapabilitiesMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.GetControllerCapabilitiesMessageClass) ZWaveCommandProcessor(org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor) EnableSucMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.EnableSucMessageClass)

Example 2 with SerialApiGetInitDataMessageClass

use of org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass in project openhab1-addons by openhab.

the class ZWaveController method requestHardReset.

/**
     * Sends a request to perform a hard reset on the controller.
     * This will reset the controller to its default, resetting the network completely
     */
public void requestHardReset() {
    logger.info("Performing hard reset on controller");
    // Clear the queues
    // If we're resetting, there's no point in queuing messages!
    sendQueue.clear();
    recvQueue.clear();
    // Hard reset the stick - everything will be reset to factory default
    SerialMessage msg = new ControllerSetDefaultMessageClass().doRequest();
    msg.attempts = 1;
    this.enqueue(msg);
    // Clear all the nodes and we'll reinitialise
    this.zwaveNodes.clear();
    this.enqueue(new SerialApiGetInitDataMessageClass().doRequest());
}
Also used : ControllerSetDefaultMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.ControllerSetDefaultMessageClass) SerialApiGetInitDataMessageClass(org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass)

Aggregations

SerialApiGetInitDataMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.SerialApiGetInitDataMessageClass)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ZWaveTransactionCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent)1 ControllerSetDefaultMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.ControllerSetDefaultMessageClass)1 EnableSucMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.EnableSucMessageClass)1 GetControllerCapabilitiesMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.GetControllerCapabilitiesMessageClass)1 SetSucNodeMessageClass (org.openhab.binding.zwave.internal.protocol.serialmessage.SetSucNodeMessageClass)1 ZWaveCommandProcessor (org.openhab.binding.zwave.internal.protocol.serialmessage.ZWaveCommandProcessor)1