Package org.openhab.binding.zwave.internal.protocol.commandclass

Examples of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveMultiInstanceCommandClass


   
    if (endpointId == 0) {
      return getCommandClass(commandClass);
    }
   
    ZWaveMultiInstanceCommandClass multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass) supportedCommandClasses.get(CommandClass.MULTI_INSTANCE);
    if (multiInstanceCommandClass == null) {
      return null
    }
    else if (multiInstanceCommandClass.getVersion() == 2) {
      ZWaveEndpoint endpoint = multiInstanceCommandClass.getEndpoint(endpointId);
     
      if (endpoint != null) {
        ZWaveCommandClass result = endpoint.getCommandClass(commandClass);
        if (result != null) {
          return result;
        }
      }
    }
    else if (multiInstanceCommandClass.getVersion() == 1) {
      ZWaveCommandClass result = getCommandClass(commandClass);
      if (endpointId <= result.getInstances()) {
        return result;
      }
    } else {
      logger.warn("NODE {}: Unsupported multi instance command version: {}.", nodeId, multiInstanceCommandClass.getVersion());
    }
   
    return null;
  }
View Full Code Here


   * @param node the destination node.
   * @return SerialMessage on success, null on failure.
   */
  public SerialMessage encapsulate(SerialMessage serialMessage,
      ZWaveCommandClass commandClass, int endpointId) {
    ZWaveMultiInstanceCommandClass multiInstanceCommandClass;
   
    if (serialMessage == null)
      return null;
   
    // no encapsulation necessary.
    if (endpointId == 0) {
      return serialMessage;
    }
   
    multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass)this.getCommandClass(CommandClass.MULTI_INSTANCE);
   
    if (multiInstanceCommandClass != null) {
      logger.debug("NODE {}: Encapsulating message, instance / endpoint {}", this.getNodeId(), endpointId);
      switch (multiInstanceCommandClass.getVersion()) {
        case 2:
          if (commandClass.getEndpoint() != null) {
            serialMessage = multiInstanceCommandClass.getMultiChannelEncapMessage(serialMessage, commandClass.getEndpoint());
            return serialMessage;
          }
          break;
        case 1:
        default:
          if (commandClass.getInstances() >= endpointId) {
            serialMessage = multiInstanceCommandClass.getMultiInstanceEncapMessage(serialMessage, endpointId);
            return serialMessage;
          }
          break;
      }
    }
