Example #1
0
  @Override
  public void run() {
    logger.info("Response Parser Running");
    if (!Main.LOGLEVEL.equals("OFF")) {
      Main.print("[+]Response Parser Thread Running...");
    }
    while (RUN) {
      try {
        line = TinygDriver.jsonQueue.take();
        if (line.equals("")) {
          continue;
        }
        if (line.startsWith("{")) {
          if (isTEXT_MODE()) {
            setTEXT_MODE(false);
            // This checks to see if we WERE in textmode.  If we were we notify the user that we are
            // not longer and update the system state.
            setChanged();
            message[0] = "TEXTMODE_REPORT";
            message[1] =
                "[+]JSON Response Detected... Leaving Text mode..  Querying System State....\n";
            notifyObservers(message);
            try {
              TinygDriver.getInstance().cmdManager.queryAllMachineSettings();
              TinygDriver.getInstance().cmdManager.queryAllHardwareAxisSettings();
              TinygDriver.getInstance().cmdManager.queryAllMotorSettings();
            } catch (Exception ex) {
              logger.error(
                  "Error leaving Text mode and querying Motor, Machine and Axis Settings.");
            }
          }
          parseJSON(line); // Take a line from the response queue when its ready and parse it.

        } else {
          // Text Mode Response
          if (!isTEXT_MODE()) {
            // We are just entering text mode and need to alert the user.
            // This will fire the every time user is entering text mode.
            setTEXT_MODE(true);
            setChanged();
            message[0] = "TEXTMODE_REPORT";
            message[1] = "[+]User has entered text mode.  To exit type \"{\" and hit enter.\n";
            notifyObservers(message);
          }
          setChanged();
          message[0] = "TEXTMODE_REPORT";
          message[1] = line + "\n";
          notifyObservers(message);
        }
      } catch (InterruptedException | JSONException ex) {
        logger.error("[!]Error in responseParser run(): " + ex.getMessage());
      }
    }
  }