Esempio n. 1
0
  public void programBlock() {
    if (!mProgramming) return;

    if (iBlocks < nBlocks) {
      mProgramming = true;

      // Prepare block
      mOadBuffer[0] = Conversion.loUint16((short) iBlocks);
      mOadBuffer[1] = Conversion.hiUint16((short) iBlocks);
      System.arraycopy(mFileBuffer, iBytes, mOadBuffer, 2, OAD_BLOCK_SIZE);

      // Send block
      mCharBlock.setValue(mOadBuffer);
      boolean success = mBtLeService.writeCharacteristicNonBlock(deviceAddress, mCharBlock);
      Log.d(TAG, "Sent block : " + iBlocks + " to [" + deviceAddress + "]");
      if (success) {
        // Update stats
        packetsSent++;
        iBlocks++;
        iBytes += OAD_BLOCK_SIZE;

        if (isComplete()) {
          Log.d(TAG, "OAD Completed on [" + deviceAddress + "]");
        }
      } else {
        mProgramming = false;
        Log.e(TAG, "GATT writeCharacteristic failed on [" + deviceAddress + "]");
      }
    } else {
      mProgramming = false;
    }

    if (!mProgramming) {
      stopProgramming();
    }
  }