With Bluetooth LE GATT service, is processing Characteristics and Descriptors sequentially an acceptable way to go?

23 Views Asked by At

I'm writing a service that connects to a bluetooth LE device.
I am iterating through the various services looking for the ones I'm interested in.
At the moment I'm looking at battery services. Some devices (like wireless headphones) have multiple batteries.
Right now I am connecting to the GATT server, then in my callback, I'm iterating through the services. When I find one I'm interested in I push the characteristic to a (thread safe) queue, then get the descriptor for that characteristic and push that to the queue too.
Then I process each item calling either gatt.readCharacteristic() or gatt.readDescriptor() depending on what's next in the queue.

Since I always put the the characteristic first, then the descriptor after, and no item in the queue is processed until the preceding item is complete; they will always be processed in that order.
Then in the onCharacteristicRead() callback I create a new object to represent it and add it to a list, then when onDescriptorRead() is called I take the last object from the list and add the descriptor to it.
Is this a reasonable way to do things?
I don't expect there to ever be more than two or three Characteristics that I'm interested in.

0

There are 0 best solutions below