How to implement synchronous task queue for RxAndroidBle

How to implement synchronous task queue for RxAndroidBle



I use RxAndroidBle as the BLE communication framework in my project. I receive the data from the notification after writing in the following way:


public Observable<byte> requestCharacteristic(UUID notificationUuid, UUID writeUuid, byte writeData)
return Observable.zip(
connectionObservable.concatMap(rxConnection -> rxConnection.setupNotification(notificationUuid))
.concatMap(rxConnection -> rxConnection).first(),
connectionObservable.concatMap(rxConnection -> rxConnection.writeCharacteristic(writeUuid, writeData)),
(responseBytes, writeBytes) -> return responseBytes;
);



Because the BLE device needs to guarantee the synchronization request by the mobile phone, the request must be completed after the request execution is completed. I am not familiar with RX. How can I do the FIFO way to execute the above code?




1 Answer
1



As you have stated your code will work for a single execution but when there would be multiple parallel requests they will not get serialised. What you would need to add is an external synchronisation for your requestCharacteristic() function.


requestCharacteristic()



There is an already answered question for keeping a persistant connection with serialised write/notification handling which may be exactly what you are looking for. The answer was created for the library version that was based on RxJava1 but it should not be too hard to adjust it to RxJava2.


RxJava1


RxJava2






Thanks , this way can make logical serial

– Zachary
Sep 13 '18 at 8:46



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế