Пример #1
0
  public void handleRemoveNodeFromNetworkRequest(byte[] data) {
    ControllerCmd cci = queue.getCurrentControllerCmd();

    if (cci == null) {
      return;
    }

    ControllerState state = cci.getControllerState();
    switch (data[3]) {
      case Defs.REMOVE_NODE_STATUS_LEARN_READY:
        logs.add("REMOVE_NODE_STATUS_LEARN_READY");
        state = ControllerState.Waiting;
        cci.setControllerCommandNode((byte) 0);
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        break;
      case Defs.REMOVE_NODE_STATUS_NODE_FOUND:
        logs.add("REMOVE_NODE_STATUS_NODE_FOUND");
        state = ControllerState.InProgress;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        break;
      case Defs.REMOVE_NODE_STATUS_REMOVING_SLAVE:
        logs.add("REMOVE_NODE_STATUS_REMOVING_SLAVE --- Node: " + String.valueOf(data[4]));
        cci.setControllerCommandNode(data[4]);
        break;
      case Defs.REMOVE_NODE_STATUS_REMOVING_CONTROLLER:
        logs.add("REMOVE_NODE_STATUS_REMOVING_CONTROLLER --- Node: " + String.valueOf(data[4]));
        // mCurrentControllerCommand.mControllerCommandNode = data[4];
        cci.setControllerCommandNode(data[4]);
        if (data[4] == (byte) 0) {
          if (data[5] >= 3) {
            for (int i = 0; i < Defs.MAX_TOTAL_NODES; i++) {
              Node node = getNode((byte) i);
              synchronized (node) {
                if (node == null || primaryController == null) {
                  continue;
                }
                if (node.getNodeId() == primaryController.getNodeId()) {
                  continue;
                } // Ignore primary controller
                // See if we can match another way
                if (node.getBasicDeviceClassID() == data[6]
                    && node.getGenericDeviceClassID() == data[7]
                    && node.getSpecificDeviceClassID() == data[8]) {
                  if (cci.getControllerCommandNode() != 0) {
                    // TODO: Alternative controller found
                  } else {
                    cci.setControllerCommandNode(node.getNodeId());
                  }
                }
              }
            }
          } else {
            // TODO: error message not enough data
          }
        } else {
          cci.setControllerCommandNode(data[4]);
        }
        break;
      case Defs.REMOVE_NODE_STATUS_DONE:
        logs.add("REMOVE_NODE_STATUS_DONE");
        state = ControllerState.Completed;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        if (!cci.isControllerCommandDone()) {
          primaryController.updateControllerState(ControllerState.Completed);
          primaryController.addNodeStop(Defs.FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK);
          if (cci.getControllerCommandNode() == (byte) 0) {
            if (data[4] != (byte) 0) {
              cci.setControllerCommandNode(data[4]);
            }
          }

          if (cci.getControllerCommandNode() != (byte) 0
              && cci.getControllerCommandNode() != (byte) 0xFF) {
            removeNode(cci.getControllerCommandNode());
          }
        }
        return;
      case Defs.REMOVE_NODE_STATUS_FAILED:
        logs.add("REMOVE_NODE_STATUS_FAILED");
        primaryController.addNodeStop(Defs.FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK);
        state = ControllerState.Failed;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        break;
      default:
        logs.add("No Detected ...");
        break;
    }

    primaryController.updateControllerState(state);
  }
