示例#1
0
  // only works locally.
  void enterCommandMode() throws ZigBeeException, SerialException {
    if (serialPort == null) {
      serialPort = new Serial();
    }
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }

    serialPort.addListener(null);

    String s = new String("+++");
    serialPort.write(s);

    do {
      s = serialPort.waitForData(1500);

      if (s != null) {
        if (s.indexOf("OK") >= 0) {
          return;
        }
      }
    } while (s != null);

    close();
    throw new ZigBeeException("Unable to enter command mode.");
  }
示例#2
0
 void closeSerial() {
   if (serialPort != null) {
     serialPort.addListener(null);
     serialPort.dispose();
     serialPort = null;
   }
 }
示例#3
0
 public void exitAPIMode() throws ZigBeeException, SerialException {
   if (!apiMode) {
     return;
   }
   executeCommand("AP", new Integer(0), internalWait);
   serialPort.addListener(null);
   serialPort.dispose();
   serialPort = null;
   apiMode = false;
 }
示例#4
0
  // should work remotely, but probably a bad idea.
  public void enterAPIMode() throws ZigBeeException, SerialException {
    if (apiMode) {
      return;
    }

    // can't do this locally since we use API mode to execute the command.
    if (!isLocal()) {
      executeCommand("AP", new Integer(1), internalWait);
    } else {
      enterCommandMode();
      serialPort.write("ATAP1\r\n");
      serialPort.waitForData(internalWait);
      exitCommandMode();
      serialPort.addListener(this);
      apiMode = true;
    }
  }
示例#5
0
  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());
      }
    }
  }