public Object executeCommand(Command c, long wait) throws ZigBeeException, SerialException { String command = c.commandString; Object argument = c.argument; ZigBee local = getLocalNoCreate(); local.enterAPIMode(); if (local == this) { return executeLocalCommand(c, command, argument, wait); } else { return executeRemoteCommand(c, command, argument, wait); } }
public static ZigBee getLocal() throws ZigBeeException, SerialException { synchronized (getLocalLock) { if (local != null) { if (serialPort == null) { serialPort = new Serial(); if (local.apiMode) { serialPort.addListener(local); } } return local; } try { ZigBee l = new ZigBee(); local = l; // must do this first, otherwise isLocal fails. // l isn't really complete yet, but it's good enough for // local communications. l.enterAPIMode(); // Just queue up these commands and let the incoming // api message processor deal with the results. l.executeCommand("SL", null, internalWait); l.executeCommand("SH", null, internalWait); l.executeCommand("NI", null, internalWait); l.executeCommand("MY", null, internalWait); l.executeCommand("ID", null, internalWait); l.executeCommand("DL", null, internalWait); l.executeCommand("DH", null, internalWait); // Can't get profile id and manufacturer_id with out doing a loop back node id. l.bps = Long.parseLong(Preferences.get("serial.debug_rate")); l.parity = Preferences.get("serial.parity").charAt(0); return l; } catch (Exception e) { close(); local = null; e.printStackTrace(); if (e instanceof ZigBeeException) { throw (ZigBeeException) e; } else if (e instanceof SerialException) { throw (SerialException) e; } throw new ZigBeeException(e.getMessage()); } } }