Пример #2
0
  private void commonAddNodeStatusRequestHandler(byte funcId, byte[] data) {
    ControllerCmd cci = queue.getCurrentControllerCmd();
    ControllerState state = ControllerState.Normal;

    if (cci != null) {
      state = cci.getControllerState();
    }
    switch (data[3]) {
      case Defs.ADD_NODE_STATUS_LEARN_READY:
        logs.add("ADD_NODE_STATUS_LEARN_READY");
        if (cci != null) {
          cci.setControllerAdded(false);
        }
        state = ControllerState.Waiting;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        break;
      case Defs.ADD_NODE_STATUS_NODE_FOUND:
        logs.add("ADD_NODE_STATUS_NODE_FOUND");
        state = ControllerState.InProgress;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        break;
      case Defs.ADD_NODE_STATUS_ADDING_SLAVE:
        logs.add("ADD_NODE_STATUS_ADDING_SLAVE --- Node: " + String.valueOf(data[4]));
        if (cci != null) {
          cci.setControllerAdded(false);
          cci.setControllerCommandNode(data[4]);
        }
        break;
      case Defs.ADD_NODE_STATUS_ADDING_CONTROLLER:
        logs.add("ADD_NODE_STATUS_ADDING_CONTROLLER --- Node: " + String.valueOf(data[4]));
        if (cci != null) {
          cci.setControllerAdded(true);
          cci.setControllerCommandNode(data[4]);
        }
        break;
      case Defs.ADD_NODE_STATUS_PROTOCOL_DONE:
        logs.add("ADD_NODE_STATUS_PROTOCOL_DONE");
        primaryController.addNodeStop(funcId);
        break;
      case Defs.ADD_NODE_STATUS_DONE:
        logs.add("ADD_NODE_STATUS_DONE");
        state = ControllerState.Completed;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        if (cci != null && cci.getControllerCommandNode() != (byte) 0xFF) {
          addNode(cci.getControllerCommandNode());
        }
        if (funcId != Defs.FUNC_ID_ZW_ADD_NODE_TO_NETWORK
            && cci != null
            && cci.isControllerAdded()) {
          initAllNodes();
        }

        break;
      case Defs.ADD_NODE_STATUS_FAILED:
        logs.add("ADD_NODE_STATUS_FAILED");
        state = ControllerState.Failed;
        if (cci != null && cci.getControllerCallback() != null) {
          cci.getControllerCallback().onAction(state, null, null);
        }
        queue.removeCurrentMsg();
        primaryController.addNodeStop(funcId);
        break;
      default:
        logs.add("No detected ...");
        break;
    }

    primaryController.updateControllerState(state);
  }
Пример #3
0
  public boolean moveMsgToWakeUpQueue(byte targetNodeId, boolean move) {
    Node node = getNode(targetNodeId);
    if (node != null
        && !node.isListeningDevice()
        && !node.isFrequentListeningDevice()
        && primaryController != null
        && targetNodeId != primaryController.getNodeId()) {
      WakeUp wu = (WakeUp) node.getCommandClassManager().getCommandClass(WakeUp.COMMAND_CLASS_ID);
      if (wu != null) {
        wu.setAwake(false);
        if (move) {
          if (queue.getCurrentControllerCmd() != null) {
            queue.removeCurrentMsg();
          }
          if (queue.getCurrentMsg() != null) {
            Msg msg = queue.getCurrentMsg();
            if (targetNodeId == SafeCast.nodeIdFromMsg(msg)) {
              if (!msg.isWakeUpNoMoreInformationCommand() && !msg.isNoOperation()) {
                QueueItem item = new QueueItem();
                item.setCommand(QueueCommand.SendMessage);
                item.setMsg(msg);
                wu.queueItem(item);
              }
              queue.removeCurrentMsg();
            }
          }

          for (int i = 0; i < queue.size(); ++i) {
            Iterator<QueueItem> iter = queue.getQueue().iterator();
            while (iter.hasNext()) {
              boolean remove = false;
              QueueItem it = iter.next();
              if (it.getCommand() == QueueCommand.SendMessage
                  && targetNodeId == SafeCast.nodeIdFromMsg(it.getMsg())) {
                if (!it.getMsg().isWakeUpNoMoreInformationCommand()
                    && !it.getMsg().isNoOperation()) {
                  wu.queueItem(it);
                } else {
                  it.setMsg(null);
                }
                remove = true;
              } else if (it.getCommand() == QueueCommand.QueryStageComplete
                  && targetNodeId == SafeCast.nodeIdFromMsg(it.getMsg())) {
                wu.queueItem(it);
                remove = true;
              } else if (it.getCommand() == QueueCommand.Controller
                  && targetNodeId == SafeCast.nodeIdFromMsg(it.getMsg())) {
                wu.queueItem(it);
                remove = true;
              }

              if (remove) {
                iter.remove();
              }
            }
          }

          if (queue.getCurrentControllerCmd() != null) {
            primaryController.updateControllerState(ControllerState.Sleeping);
            queue.sendControllerCommand(queue.getCurrentControllerCmd());
          }
          return true;
        }
      }
    }

    return false;
  }