/**
* Asynchronously reads all characteristics from the given service. The DataAvailable will be raised when the data is available.
*/
public void ReadData(String Service) {
ReadData2(Service, null);
}
/**
* Asynchronously reads the value of the specified characteristic.
*The DataAvailable will be raised when the data of this characteristic is available.
*/
public void ReadData2(String Service, String Characteristic) {
synchronized (charsToReadQueue) {
boolean queueWasEmpty = charsToReadQueue.isEmpty();
boolean atLeastOneReadable = false;
BluetoothGattService ser = getService(Service);
for (BluetoothGattCharacteristic chr : readableCharsFromService(ser)) {
if (Characteristic == null || chr.getUuid().toString().equals(Characteristic)) {
charsToReadQueue.add(chr);
atLeastOneReadable = true;
}
}
if (atLeastOneReadable) {
if (queueWasEmpty){
/* gatt.readCharacteristic(charsToReadQueue.get(0));
*/
Map data = new Map();
data.Initialize();
for (BluetoothGattCharacteristic chr : ser.getCharacteristics()) {
String uuid = chr.getUuid().toString();
data.Put(uuid, new byte[0]);
}
ba.raiseEventFromDifferentThread(BleManagerMY.this, null, 0, eventName + "_dataavailable", false,
new Object[] {Service, data});
}
}
else {
if (Characteristic == null) {
Map data = new Map();
data.Initialize();
for (BluetoothGattCharacteristic chr : ser.getCharacteristics()) {
String uuid = chr.getUuid().toString();
data.Put(uuid, new byte[0]);
}
ba.raiseEventFromDifferentThread(BleManagerMY.this, null, 0, eventName + "_dataavailable", false,
new Object[] {Service, data});
}
else {
BA.LogInfo("No matching characteristic found.");
}
}
}
}