Search in sources :

Example 11 with SerialMessage

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

the class ZWaveUserCodeCommandClass method buildGetMessage.

public SerialMessage buildGetMessage(int type, Integer... argBytes) {
    if (type != USER_NUMBER_GET && type != USER_CODE_GET) {
        logger.error("NODE {}: Called buildGetMessage with invalid type of {}", this.getNode().getNodeId(), (0xff & type));
        return null;
    }
    logger.debug("NODE {}: Creating new message for application command USER_CODE {}", this.getNode().getNodeId(), (0xff & type));
    SerialMessage message = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Get);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write((byte) this.getNode().getNodeId());
    baos.write(2 + argBytes.length);
    baos.write((byte) getCommandClass().getKey());
    baos.write((byte) (type & 0xff));
    for (Integer aArgByte : argBytes) {
        baos.write((byte) (0xff & aArgByte));
    }
    message.setMessagePayload(baos.toByteArray());
    return message;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with SerialMessage

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

the class ZWaveUserCodeCommandClass method getDynamicValues.

@Override
public Collection<SerialMessage> getDynamicValues(boolean refresh) {
    logger.debug("NODE {}: User Code initialize starting, refresh={}", getNode().getNodeId());
    Collection<SerialMessage> result = new ArrayList<SerialMessage>();
    if (refresh == true) {
        if (numberOfUsersSupported == ZWaveUserCodeCommandClass.UNKNOWN) {
            // Request it and wait for response
            logger.debug("NODE {}: numberOfUsersSupported=-1, refreshing}", getNode().getNodeId());
            SerialMessage message = buildGetMessage(ZWaveUserCodeCommandClass.USER_NUMBER_GET);
            result.add(message);
        // when we receive USER_NUMBER_REPORT it will kickoff syncUserCodes();
        } else if (numberOfUsersSupported == 0) {
            logger.error("NODE {}: door lock does not support any user codes, no codes set", getNode().getNodeId());
        } else {
            syncUserCodes();
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 13 with SerialMessage

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

the class ZWaveWakeUpCommandClass method setAwake.

/**
     * Sets whether the node is awake.
     * If the node is awake we send the first message in the wake-up queue.
     * The remaining messages are triggered within the notification handler
     *
     * @param isAwake the isAwake to set
     */
public void setAwake(boolean isAwake) {
    this.isAwake = isAwake;
    if (isAwake) {
        logger.debug("NODE {}: Is awake with {} messages in the wake-up queue.", this.getNode().getNodeId(), this.wakeUpQueue.size());
        this.lastWakeup = Calendar.getInstance().getTime();
        ZWaveWakeUpEvent event = new ZWaveWakeUpEvent(getNode().getNodeId(), WAKE_UP_NOTIFICATION);
        this.getController().notifyEventListeners(event);
        // We send the first message, and when that's ACKed, we sent the next
        if (!this.wakeUpQueue.isEmpty()) {
            // Get the next message from the queue.
            // Bump its priority to highest to try and send it while the node is awake
            SerialMessage serialMessage = this.wakeUpQueue.poll();
            serialMessage.setPriority(SerialMessagePriority.Immediate);
            this.getController().sendData(serialMessage);
        } else {
            // No messages in the queue.
            // Start a timer to send the "Go To Sleep" message
            // This gives other tasks some time to do something if they want
            setSleepTimer();
        }
    } else {
        logger.debug("NODE {}: Is sleeping", this.getNode().getNodeId());
    }
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 14 with SerialMessage

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

the class ZWaveWakeUpCommandClass method ZWaveIncomingEvent.

/**
     * Event handler for incoming Z-Wave events. We monitor Z-Wave events for completed
     * transactions. Once a transaction is completed for the WAKE_UP_NO_MORE_INFORMATION
     * event, we set the node state to asleep.
     * {@inheritDoc}
     */
@Override
public void ZWaveIncomingEvent(ZWaveEvent event) {
    if (!(event instanceof ZWaveTransactionCompletedEvent)) {
        return;
    }
    SerialMessage serialMessage = ((ZWaveTransactionCompletedEvent) event).getCompletedMessage();
    if (serialMessage.getMessageClass() != SerialMessageClass.SendData && serialMessage.getMessageType() != SerialMessageType.Request) {
        return;
    }
    byte[] payload = serialMessage.getMessagePayload();
    // Check if it's addressed to this node
    if (payload.length == 0 || (payload[0] & 0xFF) != this.getNode().getNodeId()) {
        return;
    }
    // If it's not the WAKE_UP_NO_MORE_INFORMATION, then we need to set the wakeup timer
    if (payload.length >= 4 && (payload[2] & 0xFF) == this.getCommandClass().getKey() && (payload[3] & 0xFF) == WAKE_UP_NO_MORE_INFORMATION) {
        // This is confirmation of our 'go to sleep' message
        logger.debug("NODE {}: Went to sleep", this.getNode().getNodeId());
        this.setAwake(false);
        return;
    }
    // Send the next message in the wake-up queue
    if (!this.wakeUpQueue.isEmpty()) {
        // Get the next message from the queue.
        // Bump its priority to highest to try and send it while the node is awake
        serialMessage = this.wakeUpQueue.poll();
        serialMessage.setPriority(SerialMessagePriority.Immediate);
        this.getController().sendData(serialMessage);
    } else if (isAwake() == true) {
        // No more messages in the queue.
        // Start a timer to send the "Go To Sleep" message
        // This gives other tasks some time to do something if they want
        setSleepTimer();
    }
}
Also used : ZWaveTransactionCompletedEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 15 with SerialMessage

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

the class ZWaveWakeUpCommandClass method getNoMoreInformationMessage.

/**
     * Gets a SerialMessage with the WAKE_UP_NO_MORE_INFORMATION command.
     *
     * @return the serial message
     */
public SerialMessage getNoMoreInformationMessage() {
    logger.debug("NODE {}: Creating new message for application command WAKE_UP_NO_MORE_INFORMATION", this.getNode().getNodeId());
    SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.SendData, SerialMessagePriority.Immediate);
    byte[] newPayload = { (byte) this.getNode().getNodeId(), 2, (byte) getCommandClass().getKey(), (byte) WAKE_UP_NO_MORE_INFORMATION };
    result.setMessagePayload(newPayload);
    return result;
}
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