示例#1
0
  /**
   * Send whole buffer - this will be the task which will be run periodically
   *
   * @throws InterruptedException
   */
  public void sendBuffer(Vector<data.Data> dataToSend, Long duration)
      throws IOException, BCDPrecisionException, InterruptedException {
    Iterator<data.Data> iDataToSend = dataToSend.iterator();

    /* Duration as BCD */
    Long durationBCD = Long.parseLong(duration.toString(), 16);

    /* Send start byte */
    outputStream.write(0xFF);

    /* Send duration */
    outputStream.write(Data.intToByteArray(durationBCD));

    /* For each element */
    while (iDataToSend.hasNext()) {
      /* Get current data */
      data.Data current = iDataToSend.next();

      /* Send single data */
      send(current);

      /* Wait as it was specified by the user */
      Thread.sleep(5);
    }

    /* Send finish byte */
    outputStream.write(0xAA);
  }
示例#2
0
  /** based on http://www.exampledepot.com/egs/java.net/Post.html */
  private void GetNewRobotUID() {
    try {
      // Send data
      URL url = new URL("http://marginallyclever.com/drawbot_getuid.php");
      URLConnection conn = url.openConnection();
      BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      robot_uid = Long.parseLong(rd.readLine());
      rd.close();
    } catch (Exception e) {
    }

    // did read go ok?
    if (robot_uid != 0) {
      SendLineToRobot("UID " + robot_uid);
    }
  }
示例#3
0
  /**
   * Complete the handshake, load robot-specific configuration, update the menu, repaint the preview
   * with the limits.
   *
   * @return true if handshake succeeds.
   */
  public boolean ConfirmPort() {
    if (portConfirmed == true) return true;
    String hello = "HELLO WORLD! I AM DRAWBOT #";
    int found = line3.lastIndexOf(hello);
    if (found >= 0) {
      portConfirmed = true;

      // get the UID reported by the robot
      String[] lines = line3.substring(found + hello.length()).split("\\r?\\n");
      if (lines.length > 0) {
        try {
          robot_uid = Long.parseLong(lines[0]);
        } catch (NumberFormatException e) {
        }
      }

      // new robots have UID=0
      if (robot_uid == 0) GetNewRobotUID();

      mainframe.setTitle("Drawbot #" + Long.toString(robot_uid) + " connected");

      // load machine specific config
      GetRecentPaperSize();
      LoadConfig();
      if (limit_top == 0 && limit_bottom == 0 && limit_left == 0 && limit_right == 0) {
        UpdateConfig();
      }

      previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right);
      SendConfig();

      UpdateMenuBar();
      previewPane.setConnected(true);
    }
    return portConfirmed;
  }