示例#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();
    }
  }
示例#2
0
 /**
  * Make sure connection interval is long enough for OAD (Android default connection interval is
  * 7.5 ms)
  */
 private void setConnectionParameters() {
   byte[] value = {
     Conversion.loUint16(OAD_CONN_INTERVAL),
     Conversion.hiUint16(OAD_CONN_INTERVAL),
     Conversion.loUint16(OAD_CONN_INTERVAL),
     Conversion.hiUint16(OAD_CONN_INTERVAL),
     0,
     0,
     Conversion.loUint16(OAD_SUPERVISION_TIMEOUT),
     Conversion.hiUint16(OAD_SUPERVISION_TIMEOUT)
   };
   mCharConnReq.setValue(value);
   mBtLeService.writeCharacteristic(deviceAddress, mCharConnReq);
 }