コード例 #1
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);
  }
コード例 #2
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);
  }