Hi i am trying to build my first app with RxJava and BLE and i have a question: I made a wite(byte b) method in singletone class(that i use for connection, notifications, etc..). So now if i want to write data to BLE device i call this method. I need to do this a lot from different parts of code. I am very new to RxJava concept, and i feel like i am doing wrong. Current solution:
public void write(byte[] b) {
if (isConnected()) {
connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristicUuid, b))
.subscribe(bytes -> {
onWriteSuccess(bytes);
}, this::onWriteFailure);
}
}
I feel like i need to do something like that, but i dont know how:
protected static final BlockingQueue<byte[]> TxQueue = new ArrayBlockingQueue<>(32);
public void write(byte[] b) {
TxQueue.add(bytes);
}
And call this only once during connection to device:
connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristicUuid, TxQueue.take))
.subscribe(bytes -> {
onWriteSuccess(bytes);
}, this::onWriteFailure);
Thanks for an answer!