Search in sources :

Example 91 with SerialMessage

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;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 92 with SerialMessage

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;
}
Also used : ConfigurationParameter(org.openhab.binding.zwave.internal.protocol.ConfigurationParameter) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 93 with SerialMessage

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);
             */
    }
}
Also used : ZWaveNodeStatusEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent) ZWaveTransactionCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ZWaveNodeInfoEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeInfoEvent) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)

Example 94 with SerialMessage

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;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 95 with SerialMessage

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;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Aggregations

SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)125 State (org.openhab.core.types.State)12 ZWaveEndpoint (org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 HashMap (java.util.HashMap)5 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)5 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ConfigurationParameter (org.openhab.binding.zwave.internal.protocol.ConfigurationParameter)3 SecurityEncapsulatedSerialMessage (org.openhab.binding.zwave.internal.protocol.SecurityEncapsulatedSerialMessage)3 ZWaveCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ZWaveDbConfigurationParameter (org.openhab.binding.zwave.internal.config.ZWaveDbConfigurationParameter)2 ZWaveProductDatabase (org.openhab.binding.zwave.internal.config.ZWaveProductDatabase)2 MultiLevelPercentCommandConverter (org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)2 ZWaveAssociationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass)2 ZWaveConfigurationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass)2 ZWaveNetworkEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)2