Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT

The following examples show how to use android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testWriteFirstChunkFailed() throws IOException {
    InputSource inputSource = Mockito.mock(InputSource.class);
    doThrow(IOException.class).when(inputSource).open();

    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);

    WriteCommand writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);
    CommandResult result = CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    Mockito.reset(commandObserver, operationCommandObserver, inputSource);

    when(inputSource.nextChunk()).thenThrow(IOException.class);
    writeCommand.execute(device, operationCommandObserver, gatt);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
 
Example 2
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testOnCharacteristicWriteNextChunk() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenReturn(new byte[]{12, 21});

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);

    writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
    verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
    verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
}
 
Example 3
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testInputSourceClosesOnError() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenThrow(new IOException());

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);
    writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);

    verify(inputSource).close();
}
 
Example 4
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testOnCharacteristicWriteFinished() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenReturn(new byte[]{12, 21});

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);

    when(inputSource.nextChunk()).thenReturn(null);
    writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
    CommandResult result = CommandResult.createEmptySuccess(characteristicUUID);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(inputSource).close();
}
 
Example 5
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testOnCharacteristicWriteFai2() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenReturn(new byte[]{21, 22});

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);

    doThrow(IOException.class).when(inputSource).nextChunk();
    writeCommand.onCharacteristicWrite(gatt, gattCharacteristic, BluetoothGatt.GATT_SUCCESS);
    verifyCommandFail();
}
 
Example 6
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testWriteSuccess() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenReturn(new byte[]{21, 22});

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);
    verify(commandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
    verify(operationCommandObserver, times(0)).finished(any(Command.class), any(CommandResult.class));
    reset(commandObserver, operationCommandObserver);

    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(false);
    writeCommand.execute(device, operationCommandObserver, gatt);
    verifyCommandFail();
}
 
Example 7
Source File: WriteCommandTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
public void testWriteSuccessEmpty() throws IOException {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.readCharacteristic(eq(gattCharacteristic))).thenReturn(true);
    InputSource inputSource = Mockito.mock(InputSource.class);
    when(inputSource.nextChunk()).thenReturn(null);

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);
    CommandResult result = CommandResult.createEmptySuccess(characteristicUUID);
    verify(commandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
    verify(operationCommandObserver, times(1)).finished(eq(writeCommand), refEq(result, "timestamp"));
}
 
Example 8
Source File: WriteCommandTest.java    From neatle with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    InputSource inputSource = new StringInputSource("lorem ipsum dolor sit amet");
    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);
}
 
Example 9
Source File: WriteCommandTest.java    From neatle with MIT License 5 votes vote down vote up
@Test
public void testAsyncOnError() throws Exception {
    when(gatt.getService(eq(serviceUUID))).thenReturn(gattService);
    when(gattService.getCharacteristic(characteristicUUID)).thenReturn(gattCharacteristic);
    when(gatt.writeCharacteristic(eq(gattCharacteristic))).thenReturn(true);

    AsyncInputSource inputSource = Mockito.mock(AsyncInputSource.class);
    when(inputSource.nextChunk()).thenAnswer(new Answer<byte[]>()
    {
        @Override
        public byte[] answer(InvocationOnMock invocationOnMock) {
            writeCommand.onError(BluetoothGatt.GATT_FAILURE);
            return new byte[]{12, 21};
        }
    });

    writeCommand = new WriteCommand(
            serviceUUID,
            characteristicUUID,
            BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
            inputSource,
            commandObserver);

    writeCommand.execute(device, operationCommandObserver, gatt);

    while (writeCommand.readerThread.isAlive()) {
        Robolectric.getForegroundThreadScheduler().advanceBy(0, TimeUnit.MILLISECONDS);
        Thread.yield();
    }
    Robolectric.getForegroundThreadScheduler().advanceBy(0, TimeUnit.MILLISECONDS);

    verifyCommandFail();
    verify(inputSource).close();
}
 
Example 10
Source File: ParserUtils.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
public static String writeTypeToString(@WriteType final int type) {
	switch (type) {
		case BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT:
			return "WRITE REQUEST";
		case BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE:
			return "WRITE COMMAND";
		case BluetoothGattCharacteristic.WRITE_TYPE_SIGNED:
			return "WRITE SIGNED";
		default:
			return "UNKNOWN (" + type + ")";
	}
}
 
Example 11
Source File: BluetoothDebug.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private boolean isWriteType(int property, int writeType) {
    switch (property) {
        case BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;
        case BluetoothGattCharacteristic.PROPERTY_WRITE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
        case BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED;
    }
    return false;
}
 
Example 12
Source File: WriteRequest.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
WriteRequest(@NonNull final Type type, @Nullable final BluetoothGattDescriptor descriptor,
			 @Nullable final byte[] data,
			 @IntRange(from = 0) final int offset, @IntRange(from = 0) final int length) {
	super(type, descriptor);
	this.data = Bytes.copy(data, offset, length);
	this.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
}
 
