public static ZigBee[] getNodes() { synchronized (knownNodes) { ZigBee[] z = new ZigBee[1]; return knownNodes.values().toArray(z); } }
void processCommandResponse(byte[] packet, int offset) throws ZigBeeException, SerialException { String command = new String(packet, offset, 2); // commands are all 2 characters. Command c; synchronized (outstandingCommands) { c = outstandingCommands.get(packet[4]); } if (c == null) { System.err.println("Command " + command + " command already timed out or not issued."); } else { if (c.command != ZigBeeCommands.ND || packet.length == 9) { c.status = new Byte(packet[offset + 2]); synchronized (outstandingCommands) { outstandingCommands.values().remove(c); } } else { c = null; } } if (packet[offset + 2] != 0) { // Need to get the message to the user. if (c != null && packet[offset + 2] == 4) { if (c.retransmits++ < c.maxRetransmits) { executeCommand(c, 0); return; } } if (c != null) { synchronized (c) { c.notifyAll(); } } return; } // Did we get some data back as well? if (packet.length > offset + 4) { command = command.toUpperCase(); ZigBeeCommands zbc; try { zbc = ZigBeeCommands.valueOf(command); if (c != null) { if (zbc.responseString) { c.response = bytesToString(packet, offset + 3, packet.length - offset - 1); } else { c.response = new Long(bytesToNum(packet, offset + 3, 8, packet.length - 1)); } } zbc.process(this, packet, offset + 3); } catch (IllegalArgumentException iae) { if (c != null) { c.response = new Long(bytesToNum(packet, offset + 3, 8, packet.length - 1)); } // unhandled message, just ignore it. } } // let any waiters know we are done. if (c != null) { synchronized (c) { c.notifyAll(); } } }