Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class BluetoothCharacteristic {
.where((p) => p.remoteId == request.remoteId)
.where((p) => p.serviceUuid == request.serviceUuid)
.where((p) => p.characteristicUuid == request.characteristicUuid)
.where((p) => p.primaryServiceUuid == request.primaryServiceUuid);
.where((p) => p.primaryServiceUuid == request.primaryServiceUuid)
.where((p) => p.receiveEvent != BmReceiveEventEnum.notify);

// Start listening now, before invokeMethod, to ensure we don't miss the response
Future<BmCharacteristicData> futureResponse = responseStream.first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status)
}

// called for both notifications & reads
public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status)
public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status, int receiveEvent)
{
// GATT Service?
if (uuidStr(characteristic.getService().getUuid()) == "1800") {
Expand All @@ -2306,6 +2306,7 @@ public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteri
if (primaryService != null) {
response.put("primary_service_uuid", uuidStr(primaryService.getUuid()));
}
response.put("receive_event", receiveEvent);

invokeMethodUIThread("OnCharacteristicReceived", response);
}
Expand All @@ -2318,7 +2319,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
LogLevel level = LogLevel.DEBUG;
log(level, "onCharacteristicChanged:");
log(level, " chr: " + uuidStr(characteristic.getUuid()));
onCharacteristicReceived(gatt, characteristic, value, BluetoothGatt.GATT_SUCCESS);
onCharacteristicReceived(gatt, characteristic, value, BluetoothGatt.GATT_SUCCESS, 2); // see BmReceiveEventEnum
}

@Override
Expand All @@ -2330,7 +2331,7 @@ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic
log(level, "onCharacteristicRead:");
log(level, " chr: " + uuidStr(characteristic.getUuid()));
log(level, " status: " + gattErrorString(status) + " (" + status + ")");
onCharacteristicReceived(gatt, characteristic, value, status);
onCharacteristicReceived(gatt, characteristic, value, status, 1); // see BmReceiveEventEnum
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ - (void)peripheral:(CBPeripheral *)peripheral
@"success": error == nil ? @(1) : @(0),
@"error_string": error ? [error localizedDescription] : @"success",
@"error_code": error ? @(error.code) : @(0),
@"receive_event": @(0), // see BmReceiveEventEnum
} mutableCopy];

// remove if null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ class BmReadCharacteristicRequest {
}
}

enum BmReceiveEventEnum {
unknown, // 0
read, // 1
notify, // 2
}

class BmCharacteristicData {
final DeviceIdentifier remoteId;
final Guid serviceUuid;
Expand All @@ -468,6 +474,7 @@ class BmCharacteristicData {
final bool success;
final int errorCode;
final String errorString;
final BmReceiveEventEnum receiveEvent;


BmCharacteristicData({
Expand All @@ -479,6 +486,7 @@ class BmCharacteristicData {
required this.success,
required this.errorCode,
required this.errorString,
this.receiveEvent = BmReceiveEventEnum.unknown,
});

factory BmCharacteristicData.fromMap(Map<dynamic, dynamic> json) {
Expand All @@ -491,6 +499,7 @@ class BmCharacteristicData {
success: json['success'] != 0,
errorCode: json['error_code'],
errorString: json['error_string'],
receiveEvent: BmReceiveEventEnum.values[json['receive_event']],
);
}
}
Expand Down