Example 13
Source File: BlePeripheralUart.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
private void uartSendPacket(@NonNull byte[] data, int offset, BluetoothGattCharacteristic uartTxCharacteristic, int withResponseEveryPacketCount, int numPacketsRemainingForDelay, BlePeripheral.ProgressHandler progressHandler, BlePeripheral.CompletionHandler completionHandler) {
    final int packetSize = Math.min(data.length - offset, mBlePeripheral.getMaxPacketLength());
    final byte[] packet = Arrays.copyOfRange(data, offset, offset + packetSize);
    final int writeStartingOffset = offset;
    final int uartTxCharacteristicWriteType = numPacketsRemainingForDelay <= 0 ? BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT : BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;          // Send a packet WRITE_TYPE_DEFAULT to force wait until receive response and avoid dropping packets if the peripheral is not processing them fast enough

    mBlePeripheral.writeCharacteristic(uartTxCharacteristic, uartTxCharacteristicWriteType, packet, status -> {
        int writtenSize = writeStartingOffset;

        if (status != BluetoothGatt.GATT_SUCCESS) {
            Log.w(TAG, "Error " + status + " writing packet at offset" + writeStartingOffset + " Error: " + status);
        } else {
            Log.d(TAG, "uart tx " + (uartTxCharacteristicWriteType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE ? "withoutResponse" : "withResponse") + " offset " + writeStartingOffset + ": " + BleUtils.bytesToHex2(packet));

            writtenSize += packet.length;

            if (!mIsSendSequentiallyCancelled && writtenSize < data.length) {
                //int finalWrittenSize = writtenSize;
                //handler.postDelayed(() -> uartSendPacket(handler, data, finalWrittenSize, uartTxCharacteristic, uartTxCharacteristicWriteType, delayBetweenPackets, progressHandler, completionHandler), delayBetweenPackets);
                uartSendPacket(data, writtenSize, uartTxCharacteristic, withResponseEveryPacketCount, numPacketsRemainingForDelay <= 0 ? withResponseEveryPacketCount : numPacketsRemainingForDelay - 1, progressHandler, completionHandler);
            }
        }

        if (mIsSendSequentiallyCancelled) {
            completionHandler.completion(BluetoothGatt.GATT_SUCCESS);
        } else if (writtenSize >= data.length) {
            progressHandler.progress(1);
            completionHandler.completion(status);
        } else {
            progressHandler.progress(writtenSize / (float) data.length);
        }
    });
}
 
Example 14
Source File: WriteOptions.java    From easyble-x with Apache License 2.0 5 votes vote down vote up
/**
 * 设置写入模式
 *
 * @param writeType {@link BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT}
 *                  <br>{@link BluetoothGattCharacteristic#WRITE_TYPE_NO_RESPONSE}
 *                  <br>{@link BluetoothGattCharacteristic#WRITE_TYPE_SIGNED}
 */
public Builder setWriteType(int writeType) {
    if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT ||
            writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE ||
            writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED) {
        this.writeType = writeType;
    }            
    return this;
}
 
Example 15
Source File: P_Task_Write.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void executeReadOrWrite()
{
	m_data = m_futureData.getData();

	if( false == write_earlyOut(m_data) )
	{
		final BluetoothGattCharacteristic char_native = getFilteredCharacteristic() != null ? getFilteredCharacteristic() : getDevice().getNativeCharacteristic(getServiceUuid(), getCharUuid());

		if( char_native == null )
		{
			fail(Status.NO_MATCHING_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), ReadWriteEvent.NON_APPLICABLE_UUID);
		}
		else
		{
			// Set the write type now, if it is not null
			if (m_writeType != null)
			{
				if (m_writeType == Type.WRITE_NO_RESPONSE)
				{
					char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
				}
				else if (m_writeType == Type.WRITE_SIGNED)
				{
					char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_SIGNED);
				}
				else if (char_native.getWriteType() != BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
				{
					char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
				}
			}

			if( false == getDevice().layerManager().setCharValue(char_native, m_data) )
			{
				fail(Status.FAILED_TO_SET_VALUE_ON_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), ReadWriteEvent.NON_APPLICABLE_UUID);
			}
			else
			{
				if( false == getDevice().layerManager().writeCharacteristic(char_native) )
				{
					fail(Status.FAILED_TO_SEND_OUT, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), ReadWriteEvent.NON_APPLICABLE_UUID);
				}
				else
				{
					// SUCCESS, for now...
				}
			}
		}
	}
}
 
