Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import no.nordicsemi.android.ble.annotation.PairingVariant;
import no.nordicsemi.android.ble.annotation.PhyMask;
import no.nordicsemi.android.ble.annotation.PhyOption;
import no.nordicsemi.android.ble.annotation.WriteType;
import no.nordicsemi.android.ble.observer.BondingObserver;
import no.nordicsemi.android.ble.observer.ConnectionObserver;
import no.nordicsemi.android.ble.callback.ConnectionPriorityCallback;
Expand Down Expand Up @@ -1273,6 +1274,83 @@ protected ReadRequest readCharacteristic(@Nullable final BluetoothGattCharacteri
.setRequestHandler(requestHandler);
}

/**
* Writes the given data to the characteristic.
* <p>
* Use {@link WriteRequest#split() split()} or
* {@link WriteRequest#split(DataSplitter) split(DataSplitter)} on the returned
* {@link WriteRequest} if data should be automatically split into multiple packets.
* If the characteristic is null, the {@link Request#fail(FailCallback) fail(FailCallback)}
* callback will be called.
* <p>
* The returned request must be either enqueued using {@link Request#enqueue()} for
* asynchronous use, or awaited using await() in synchronous execution.
*
* @param characteristic the characteristic to write to.
* @param data data to be written to the characteristic.
* @param writeType the write type which is to be used.
* @return The request.
*/
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final Data data,
@WriteType final int writeType) {
return Request.newWriteRequest(characteristic, data != null ? data.getValue() : null, writeType)
.setRequestHandler(requestHandler);
}

/**
* Writes the given data to the characteristic.
* <p>
* Use {@link WriteRequest#split() split()} or
* {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned
* {@link WriteRequest} if data should be automatically split into multiple packets.
* If the characteristic is null, the {@link Request#fail(FailCallback) fail(FailCallback)}
* callback will be called.
* <p>
* The returned request must be either enqueued using {@link Request#enqueue()} for
* asynchronous use, or awaited using await() in synchronous execution.
*
* @param characteristic the characteristic to write to.
* @param data data to be written to the characteristic.
* @param writeType the write type which is to be used.
* @return The request.
*/
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final byte[] data,
@WriteType final int writeType) {
return Request.newWriteRequest(characteristic, data, writeType)
.setRequestHandler(requestHandler);
}

/**
* Writes at most length bytes from offset at given data to the characteristic.
* <p>
* Use {@link WriteRequest#split() split()} or
* {@link WriteRequest#split(DataSplitter) split(ValueSplitter)} on the returned
* {@link WriteRequest} if data should be automatically split into multiple packets.
* If the characteristic is null, the {@link Request#fail(FailCallback) fail(FailCallback)}
* callback will be called.
* <p>
* The returned request must be either enqueued using {@link Request#enqueue()} for
* asynchronous use, or awaited using await() in synchronous execution.
*
* @param characteristic the characteristic to write to.
* @param data data to be written to the characteristic.
* @param offset index of the first byte to be sent.
* @param length number of bytes to be sent.
* @param writeType the write type which is to be used.
* @return The request.
*/
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final byte[] data, final int offset, final int length,
@WriteType final int writeType) {
return Request.newWriteRequest(characteristic, data, offset, length, writeType)
.setRequestHandler(requestHandler);
}

/**
* Writes the given data to the characteristic. The write type is taken from the characteristic.
* <p>
Expand All @@ -1288,7 +1366,9 @@ protected ReadRequest readCharacteristic(@Nullable final BluetoothGattCharacteri
* @param characteristic the characteristic to write to.
* @param data data to be written to the characteristic.
* @return The request.
* @deprecated Use {@link #writeCharacteristic(BluetoothGattCharacteristic, Data, int)} instead.
*/
@Deprecated
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final Data data) {
Expand All @@ -1311,7 +1391,9 @@ protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacte
* @param characteristic the characteristic to write to.
* @param data data to be written to the characteristic.
* @return The request.
* @deprecated Use {@link #writeCharacteristic(BluetoothGattCharacteristic, byte[], int)} instead.
*/
@Deprecated
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final byte[] data) {
Expand All @@ -1337,7 +1419,9 @@ protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacte
* @param offset index of the first byte to be sent.
* @param length number of bytes to be sent.
* @return The request.
* @deprecated Use {@link #writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int, int)} instead.
*/
@Deprecated
@NonNull
protected WriteRequest writeCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic,
@Nullable final byte[] data, final int offset, final int length) {
Expand Down