dfu/src/main/java/no/nordicsemi/android/dfu/LegacyButtonlessDfuImpl.java
private int readVersion(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
		if (!mConnected)
			throw new DeviceDisconnectedException("Unable to read version number: device disconnected");
		if (mAborted)
			throw new UploadAbortedException();
		// If the DFU Version characteristic is not available we return 0.
		if (characteristic == null)
			return 0;

		mReceivedData = null;
		mError = 0;

		logi("Reading DFU version number...");
		mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_VERBOSE, "Reading DFU version number...");

		characteristic.setValue((byte[]) null);
		mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_DEBUG, "gatt.readCharacteristic(" + characteristic.getUuid() + ")");
		gatt.readCharacteristic(characteristic);

		// We have to wait until device receives a response or an error occur
		try {
			synchronized (mLock) {
				while (((!mRequestCompleted || characteristic.getValue() == null ) && mConnected && mError == 0 && !mAborted) || mPaused) {
					mRequestCompleted = false;
					mLock.wait();
				}
			}
		} catch (final InterruptedException e) {
			loge("Sleeping interrupted", e);
		}
		if (mError != 0)
			throw new DfuException("Unable to read version number", mError);
		if (!mConnected)
			throw new DeviceDisconnectedException("Unable to read version number: device disconnected");

		// The version is a 16-bit unsigned int
		return characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);
	}
/**
	 * Reads the DFU Version characteristic if such exists. Otherwise it returns 0.
	 *
	 * @param gatt the GATT device
	 * @param characteristic the characteristic to read
	 * @return a version number or 0 if not present on the bootloader
	 * @throws DeviceDisconnectedException
	 * @throws DfuException
	 * @throws UploadAbortedException
	 */
Reads the DFU Version characteristic if such exists. Otherwise it returns 0.
Reads the DFU Version characteristic if such exists . Otherwise it returns 0 .
private int readVersion(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
		if (!mConnected)
			throw new DeviceDisconnectedException("Unable to read version number: device disconnected");
		if (mAborted)
			throw new UploadAbortedException();
		if (characteristic == null)
			return 0;
		mReceivedData = null;
		mError = 0;
		logi("Reading DFU version number...");
		mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_VERBOSE, "Reading DFU version number...");
		characteristic.setValue((byte[]) null);
		mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_DEBUG, "gatt.readCharacteristic(" + characteristic.getUuid() + ")");
		gatt.readCharacteristic(characteristic);
		try {
			synchronized (mLock) {
				while (((!mRequestCompleted || characteristic.getValue() == null ) && mConnected && mError == 0 && !mAborted) || mPaused) {
					mRequestCompleted = false;
					mLock.wait();
				}
			}
		} catch (final InterruptedException e) {
			loge("Sleeping interrupted", e);
		}
		if (mError != 0)
			throw new DfuException("Unable to read version number", mError);
		if (!mConnected)
			throw new DeviceDisconnectedException("Unable to read version number: device disconnected");
		return characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);
	}
private int readVersion ( final BluetoothGatt gatt , final BluetoothGattCharacteristic characteristic ) throws DeviceDisconnectedException , DfuException , UploadAbortedException { if ( ! mConnected ) throw new DeviceDisconnectedException ( "Unable to read version number: device disconnected" ) ; if ( mAborted ) throw new UploadAbortedException ( ) ; if ( characteristic == null ) return 0 ; mReceivedData = null ; mError = 0 ; logi ( "Reading DFU version number..." ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_VERBOSE , "Reading DFU version number..." ) ; characteristic . setValue ( ( byte [ ] ) null ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_DEBUG , "gatt.readCharacteristic(" + characteristic . getUuid ( ) + ")" ) ; gatt . readCharacteristic ( characteristic ) ; try { synchronized ( mLock ) { while ( ( ( ! mRequestCompleted || characteristic . getValue ( ) == null ) && mConnected && mError == 0 && ! mAborted ) || mPaused ) { mRequestCompleted = false ; mLock . wait ( ) ; } } } catch ( final InterruptedException e ) { loge ( "Sleeping interrupted" , e ) ; } if ( mError != 0 ) throw new DfuException ( "Unable to read version number" , mError ) ; if ( ! mConnected ) throw new DeviceDisconnectedException ( "Unable to read version number: device disconnected" ) ; return characteristic . getIntValue ( BluetoothGattCharacteristic . FORMAT_UINT16 , 0 ) ; }
Reads the DFU Version characteristic if such exists.
Reads the DFU Version characteristic if such exists .
// If the DFU Version characteristic is not available we return 0. // We have to wait until device receives a response or an error occur // The version is a 16-bit unsigned int