Example 16
Source File: P_Task_TestMtu.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void executeReadOrWrite()
{
    if( false == write_earlyOut(m_data) )
    {
        final BluetoothGattCharacteristic char_native = getFilteredCharacteristic() != null ? getFilteredCharacteristic() : getDevice().getNativeCharacteristic(getServiceUuid(), getCharUuid());

        if( char_native == null )
        {
            fail(BleDevice.ReadWriteListener.Status.NO_MATCHING_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
        }
        else
        {
            // Set the write type now, if it is not null
            if (m_writeType != null)
            {
                if (m_writeType == BleDevice.ReadWriteListener.Type.WRITE_NO_RESPONSE)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
                }
                else if (m_writeType == BleDevice.ReadWriteListener.Type.WRITE_SIGNED)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_SIGNED);
                }
                else if (char_native.getWriteType() != BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
                }
            }

            if( false == getDevice().layerManager().setCharValue(char_native, m_data) )
            {
                fail(BleDevice.ReadWriteListener.Status.FAILED_TO_SET_VALUE_ON_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
            }
            else
            {
                if( false == getDevice().layerManager().writeCharacteristic(char_native) )
                {
                    fail(BleDevice.ReadWriteListener.Status.FAILED_TO_SEND_OUT, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
                }
                else
                {
                    // SUCCESS, for now...
                }
            }
        }
    }
}
 
Example 17
Source File: P_Task_TestMtu.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void executeReadOrWrite()
{
    if( false == write_earlyOut(m_data) )
    {
        final BluetoothGattCharacteristic char_native = getFilteredCharacteristic() != null ? getFilteredCharacteristic() : getDevice().getNativeCharacteristic(getServiceUuid(), getCharUuid());

        if( char_native == null )
        {
            fail(BleDevice.ReadWriteListener.Status.NO_MATCHING_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
        }
        else
        {
            // Set the write type now, if it is not null
            if (m_writeType != null)
            {
                if (m_writeType == BleDevice.ReadWriteListener.Type.WRITE_NO_RESPONSE)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
                }
                else if (m_writeType == BleDevice.ReadWriteListener.Type.WRITE_SIGNED)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_SIGNED);
                }
                else if (char_native.getWriteType() != BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
                {
                    char_native.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
                }
            }

            if( false == getDevice().layerManager().setCharValue(char_native, m_data) )
            {
                fail(BleDevice.ReadWriteListener.Status.FAILED_TO_SET_VALUE_ON_TARGET, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
            }
            else
            {
                if( false == getDevice().layerManager().writeCharacteristic(char_native) )
                {
                    fail(BleDevice.ReadWriteListener.Status.FAILED_TO_SEND_OUT, BleStatuses.GATT_STATUS_NOT_APPLICABLE, getDefaultTarget(), getCharUuid(), BleDevice.ReadWriteListener.ReadWriteEvent.NON_APPLICABLE_UUID);
                }
                else
                {
                    // SUCCESS, for now...
                }
            }
        }
    }
}
 
Example 18
Source File: Request.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates new Write Characteristic request. The request will not be executed if given
 * characteristic is null or does not have WRITE property.
 * After the operation is complete a proper callback will be invoked.
 *
 * @param characteristic characteristic to be written.
 * @param value          value to be written. The array is copied into another buffer so it's
 *                       safe to reuse the array again.
 * @param offset         the offset from which value has to be copied.
 * @param length         number of bytes to be copied from the value buffer.
 * @return The new request.
 * @deprecated Access to this method will change to package-only.
 * Use {@link BleManager#writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int)}
 * instead.
 */
@Deprecated
@NonNull
public static WriteRequest newWriteRequest(
		@Nullable final BluetoothGattCharacteristic characteristic,
		@Nullable final byte[] value,
		@IntRange(from = 0) final int offset, @IntRange(from = 0) final int length) {
	return new WriteRequest(Type.WRITE, characteristic, value, offset, length,
			characteristic != null ?
					characteristic.getWriteType() :
					BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
}
 
Example 19
Source File: Request.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates new Write Characteristic request. The request will not be executed if given
 * characteristic is null or does not have WRITE property.
 * After the operation is complete a proper callback will be invoked.
 *
 * @param characteristic characteristic to be written.
 * @param value          value to be written. The array is copied into another buffer so it's
 *                       safe to reuse the array again.
 * @return The new request.
 * @deprecated Access to this method will change to package-only.
 * Use {@link BleManager#writeCharacteristic(BluetoothGattCharacteristic, byte[])} instead.
 */
@Deprecated
@NonNull
public static WriteRequest newWriteRequest(
		@Nullable final BluetoothGattCharacteristic characteristic,
		@Nullable final byte[] value) {
	return new WriteRequest(Type.WRITE, characteristic, value, 0,
			value != null ? value.length : 0,
			characteristic != null ?
					characteristic.getWriteType() :
					BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
}
 
Example 20
Source File: OperationBuilder.java    From neatle with MIT License 2 votes vote down vote up
/**
 * Writes data to a characteristic of a service.
 *
 * @param serviceUUID         the UUID of the service
 * @param characteristicsUUID the UUID of the characteristic.
 * @param source              the source of data for the write command
 * @param observer            the operation observer - callback
 * @return this object
 */
public OperationBuilder write(UUID serviceUUID, UUID characteristicsUUID, InputSource source, CommandObserver observer) {
    WriteCommand cmd = new WriteCommand(serviceUUID, characteristicsUUID, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT, source, observer);
    commands.add(cmd);
    return this;
}