public boolean handleApplicationUpdateRequest(byte[] data) { boolean messageRemoved = false; byte nodeId = data[3]; Node node = getNode(nodeId); Node tnode = null; if (node != null && !node.isNodeAlive()) { node.setNodeAlive(true); } switch (data[2]) { case Defs.UPDATE_STATE_SUC_ID: logs.add(String.format("Update SUC Id node %d", SafeCast.toInt(nodeId))); sucNodeId = nodeId; break; case Defs.UPDATE_STATE_DELETE_DONE: logs.add(String.format("Remove node %d", SafeCast.toInt(nodeId))); removeNode(nodeId); break; case Defs.UPDATE_STATE_NEW_ID_ASSIGNED: logs.add(String.format("Add node %d", SafeCast.toInt(nodeId))); addNode(nodeId); break; case Defs.UPDATE_STATE_ROUTING_PENDING: logs.add(String.format("Routing pending node %d", nodeId)); break; case Defs.UPDATE_STATE_NODE_INFO_REQ_FAILED: if (queue.getCurrentMsg() != null) { logs.add( String.format( "Update failed node %d", SafeCast.nodeIdFromMsg(queue.getCurrentMsg()))); tnode = getNode(SafeCast.nodeIdFromMsg(queue.getCurrentMsg())); if (tnode != null) { tnode.queryStageRetry(QueryStage.NodeInfo, (byte) 2); if (moveMsgToWakeUpQueue(tnode.getNodeId(), true)) { messageRemoved = true; } } } break; case Defs.UPDATE_STATE_NODE_INFO_REQ_DONE: logs.add(String.format("Update done node %d", nodeId)); break; case Defs.UPDATE_STATE_NODE_INFO_RECEIVED: logs.add(String.format("Update info receive node %d", nodeId)); if (node != null) { node.updateNodeInfo( Arrays.copyOfRange(data, 8, data.length), (byte) ((SafeCast.toInt(data[4]) - 3))); } break; } if (messageRemoved) { queue.removeExpectedAndACK(); } return messageRemoved; }
public void handleMemoryGetIdResponse(byte[] data) { homeId = SafeCast.toInt(data[2]) << 24 | SafeCast.toInt(data[3]) << 16 | SafeCast.toInt(data[4]) << 8 | SafeCast.toInt(data[5]); addNode(homeId, data[6]); logs.add( String.format("FUNC_ID_ZW_MEMORY_GET_ID : HomeId = 0x%08x, NodeId = %d", homeId, data[6])); }
public Node addNode(int homeId, byte nodeId) { if (!isNodeExist(nodeId)) { size++; logs.add(String.format("Adding node: %d", SafeCast.toInt(nodeId))); } Node node; if (nodesCount() == 1) { primaryController = new Controller(homeId, nodeId, queue, xml, logs); primaryController.setLibraryType(libraryType); primaryController.setLibraryTypeName(libraryTypeName); primaryController.setLibraryVersion(libraryVersion); primaryController.setNodeListener(listener); setNode(nodeId, primaryController); node = primaryController; } else { node = new Node(homeId, nodeId, primaryController, queue, xml, logs); setNode(nodeId, node); node.setNodeListener(listener); node.setQueryStage(QueryStage.ProtocolInfo); } if (listener != null) { listener.onNodeAddedToList(); } return node; }
public void handleGetSUCNodeIdResponse(byte[] data) { sucNodeId = data[2]; logs.add( String.format("FUNC_ID_ZW_GET_SUC_NODE_ID -- SUC Node Id: %d", SafeCast.toInt(sucNodeId))); if (sucNodeId == 0) { /* di OpenZ-Wave ada source tapi di comments */ } }
public Node removeNode(byte nodeId) { if (isNodeExist(nodeId)) { size--; logs.add(String.format("Removing node: %d", SafeCast.toInt(nodeId))); } Node rem = getNode(nodeId); setNode(nodeId, null); if (listener != null) { listener.onNodeRemovedToList(); } return rem; }
// ----------------------------------------------------------------------------------------- // Request Methods // ----------------------------------------------------------------------------------------- public void handleSendDataRequest(byte[] data, boolean replication) { byte nodeId = SafeCast.nodeIdFromMsg(queue.getCurrentMsg()); if (data[2] != queue.getExpectedCallbackId()) { logs.add( String.format( "Unexpected callback id: received %d != %d", SafeCast.toInt(data[2]), SafeCast.toInt(queue.getExpectedCallbackId()))); } else { Node node = getNode(nodeId); if (node != null && queue.getCurrentMsg() != null) { if (data[3] != 0) { if (!handleErrorResponse( data[3], nodeId, replication ? "ZW_REPLICATION_END_DATA" : "ZW_SEND_DATA", !replication)) { if (queue.getCurrentMsg().isNoOperation() && (node.getQueryStage() == QueryStage.Probe1 || node.getQueryStage() == QueryStage.Probe2)) { node.queryStageRetry(node.getQueryStage(), (byte) 3); } } } else { if (queue.getCurrentMsg().isWakeUpNoMoreInformationCommand()) { WakeUp wu = (WakeUp) node.getCommandClassManager().getCommandClass(WakeUp.COMMAND_CLASS_ID); if (wu != null) { wu.setAwake(false); } } if (!node.isNodeAlive()) { node.setNodeAlive(true); } } } queue.setExpectedCallbackId((byte) 0); } }
public Node getNode(byte nodeId) { return nodes.get(SafeCast.toInt(nodeId)); }
public void setNode(byte nodeId, Node node) { nodes.set(SafeCast.toInt(nodeId), node); }
public boolean isNodeExist(byte nodeId) { return nodes.get(SafeCast.toInt(nodeId)) != null; }