void uploadFirmwareImage ( final BluetoothGattCharacteristic packetCharacteristic ) throws DeviceDisconnectedException , DfuException , UploadAbortedException { if ( mAborted ) throw new UploadAbortedException ( ) ; mReceivedData = null ; mError = 0 ; mFirmwareUploadInProgress = true ; mPacketsSentSinceNotification = 0 ; final byte [ ] buffer = mBuffer ; try { final int size = mFirmwareStream . read ( buffer ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_VERBOSE , "Sending firmware to characteristic " + packetCharacteristic . getUuid ( ) + "..." ) ; writePacket ( mGatt , packetCharacteristic , buffer , size ) ; } catch ( final HexFileValidationException e ) { throw new DfuException ( "HEX file not valid" , DfuBaseService . ERROR_FILE_INVALID ) ; } catch ( final IOException e ) { throw new DfuException ( "Error while reading file" , DfuBaseService . ERROR_FILE_IO_EXCEPTION ) ; } try { synchronized ( mLock ) { while ( ( mFirmwareUploadInProgress && mReceivedData == null && mConnected && mError == 0 ) || mPaused ) mLock . wait ( ) ; } } catch ( final InterruptedException e ) { loge ( "Sleeping interrupted" , e ) ; } if ( ! mConnected ) throw new DeviceDisconnectedException ( "Uploading Firmware Image failed: device disconnected" ) ; if ( mError != 0 ) throw new DfuException ( "Uploading Firmware Image failed" , mError ) ; }
Starts sending the data . This method is SYNCHRONOUS and terminates when the whole file will be uploaded or the device get disconnected . If connection state will change or an error will occur an exception will be thrown .