Search in sources :

Example 71 with SerialMessage

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

the class ZWaveAssociationCommandClass method getAllAssociations.

/**
     * Request all association groups.
     * This method requests the number of groups from a node, when that
     * replay is processed we request association group 1 and set flags so that
     * when the response is received the command class automatically
     * requests the next group. This continues until we reach the maximum
     * number of group the device reports to us or until the device returns
     * a group with no members.
     */
public void getAllAssociations() {
    updateAssociationsNode = 1;
    SerialMessage serialMessage = getAssociationMessage(updateAssociationsNode);
    if (serialMessage != null) {
        this.getController().sendData(serialMessage);
    }
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 72 with SerialMessage

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

the class ZWaveAssociationCommandClass method processAssociationReport.

/**
     * Processes a CONFIGURATIONCMD_REPORT / CONFIGURATIONCMD_SET message.
     *
     * @param serialMessage
     *            the incoming message to process.
     * @param offset
     *            the offset position from which to start message processing.
     */
protected void processAssociationReport(SerialMessage serialMessage, int offset) {
    // Extract the group index
    int group = serialMessage.getMessagePayloadByte(offset + 1);
    // The max associations supported (0 if the requested group is not supported)
    int maxAssociations = serialMessage.getMessagePayloadByte(offset + 2);
    // Number of outstanding requests (if the group is large, it may come in multiple frames)
    int following = serialMessage.getMessagePayloadByte(offset + 3);
    if (maxAssociations == 0) {
        // Unsupported association group. Nothing to do!
        if (updateAssociationsNode == group) {
            logger.debug("NODE {}: All association groups acquired.", this.getNode().getNodeId());
            updateAssociationsNode = 0;
            // This is used for network management, so send a network event
            this.getController().notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssociationUpdate, this.getNode().getNodeId(), ZWaveNetworkEvent.State.Success));
        }
        return;
    }
    logger.debug("NODE {}: association group {} has max associations " + maxAssociations, this.getNode().getNodeId(), group);
    // Are we waiting to synchronise the start of a new group?
    if (pendingAssociation == null) {
        pendingAssociation = new AssociationGroup(group);
    }
    if (serialMessage.getMessagePayload().length > (offset + 4)) {
        logger.debug("NODE {}: association group {} includes the following nodes:", this.getNode().getNodeId(), group);
        int numAssociations = serialMessage.getMessagePayload().length - (offset + 4);
        for (int cnt = 0; cnt < numAssociations; cnt++) {
            int node = serialMessage.getMessagePayloadByte(offset + 4 + cnt);
            logger.debug("Node {}", node);
            // Add the node to the group
            pendingAssociation.addNode(node);
        }
    }
    // If this is the end of the group, update the list then let the listeners know
    if (following == 0) {
        // Clear the current information for this group
        configAssociations.remove(group);
        // Update the group in the list
        configAssociations.put(group, pendingAssociation);
        pendingAssociation = null;
        // Send an event to the users
        ZWaveAssociationEvent zEvent = new ZWaveAssociationEvent(this.getNode().getNodeId(), group);
        List<Integer> members = getGroupMembers(group);
        if (members != null) {
            for (int node : members) {
                zEvent.addMember(node);
            }
        }
        this.getController().notifyEventListeners(zEvent);
    }
    // Is this the end of the list
    if (following == 0 && group == updateAssociationsNode) {
        // so we need to request the next group
        if (updateAssociationsNode < maxGroups) {
            updateAssociationsNode++;
            SerialMessage outputMessage = getAssociationMessage(updateAssociationsNode);
            if (outputMessage != null) {
                this.getController().sendData(outputMessage);
            }
        } else {
            logger.debug("NODE {}: All association groups acquired.", this.getNode().getNodeId());
            // we have reached our maxNodes, notify listeners we are done.
            updateAssociationsNode = 0;
            // This is used for network management, so send a network event
            this.getController().notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssociationUpdate, this.getNode().getNodeId(), ZWaveNetworkEvent.State.Success));
        }
    }
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent) AssociationGroup(org.openhab.binding.zwave.internal.protocol.AssociationGroup) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)

Example 73 with SerialMessage

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

the class ZWaveAssociationCommandClass method getGroupingsMessage.

/**
     * Gets a SerialMessage with the ASSOCIATIONCMD_GROUPINGSGET command
     *
     * @return the serial message
     */
public SerialMessage getGroupingsMessage() {
    logger.debug("NODE {}: Creating new message for application command ASSOCIATIONCMD_GROUPINGSGET", this.getNode().getNodeId());
    SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Config);
    byte[] newPayload = { (byte) this.getNode().getNodeId(), 2, (byte) getCommandClass().getKey(), (byte) ASSOCIATIONCMD_GROUPINGSGET };
    result.setMessagePayload(newPayload);
    return result;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 74 with SerialMessage

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

the class ZWaveBarrierOperatorCommandClass method setValueMessage.

@Override
public SerialMessage setValueMessage(int value) {
    logger.debug("NODE {}: Creating new message for application command BARRIER_OPERATOR_SET", this.getNode().getNodeId());
    SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.SendData, SerialMessagePriority.Set);
    byte[] newPayload = { (byte) this.getNode().getNodeId(), 3, (byte) getCommandClass().getKey(), (byte) BARRIER_OPERATOR_SET, (byte) (value > 0 ? 0xFF : 0x00) };
    result.setMessagePayload(newPayload);
    return result;
}
Also used : SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage)

Example 75 with SerialMessage

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

the class ZWaveLockCommandClass method setValueMessage.

@Override
public SerialMessage setValueMessage(int value) {
    logger.debug("NODE {}: Creating new message for application command LOCK_SET", this.getNode().getNodeId());
    SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.SendData, SerialMessagePriority.Set);
    byte[] newPayload = { (byte) this.getNode().getNodeId(), 3, (byte) getCommandClass().getKey(), (byte) LOCK_SET, (byte) value };
    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