@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());
      }
    }
  }
Exemple #2
0
  void loadFS() throws Exception {
    byte sb[] = new byte[1024];
    file.seek(0);
    file.read(sb);
    superBlock = new SuperBlock(sb);
    superBlock.loadDMap(superBlock.getLatestVerison(), file);
    lastblock = superBlock.lastblock;
    version = superBlock.getLatestVerison();

    Main.print("\nVersion Loaded:  " + version + "\n");
  }
  public synchronized void parseJSON(String line) throws JSONException {

    // logger.info("Got Line: " + line + " from TinyG.");
    if (!Main.LOGLEVEL.equals("OFF")) {
      Main.print("-" + line);
    }

    final JSONObject js = new JSONObject(line);

    if (js.has("r")
        || (js.has("sr"))
        || (js.has("tgfx"))) { // tgfx is for messages like timeout connections
      Platform.runLater(
          new Runnable() {
            @Override
            public void run() {
              try {

                if (js.has("tgfx")) {
                  // This is for when tgfx times out when trying to connect to TinyG.
                  // tgFX puts a message in the response parser queue to be parsed here.
                  setChanged();
                  message[0] = "TINYG_CONNECTION_TIMEOUT";
                  message[1] = (String) js.get("tgfx") + "\n";
                  notifyObservers(message);

                } else if (js.has("f")) {
                  // The new version of TinyG's footer has a footer element in each response.
                  // We parse it here
                  parseFooter(js.getJSONArray("f"));
                  if (js.has("r")) {
                    applySetting(js.getJSONObject("r"));
                  } else if (js.has("sr")) {
                    applySettingStatusReport(js.getJSONObject("sr"));
                  }

                } else { // This is where the old footer style is dealt with

                  // These are the 2 types of responses we will get back.
                  switch (js.keys().next().toString()) {
                    case ("r"):
                      applySetting(js.getJSONObject("r"));
                      break;
                    case ("sr"):
                      applySettingStatusReport(js.getJSONObject("sr"));
                      break;
                  }
                }

              } catch (JSONException ex) {
                logger.error(ex);
              }
            }
          });

    } else if (js.has("qr")) {
      TinygDriver.getInstance().qr.parse(js);
    } else if (js.has("er")) {
      applySetting(js);
    }
  }
Exemple #4
0
 public static void main(String[] args) throws IOException {
   BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
   String s;
   char c;
   String[] q;
   List<String[]> list = new ArrayList<String[]>();
   String[] t;
   for (int i = 0; i < 17; i++) {
     if (i % 2 == 0) {
       read.readLine();
       continue;
     }
     s = read.readLine();
     q = s.split("\\|");
     for (int j = 1; j <= 8; j++) {
       c = q[j].charAt(1);
       if (c == '.' || c == ':') {
         continue;
       }
       t = new String[2];
       t[0] = "" + c;
       t[1] = "" + a[j - 1] + (8 - i / 2);
       list.add(t);
     }
   }
   System.out.print("White: ");
   print("K", list);
   print("Q", list);
   print("R", list);
   print("B", list);
   print("N", list);
   print("P", list);
   System.out.println();
   System.out.print("Black: ");
   print("k", list);
   print("q", list);
   print("r", list);
   print("b", list);
   print("n", list);
   print("p", list);
   System.out.println();
 }