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])); }
private boolean handleErrorResponse(byte error, byte nodeId, String funcStr, boolean sleepcheck) { Node node = getNode(nodeId); if (error == Defs.TRANSMIT_COMPLETE_NOROUTE) { logs.add(String.format("Error: %s failed. No route found.", funcStr)); // if (node != null) { // node.setNodeAlive(false); // } } else if (error == Defs.TRANSMIT_COMPLETE_NO_ACK) { logs.add(String.format("Error: %s failed. No ACK found.", funcStr)); if (queue.getCurrentMsg() != null) { if (moveMsgToWakeUpQueue(SafeCast.nodeIdFromMsg(queue.getCurrentMsg()), sleepcheck)) { return true; } } } else if (error == Defs.TRANSMIT_COMPLETE_FAIL) { logs.add(String.format("Error: %s failed. Network busy.", funcStr)); } else if (error == Defs.TRANSMIT_COMPLETE_NOT_IDLE) { logs.add(String.format("Error: %s failed. Network busy.", funcStr)); } if (node != null && node.incErrorCount() >= 3) { node.setNodeAlive(false); } return false; }
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 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 handleGetRoutingInfoResponse(byte[] data) { Node node = getNode(SafeCast.nodeIdFromMsg(queue.getCurrentMsg())); if (node != null) { node.setNeighbors(Arrays.copyOfRange(data, 2, 29)); logs.add( String.format( "FUNC_ID_ZW_GET_ROUTING_INFO -- Neighbors of node %d are:", node.getNodeId())); boolean neighbors = false; for (int i = 0; i < 29; i++) { for (int j = 0; j < 8; j++) { if ((data[2 + i] & (0x01 << j)) != 0) { logs.add(String.format("--- Node %d", (i << 3) + j + 1)); neighbors = true; } } } if (!neighbors) { logs.add(String.format("no neighbor on node %d", node.getNodeId())); } } }
public void handleGetSerialAPICapabilitiesResponse(byte[] data) { primaryController.setSerialAPIVersion(new byte[] {data[2], data[3]}); primaryController.setManufacturerShortId( (short) (SafeCast.toShort(data[4]) << 8 | SafeCast.toShort(data[5]))); primaryController.setProductShortType( (short) (SafeCast.toShort(data[6]) << 8 | SafeCast.toShort(data[7]))); primaryController.setProductShortId( (short) (SafeCast.toShort(data[8]) << 8 | SafeCast.toShort(data[9]))); primaryController.setApiMask(Arrays.copyOfRange(data, 10, 32)); logs.add( String.format( "FUNC_ID_SERIAL_API_GET_CAPABILITIES -- Serial API: v%d.%d," + " Man. Id = 0x%04x, Prod. Type = 0x%04x, Prod. Id = 0x%04x", primaryController.getSerialAPIVersion()[0], primaryController.getSerialAPIVersion()[1], primaryController.getManufacturerShortId(), primaryController.getProductShortType(), primaryController.getProductShortId())); Msg msg; if (primaryController.isBridgeController()) { msg = new Msg((byte) 0xFF, Defs.REQUEST, Defs.FUNC_ID_ZW_GET_VIRTUAL_NODES, false); queue.sendMsg(msg, QueuePriority.Command); } else if (primaryController.isAPICallSupported(Defs.FUNC_ID_ZW_GET_RANDOM)) { msg = new Msg((byte) 0xFF, Defs.REQUEST, Defs.FUNC_ID_ZW_GET_RANDOM, false); msg.append((byte) 32); queue.sendMsg(msg, QueuePriority.Command); } msg = new Msg((byte) 0xFF, Defs.REQUEST, Defs.FUNC_ID_SERIAL_API_GET_INIT_DATA, false); queue.sendMsg(msg, QueuePriority.Command); msg = new Msg( (byte) 0xFF, Defs.REQUEST, Defs.FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION, false, false); msg.appends(new byte[] {Defs.APPLICATION_NODEINFO_LISTENING, 0x02, 0x01, 0x01, 0x2B}); // msg.appends(new byte[] { Defs.APPLICATION_NODEINFO_LISTENING, 0x02, // 0x01, 0x00 }); queue.sendMsg(msg, QueuePriority.Command); }
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 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; }
public boolean isNodeExist(byte nodeId) { return nodes.get(SafeCast.toInt(nodeId)) != null; }