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

Examples of org.openhab.binding.zwave.internal.protocol.ZWaveNode


    return false;
  }

  public boolean handleFailedSendDataRequest(ZWaveController zController, SerialMessage originalMessage) {

    ZWaveNode node = zController.getNode(originalMessage.getMessageNode());

    // No retries if the node is DEAD or FAILED
    if (node.isDead()) {
      return false;
    }

    // High priority messages get requeued, low priority get dropped
    if (!node.isListening() && !node.isFrequentlyListening()
        && originalMessage.getPriority() != SerialMessagePriority.Low) {
      ZWaveWakeUpCommandClass wakeUpCommandClass = (ZWaveWakeUpCommandClass) node
          .getCommandClass(CommandClass.WAKE_UP);

      if (wakeUpCommandClass != null) {
        // It's a battery operated device, place in wake-up queue.
        wakeUpCommandClass.setAwake(false);
        wakeUpCommandClass.processOutgoingWakeupMessage(originalMessage);
        return false;
      }
    } else if (!node.isListening() && !node.isFrequentlyListening()
        && originalMessage.getPriority() == SerialMessagePriority.Low)
      return false;

    node.incrementResendCount();

    logger.error("NODE {}: Got an error while sending data. Resending message.", node.getNodeId());
    zController.sendData(originalMessage);
    return true;
  }
View Full Code Here


    logger.trace("Handle Message Get Node ProtocolInfo Response");
   
    int nodeId = lastSentMessage.getMessagePayloadByte(0);
    logger.debug("NODE {}: ProtocolInfo", nodeId);
   
    ZWaveNode node = zController.getNode(nodeId);
   
    boolean listening = (incomingMessage.getMessagePayloadByte(0) & 0x80)!=0 ? true : false;
    boolean routing = (incomingMessage.getMessagePayloadByte(0) & 0x40)!=0 ? true : false;
    int version = (incomingMessage.getMessagePayloadByte(0) & 0x07) + 1;
    boolean frequentlyListening = (incomingMessage.getMessagePayloadByte(1) & 0x60)!= 0 ? true : false;
   
    logger.debug("NODE {}: Listening = {}", nodeId, listening);
    logger.debug("NODE {}: Routing = {}", nodeId, routing);
    logger.debug("NODE {}: Version = {}", nodeId, version);
    logger.debug("NODE {}: fLIRS = {}", nodeId, frequentlyListening);
   
    node.setListening(listening);
    node.setRouting(routing);
    node.setVersion(version);
    node.setFrequentlyListening(frequentlyListening);
   
    Basic basic = Basic.getBasic(incomingMessage.getMessagePayloadByte(3));
    if (basic == null) {
      logger.error(String.format("NODE %d: Basic device class 0x%02x not found", nodeId, incomingMessage.getMessagePayloadByte(3)));
      return false;
    }
    logger.debug(String.format("NODE %d: Basic = %s 0x%02x", nodeId, basic.getLabel(), basic.getKey()));

    Generic generic = Generic.getGeneric(incomingMessage.getMessagePayloadByte(4));
    if (generic == null) {
      logger.error(String.format("NODE %d: Generic device class 0x%02x not found", nodeId, incomingMessage.getMessagePayloadByte(4)));
      return false;
    }
    logger.debug(String.format("NODE %d: Generic = %s 0x%02x", nodeId, generic.getLabel(), generic.getKey()));

    Specific specific = Specific.getSpecific(generic, incomingMessage.getMessagePayloadByte(5));
    if (specific == null) {
      logger.error(String.format("NODE %d: Specific device class 0x%02x not found", nodeId, incomingMessage.getMessagePayloadByte(5)));
      return false;
    }
    logger.debug(String.format("NODE %d: Specific = %s 0x%02x", nodeId, specific.getLabel(), specific.getKey()));
   
    ZWaveDeviceClass deviceClass = node.getDeviceClass();
    deviceClass.setBasicDeviceClass(basic);
    deviceClass.setGenericDeviceClass(generic);
    deviceClass.setSpecificDeviceClass(specific);
   
    // Add all the command classes.
    // If restored the node from configuration file then
    // the classes will already exist and this will be ignored

    // Add mandatory command classes as specified by it's generic device class.
    for (CommandClass commandClass : generic.getMandatoryCommandClasses()) {
      ZWaveCommandClass zwaveCommandClass = ZWaveCommandClass.getInstance(commandClass.getKey(), node, zController);
      if (zwaveCommandClass != null)
        zController.getNode(nodeId).addCommandClass(zwaveCommandClass);
    }

    // Add mandatory command classes as specified by it's specific device class.
    for (CommandClass commandClass : specific.getMandatoryCommandClasses()) {
      ZWaveCommandClass zwaveCommandClass = ZWaveCommandClass.getInstance(commandClass.getKey(), node, zController);
      if (zwaveCommandClass != null)
        node.addCommandClass(zwaveCommandClass);
    }

      // advance node stage of the current node.
    node.advanceNodeStage(NodeStage.PING);
   
    checkTransactionComplete(lastSentMessage, incomingMessage);

    return false;
  }
