Esempio n. 1
0
  private boolean runTest(int inPin, int outPin) throws Exception {
    if (outPin == 9) {
      // pin 9 doesn't support peripheral output
      return true;
    }
    final int BYTE_COUNT = 2000;
    final int SEED = 17;

    Uart uart = ioio_.openUart(inPin, outPin, 115200, Uart.Parity.NONE, Uart.StopBits.ONE);
    InputStream in = uart.getInputStream();
    OutputStream out = uart.getOutputStream();
    Random rand = new Random(SEED);
    bytesVerified_ = 0;
    Thread reader = new ReaderThread(in, SEED, BYTE_COUNT);
    reader.start();
    try {
      for (int i = 0; i < BYTE_COUNT; ++i) {
        byte value = (byte) rand.nextInt();
        out.write(value);
      }
      reader.join();
    } catch (Exception e) {
      try {
        in.close();
      } catch (IOException e1) {
      }
      reader.interrupt();
      reader.join();
      throw e;
    } finally {
      uart.close();
    }
    if (bytesVerified_ != BYTE_COUNT) {
      Log.w(
          "IOIOTortureTest",
          "Failed UartTest input: "
              + inPin
              + ", output: "
              + outPin
              + ". Bytes passed: "
              + bytesVerified_);
      return false;
    }
    return true;
  }