View Full Code Here

              sendData(node.encapsulate(serialMessage, zwaveCommandClass, i));
            }
          }
        }
      } else if (zwaveCommandClass instanceof ZWaveMultiInstanceCommandClass) {
        ZWaveMultiInstanceCommandClass multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass) zwaveCommandClass;
        for (ZWaveEndpoint endpoint : multiInstanceCommandClass.getEndpoints()) {
          for (ZWaveCommandClass endpointCommandClass : endpoint.getCommandClasses()) {
            logger.trace(String.format("NODE %d: Inspecting command class %s for endpoint %d", node.getNodeId(), endpointCommandClass
                .getCommandClass().getLabel(), endpoint.getEndpointId()));
            if (endpointCommandClass instanceof ZWaveCommandClassDynamicState) {
              logger.debug("NODE {}: Found dynamic state command class {}", node.getNodeId(), endpointCommandClass
View Full Code Here

                  // before continuing.
        break;
    case VERSION:
      this.node.setNodeStage(NodeStage.INSTANCES_ENDPOINTS);
      // try and get the multi instance / channel command class.
      ZWaveMultiInstanceCommandClass multiInstance = (ZWaveMultiInstanceCommandClass) this.node
          .getCommandClass(CommandClass.MULTI_INSTANCE);

      if (multiInstance != null) {
        multiInstance.initEndpoints();
        break;
      }

      logger.trace("NODE {}: does not support MULTI_INSTANCE, proceeding to static node stage.",
          this.node.getNodeId());
    case INSTANCES_ENDPOINTS:
      this.node.setNodeStage(NodeStage.STATIC_VALUES);
    case STATIC_VALUES:
      if (queriesPending == -1) {
        queriesPending = 0;
        for (ZWaveCommandClass zwaveCommandClass : this.node.getCommandClasses()) {
          logger.trace("NODE {}: Inspecting command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass().getLabel());
          if (zwaveCommandClass instanceof ZWaveCommandClassInitialization) {
            logger.debug("NODE {}: Found initializable command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass()
                .getLabel());
            ZWaveCommandClassInitialization zcci = (ZWaveCommandClassInitialization) zwaveCommandClass;
            int instances = zwaveCommandClass.getInstances();
            if (instances == 0) {
              Collection<SerialMessage> initqueries = zcci.initialize();
              for (SerialMessage serialMessage : initqueries) {
                this.controller.sendData(serialMessage);
                queriesPending++;
              }
            } else {
              for (int i = 1; i <= instances; i++) {
                Collection<SerialMessage> initqueries = zcci.initialize();
                for (SerialMessage serialMessage : initqueries) {
                  this.controller
                      .sendData(this.node.encapsulate(serialMessage, zwaveCommandClass, i));
                  queriesPending++;
                }
              }
            }
          } else if (zwaveCommandClass instanceof ZWaveMultiInstanceCommandClass) {
            ZWaveMultiInstanceCommandClass multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass) zwaveCommandClass;
            for (ZWaveEndpoint endpoint : multiInstanceCommandClass.getEndpoints()) {
              for (ZWaveCommandClass endpointCommandClass : endpoint.getCommandClasses()) {
                logger.trace(String.format("NODE %d: Inspecting command class %s for endpoint %d", this.node.getNodeId(), endpointCommandClass
                    .getCommandClass().getLabel(), endpoint.getEndpointId()));
                if (endpointCommandClass instanceof ZWaveCommandClassInitialization) {
                  logger.debug("NODE {}: Found initializable command class {}", this.node.getNodeId(), endpointCommandClass
                      .getCommandClass().getLabel());
                  ZWaveCommandClassInitialization zcci2 = (ZWaveCommandClassInitialization) endpointCommandClass;
                  Collection<SerialMessage> initqueries = zcci2.initialize();
                  for (SerialMessage serialMessage : initqueries) {
                    this.controller.sendData(this.node.encapsulate(serialMessage,
                        endpointCommandClass, endpoint.getEndpointId()));
                    queriesPending++;
                  }
                }
              }
            }
          }
        }
      }
      if (queriesPending-- > 0) // there is still something to be
                    // initialized.
        break;

      logger.trace("NODE {}: Done getting static values, proceeding to dynamic node stage.", this.node.getNodeId());
      queriesPending = -1;
      this.node.setNodeStage(NodeStage.DYNAMIC);
    case DYNAMIC:
      if (queriesPending == -1) {
        queriesPending = 0;
        for (ZWaveCommandClass zwaveCommandClass : this.node.getCommandClasses()) {
          logger.trace("NODE {}: Inspecting command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass().getLabel());
          if (zwaveCommandClass instanceof ZWaveCommandClassDynamicState) {
            logger.debug("NODE {}: Found dynamic state command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass()
                .getLabel());
            ZWaveCommandClassDynamicState zdds = (ZWaveCommandClassDynamicState) zwaveCommandClass;
            int instances = zwaveCommandClass.getInstances();
            if (instances == 0) {
              Collection<SerialMessage> dynamicQueries = zdds.getDynamicValues();
              for (SerialMessage serialMessage : dynamicQueries) {
                this.controller.sendData(serialMessage);
                queriesPending++;
              }
            } else {
              for (int i = 1; i <= instances; i++) {
                Collection<SerialMessage> dynamicQueries = zdds.getDynamicValues();
                for (SerialMessage serialMessage : dynamicQueries) {
                  this.controller
                      .sendData(this.node.encapsulate(serialMessage, zwaveCommandClass, i));
                  queriesPending++;
                }
              }
            }
          } else if (zwaveCommandClass instanceof ZWaveMultiInstanceCommandClass) {
            ZWaveMultiInstanceCommandClass multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass) zwaveCommandClass;
            for (ZWaveEndpoint endpoint : multiInstanceCommandClass.getEndpoints()) {
              for (ZWaveCommandClass endpointCommandClass : endpoint.getCommandClasses()) {
                logger.trace(String.format("NODE %d: Inspecting command class %s for endpoint %d", this.node.getNodeId(), endpointCommandClass
                    .getCommandClass().getLabel(), endpoint.getEndpointId()));
                if (endpointCommandClass instanceof ZWaveCommandClassDynamicState) {
                  logger.debug("NODE {}: Found dynamic state command class {}", this.node.getNodeId(), endpointCommandClass
View Full Code Here

TOP

Related Classes of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveMultiInstanceCommandClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.