View Full Code Here

   * @param nodeId
   *            Node to perform the heal on
   * @return true if the heal is scheduled
   */
  public boolean healNode(int nodeId) {
    ZWaveNode node = zController.getNode(nodeId);
    if (node == null) {
      logger.error("NODE {}: Heal node - can't be found.", nodeId);
      return false;
    }

    HealNode heal = new HealNode();
    heal.node = node;
    heal.nodeId = nodeId;
    heal.retryCnt = 0;
    heal.routeList = null;
    heal.state = HealState.WAITING;
    heal.lastChange = Calendar.getInstance().getTime();

    // Find out if this is a listening device
    if (node.isListening())
      heal.listening = true;
    else
      heal.listening = false;
    healNodes.put(nodeId, heal);

View Full Code Here

      // Update the time and send a ping...
      pingNodeTime = System.currentTimeMillis() + PING_PERIOD;

      // Find the node that we haven't communicated with for the longest
      // time
      ZWaveNode oldestNode = null;
      for (ZWaveNode node : zController.getNodes()) {
        // Ignore the controller and nodes that aren't listening
        if (node.getNodeId() == zController.getOwnNodeId() || node.isListening() == false)
          continue;
        if (oldestNode == null) {
          oldestNode = node;
        } else if (node.getLastSent().getTime() < oldestNode.getLastSent().getTime()) {
          oldestNode = node;
        }
      }

      // We now have the oldest node that we've heard from - ping it!
      if (oldestNode != null) {
        logger.debug("NODE {}: Sending periodic PING.", oldestNode.getNodeId());

        // Reset the resend count - also resets the lastUpdate timer
        oldestNode.resetResendCount();

        ZWaveNoOperationCommandClass zwaveCommandClass = (ZWaveNoOperationCommandClass) oldestNode
            .getCommandClass(CommandClass.NO_OPERATION);
        if (zwaveCommandClass != null)
          zController.sendData(zwaveCommandClass.getNoOperationMessage());
      }
View Full Code Here

      logger.debug("NODE {}: Node Status event - Node is {}", statusEvent.getNodeId(), statusEvent.getState());

      switch (statusEvent.getState()) {
      case Dead:
      case Failed:
        ZWaveNode node = zController.getNode(statusEvent.getNodeId());
        if (node == null) {
          logger.error("NODE {}: Status event received, but node not found.", statusEvent.getNodeId());
          return;
        }

        // If this is a DEAD notification, then ask the controller if it's really FAILED
        if(statusEvent.getState() == ZWaveNodeStatusEvent.State.Dead) {
          zController.requestIsFailedNode(node.getNodeId());
        }

        // The node is dead, but we may have already started a Heal
        // If so, don't start it again!
        if (!isNodeHealing(node.getNodeId())) {
          logger.debug("NODE {}: {} node - requesting network heal.", node.getNodeId(), statusEvent.getState());

          healNode(node.getNodeId());

          // Reset the node stage to PING.
          // This will also set the state back to DONE in
          // resetResendCount if the node
          // has already completed initialisation.
          // node.setNodeStage(NodeStage.PING);

          node.resetResendCount();
        } else {
          logger.debug("NODE {}: {} node - already healing.", node.getNodeId(), statusEvent.getState());
        }
        break;
      case Alive:
        break;
      }
View Full Code Here

        nodeNumber = nodeNumber.substring(0, next);
      }
      int nodeId = Integer.parseInt(nodeNumber);

      // Return the detailed configuration for this node
      ZWaveNode node = zController.getNode(nodeId);
      if (node == null)
        return null;

      // Open the product database
      ZWaveProductDatabase database = new ZWaveProductDatabase();

      // Process the request
      if (arg.equals("")) {
        record = new OpenHABConfigurationRecord(domain, "Name", "Name", false);
        record.value = node.getName();
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Location", "Location", false);
        record.value = node.getLocation();
        records.add(record);

        if(node.getManufacturer() != Integer.MAX_VALUE) {
          if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) == true) {
            // Add links to configuration if the node supports the various command classes
            if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey()) == true) {
              record = new OpenHABConfigurationRecord(domain + "parameters/", "Configuration Parameters");
              record.addAction("Refresh", "Refresh");
              records.add(record);
            }
 
            if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey()) == true) {
              record = new OpenHABConfigurationRecord(domain + "associations/", "Association Groups");
              record.addAction("Refresh", "Refresh");
              records.add(record);
            }
 
            if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.WAKE_UP.getKey()) == true) {
              record = new OpenHABConfigurationRecord(domain + "wakeup/", "Wakeup Period");
              record.addAction("Refresh", "Refresh");
              records.add(record);
            }
          }
        }

        // Is this a controller
        if(nodeId == zController.getOwnNodeId()) {
          record = new OpenHABConfigurationRecord(domain + "controller/", "Controller");
          records.add(record);
        }

        record = new OpenHABConfigurationRecord(domain + "neighbors/", "Neighbors");
        record.addAction("Refresh", "Refresh");
        records.add(record);
       
        record = new OpenHABConfigurationRecord(domain + "status/", "Status");
        records.add(record);

        record = new OpenHABConfigurationRecord(domain + "info/", "Information");
        records.add(record);
      } else if (arg.equals("info/")) {
        if (node.getManufacturer() != Integer.MAX_VALUE) {
          if (database.FindManufacturer(node.getManufacturer()) == true) {
            record = new OpenHABConfigurationRecord(domain, "Manufacturer", "Manufacturer", true);
            record.value = database.getManufacturerName();
            records.add(record);
          }

          if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) == true) {
            record = new OpenHABConfigurationRecord(domain, "Product", "Product", true);
            record.value = database.getProductName();
            records.add(record);
          }
        }

        record = new OpenHABConfigurationRecord(domain, "ManufacturerID", "Manufacturer ID", true);
        if(node.getDeviceId() == Integer.MAX_VALUE) {
          record.value = "UNKNOWN";
        }
        else {
          record.value = Integer.toHexString(node.getManufacturer());
        }
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "DeviceID", "Device ID", true);
        if(node.getDeviceId() == Integer.MAX_VALUE) {
          record.value = "UNKNOWN";
        }
        else {
          record.value = Integer.toHexString(node.getDeviceId());
        }
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "DeviceType", "Device Type", true);
        if(node.getDeviceId() == Integer.MAX_VALUE) {
          record.value = "UNKNOWN";
        }
        else {
          record.value = Integer.toHexString(node.getDeviceType());
        }
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Version", "Version", true);
        record.value = Integer.toString(node.getVersion());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Listening", "Listening", true);
        record.value = Boolean.toString(node.isListening());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Routing", "Routing", true);
        record.value = Boolean.toString(node.isRouting());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Power", "Power", true);
        ZWaveBatteryCommandClass batteryCommandClass = (ZWaveBatteryCommandClass) node
            .getCommandClass(CommandClass.BATTERY);
        if (batteryCommandClass != null) {
          if(batteryCommandClass.getBatteryLevel() == null) {
            record.value = "BATTERY " + "UNKNOWN";
          }
          else {
            record.value = "BATTERY " + batteryCommandClass.getBatteryLevel() + "%";
          }
        } else {
          record.value = "MAINS";
        }
        records.add(record);

        ZWaveVersionCommandClass versionCommandClass = (ZWaveVersionCommandClass) node
            .getCommandClass(CommandClass.VERSION);
        if (versionCommandClass != null) {
          record = new OpenHABConfigurationRecord(domain, "LibType", "Library Type", true);
          if (versionCommandClass.getLibraryType() == null)
            record.value = "Unknown";
          else
            record.value = versionCommandClass.getLibraryType().getLabel();
          records.add(record);

          record = new OpenHABConfigurationRecord(domain, "ProtocolVersion", "Protocol Version", true);
          if (versionCommandClass.getProtocolVersion() == null)
            record.value = "Unknown";
          else
            record.value = Double.toString(versionCommandClass.getProtocolVersion());
          records.add(record);

          record = new OpenHABConfigurationRecord(domain, "AppVersion", "Application Version", true);
          if (versionCommandClass.getApplicationVersion() == null)
            record.value = "Unknown";
          else
            record.value = Double.toString(versionCommandClass.getApplicationVersion());
          records.add(record);
        }

        ZWaveDeviceClass devClass = node.getDeviceClass();
        if (devClass != null) {
          record = new OpenHABConfigurationRecord(domain, "BasicClass", "Basic Device Class", true);
          record.value = devClass.getBasicDeviceClass().toString();
          records.add(record);
          record = new OpenHABConfigurationRecord(domain, "GenericClass", "Generic Device Class", true);
          record.value = devClass.getGenericDeviceClass().toString();
          records.add(record);
          record = new OpenHABConfigurationRecord(domain, "SpecificClass", "Specific Device Class", true);
          record.value = devClass.getSpecificDeviceClass().toString();
          records.add(record);
        }
      } else if (arg.equals("status/")) {
        record = new OpenHABConfigurationRecord(domain, "LastSent", "Last Packet Sent", true);
        if(node.getLastSent() == null) {
          record.value = "NEVER";
        }
        else {
          record.value = df.format(node.getLastSent());
        }
        records.add(record);
       
        record = new OpenHABConfigurationRecord(domain, "LastReceived", "Last Packet Received", true);
        if(node.getLastReceived() == null) {
          record.value = "NEVER";
        }
        else {
          record.value = df.format(node.getLastReceived());
        }
        records.add(record);
       
        if(networkMonitor != null) {
          record = new OpenHABConfigurationRecord(domain, "LastHeal", "Heal Status", true);
          if (node.getHealState() == null)
                        record.value = networkMonitor.getNodeState(nodeId);
                    else
                        record.value = node.getHealState();
         
          records.add(record);
        }

        record = new OpenHABConfigurationRecord(domain, "NodeStage", "Node Stage", true);
        record.value = node.getNodeStage() + " @ " + df.format(node.getQueryStageTimeStamp());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Packets", "Packet Statistics", true);
        record.value = node.getRetryCount() + " / " + node.getSendCount();
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Dead", "Dead", true);
        if(node.getDeadCount() == 0) {
          record.value = Boolean.toString(node.isDead());
        }
        else {
          record.value = Boolean.toString(node.isDead()) + " [" + node.getDeadCount() + " previous - last @ " + df.format(node.getDeadTime()) + "]";
        }
        records.add(record);
      } else if (arg.equals("parameters/")) {
        if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {
          List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
          if(configList == null)
            return records;

          // Get the configuration command class for this node
          ZWaveConfigurationCommandClass configurationCommandClass = (ZWaveConfigurationCommandClass) node
              .getCommandClass(CommandClass.CONFIGURATION);

          if (configurationCommandClass == null) {
            logger.error("NODE {}: Error getting configurationCommandClass", nodeId);
            return null;
          }

          // Loop through the parameters and add to the records...
          for (ZWaveDbConfigurationParameter parameter : configList) {
            record = new OpenHABConfigurationRecord(domain, "configuration" + parameter.Index,
                parameter.Index + ": " + database.getLabel(parameter.Label), false);

            ConfigurationParameter configurationParameter = configurationCommandClass
                .getParameter(parameter.Index);

            // Only provide a value if it's stored in the node
            // This is the only way we can be sure of its real value
            if (configurationParameter != null)
              record.value = Integer.toString(configurationParameter.getValue());

            // If the value is in our PENDING list, then use that instead
            Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey(), nodeId, parameter.Index);
            if(pendingValue != null) {
              record.value = Integer.toString(pendingValue);
              record.state = OpenHABConfigurationRecord.STATE.PENDING;
            }

            try {
              record.type = OpenHABConfigurationRecord.TYPE.valueOf(parameter.Type.toUpperCase());
            } catch(IllegalArgumentException e) {
              record.type = OpenHABConfigurationRecord.TYPE.LONG;             
            }

            if(parameter.Item != null) {
              for (ZWaveDbConfigurationListItem item : parameter.Item)
                record.addValue(Integer.toString(item.Value), database.getLabel(item.Label));
            }
           
            // Add any limits
            record.minimum = parameter.Minimum;
            record.maximum = parameter.Maximum;

            // Add the description
            record.description = database.getLabel(parameter.Help);

            records.add(record);
          }
        }
      } else if (arg.equals("associations/")) {
        if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {
          List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();

          if (groupList != null) {
            // Loop through the associations and add all groups to the
            // records...
            for (ZWaveDbAssociationGroup group : groupList) {
              // TODO: Controller reporting associations are set to read only
              record = new OpenHABConfigurationRecord(domain, "association" + group.Index + "/",
                  database.getLabel(group.Label), true);

              // Add the description
              record.description = database.getLabel(group.Help);
             
              // For the 'value', describe how many devices are set and the maximum allowed
              ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node
                  .getCommandClass(CommandClass.ASSOCIATION);
              int memberCnt = 0;
              List<Integer> members = associationCommandClass.getGroupMembers(group.Index);
              if(members != null)
                memberCnt = members.size();
              record.value = memberCnt + " of " + group.Maximum + " group members";

              // Add the action for refresh
              record.addAction("Refresh", "Refresh");

              records.add(record);
            }
          }
        }
      } else if (arg.startsWith("associations/association")) {
        if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {

          String groupString = arg.substring(24);
          int nextDelimiter = groupString.indexOf('/');
          // String arg = null;
          if (nextDelimiter != -1) {
            // arg = nodeNumber.substring(nextDelimiter + 1);
            groupString = groupString.substring(0, nextDelimiter);
          }
          int groupId = Integer.parseInt(groupString);

          // Get the requested group so we have access to the
          // attributes
          List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();
          if (groupList == null)
            return null;
          ZWaveDbAssociationGroup group = null;
          for (int cnt = 0; cnt < groupList.size(); cnt++) {
            if (groupList.get(cnt).Index == groupId) {
              group = groupList.get(cnt);
              break;
            }
          }

          // Return if the group wasn't found
          if (group == null)
            return null;

          // Get the group members
          ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node
              .getCommandClass(CommandClass.ASSOCIATION);

          List<Integer> members = associationCommandClass.getGroupMembers(groupId);
          for(ZWaveNode nodeList : zController.getNodes()) {
            // Don't allow an association with itself
            if(nodeList.getNodeId() == node.getNodeId())
              continue;
           
            // Add the member
            if (nodeList.getName() == null || nodeList.getName().isEmpty())
              record = new OpenHABConfigurationRecord(domain, "node" + nodeList.getNodeId(), "Node " + nodeList.getNodeId(), false);
            else
              record = new OpenHABConfigurationRecord(domain, "node" + nodeList.getNodeId(), nodeList.getName(), false);

            record.type = OpenHABConfigurationRecord.TYPE.LIST;
            record.addValue("true", "Member");
            record.addValue("false", "Non-Member");

            if (members != null && members.contains(nodeList.getNodeId())) {
              record.value = "true";
            } else {
              record.value = "false";
            }

            // If the value is in our PENDING list, then use that instead
            Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey(), nodeId, groupId, nodeList.getNodeId());
            if(pendingValue != null) {
              if(pendingValue == 1)
                record.value = "true";
              else
                record.value = "false";
              record.state = OpenHABConfigurationRecord.STATE.PENDING;
            }

            records.add(record);
          }
        }
      } else if (arg.equals("wakeup/")) {
        ZWaveWakeUpCommandClass wakeupCommandClass = (ZWaveWakeUpCommandClass) node
            .getCommandClass(CommandClass.WAKE_UP);

        if(wakeupCommandClass == null) {
          logger.error("NODE {}: Error getting wakeupCommandClass", nodeId);
          return null;
        }

        // Display the wakeup parameters.
        // Note that only the interval is writable.
        record = new OpenHABConfigurationRecord(domain, "Interval", "Wakeup Interval", false);
        record.minimum = wakeupCommandClass.getMinInterval();
        record.maximum = wakeupCommandClass.getMaxInterval();
        record.value = Integer.toString(wakeupCommandClass.getInterval());
        // If the value is in our PENDING list, then use that instead
        Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.WAKE_UP.getKey(), nodeId);
        if(pendingValue != null) {
          record.value = Integer.toString(pendingValue);
          record.state = OpenHABConfigurationRecord.STATE.PENDING;
        }
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Minimum", "Minimum Interval", true);
        record.value = Integer.toString(wakeupCommandClass.getMinInterval());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Maximum", "Maximum Interval", true);
        record.value = Integer.toString(wakeupCommandClass.getMaxInterval());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Default", "Default Interval", true);
        record.value = Integer.toString(wakeupCommandClass.getDefaultInterval());
        records.add(record);

        record = new OpenHABConfigurationRecord(domain, "Step", "Interval Step", true);
        record.value = Integer.toString(wakeupCommandClass.getIntervalStep());
        records.add(record);
      } else if (arg.equals("neighbors/")) {
        // Check that we have the neighbor list for this node
        if(node.getNeighbors() == null)
          return null;

        for (Integer neighbor : node.getNeighbors()) {
          ZWaveNode nodeNeighbor = zController.getNode(neighbor);
          String neighborName;
          if (nodeNeighbor == null)
            neighborName = "Node " + neighbor + " (UNKNOWN)";
          else if (nodeNeighbor.getName() == null || nodeNeighbor.getName().isEmpty())
            neighborName = "Node " + neighbor;
          else
            neighborName = nodeNeighbor.getName();

          // Create the record
          record = new OpenHABConfigurationRecord(domain, "node" + neighbor, neighborName, false);
          record.readonly = true;
View Full Code Here

TOP

Related Classes of org.openhab.binding.zwave.internal.protocol.ZWaveNode

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.