public void notifyNativeConnectionStateCallback(BluetoothGatt gatt, int status, int newState) { if (nativeCallback != null) { nativeCallback.onConnectionStateChange(gatt, status, newState); } }
void notifyNativeReadCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (nativeCallback != null) { nativeCallback.onCharacteristicRead(gatt, characteristic, status); } } }
public void notifyNativeWriteCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (nativeCallback != null) { nativeCallback.onCharacteristicWrite(gatt, characteristic, status); } }
public void notifyNativeServicesDiscoveredCallback(BluetoothGatt gatt, int status) { if (nativeCallback != null) { nativeCallback.onServicesDiscovered(gatt, status); } }
public void notifyNativeChangedCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if (nativeCallback != null) { nativeCallback.onCharacteristicChanged(gatt, characteristic); } }
public void notifyNativeDescriptorWriteCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { if (nativeCallback != null) { nativeCallback.onDescriptorWrite(gatt, descriptor, status); } }
public void notifyNativeReadRssiCallback(BluetoothGatt gatt, int rssi, int status) { if (nativeCallback != null) { nativeCallback.onReadRemoteRssi(gatt, rssi, status); } }
public void notifyNativeDescriptorReadCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { if (nativeCallback != null) { nativeCallback.onDescriptorRead(gatt, descriptor, status); } }
public void notifyNativeReliableWriteCallback(BluetoothGatt gatt, int status) { if (nativeCallback != null) { nativeCallback.onReliableWriteCompleted(gatt, status); } }
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { mGattCallback.onReadRemoteRssi(mBluetoothGatt, -666, BluetoothGatt.GATT_SUCCESS);
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { RxBleLog.d("onServicesDiscovered status=%d", status); nativeCallbackDispatcher.notifyNativeServicesDiscoveredCallback(gatt, status); super.onServicesDiscovered(gatt, status); if (servicesDiscoveredOutput.hasObservers() && !propagateErrorIfOccurred(servicesDiscoveredOutput, gatt, status, BleGattOperationType.SERVICE_DISCOVERY)) { servicesDiscoveredOutput.valueRelay.accept(new RxBleDeviceServices(gatt.getServices())); } }
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { RxBleLog.d("onCharacteristicChanged characteristic=%s", characteristic.getUuid()); nativeCallbackDispatcher.notifyNativeChangedCallback(gatt, characteristic); super.onCharacteristicChanged(gatt, characteristic); /* * It is important to call changedCharacteristicSerializedPublishRelay as soon as possible because a quick changing * characteristic could lead to out-of-order execution since onCharacteristicChanged may be called on arbitrary * threads. */ if (changedCharacteristicSerializedPublishRelay.hasObservers()) { changedCharacteristicSerializedPublishRelay.accept( new CharacteristicChangedEvent( characteristic.getUuid(), characteristic.getInstanceId(), characteristic.getValue() ) ); } }
@Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { RxBleLog.d("onDescriptorWrite descriptor=%s status=%d", descriptor.getUuid(), status); nativeCallbackDispatcher.notifyNativeDescriptorWriteCallback(gatt, descriptor, status); super.onDescriptorWrite(gatt, descriptor, status); if (writeDescriptorOutput.hasObservers() && !propagateErrorIfOccurred(writeDescriptorOutput, gatt, descriptor, status, BleGattOperationType.DESCRIPTOR_WRITE)) { writeDescriptorOutput.valueRelay.accept(new ByteAssociation<>(descriptor, descriptor.getValue())); } }
@Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { RxBleLog.d("onReadRemoteRssi rssi=%d status=%d", rssi, status); nativeCallbackDispatcher.notifyNativeReadRssiCallback(gatt, rssi, status); super.onReadRemoteRssi(gatt, rssi, status); if (readRssiOutput.hasObservers() && !propagateErrorIfOccurred(readRssiOutput, gatt, status, BleGattOperationType.READ_RSSI)) { readRssiOutput.valueRelay.accept(rssi); } }
@Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { RxBleLog.d("onCharacteristicRead descriptor=%s status=%d", descriptor.getUuid(), status); nativeCallbackDispatcher.notifyNativeDescriptorReadCallback(gatt, descriptor, status); super.onDescriptorRead(gatt, descriptor, status); if (readDescriptorOutput.hasObservers() && !propagateErrorIfOccurred(readDescriptorOutput, gatt, descriptor, status, BleGattOperationType.DESCRIPTOR_READ)) { readDescriptorOutput.valueRelay.accept(new ByteAssociation<>(descriptor, descriptor.getValue())); } }
@Override public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { RxBleLog.d("onReliableWriteCompleted status=%d", status); nativeCallbackDispatcher.notifyNativeReliableWriteCallback(gatt, status); super.onReliableWriteCompleted(gatt, status); }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { RxBleLog.d("onConnectionStateChange newState=%d status=%d", newState, status); nativeCallbackDispatcher.notifyNativeConnectionStateCallback(gatt, status, newState); super.onConnectionStateChange(gatt, status, newState); bluetoothGattProvider.updateBluetoothGatt(gatt); if (isDisconnectedOrDisconnecting(newState)) { disconnectionRouter.onDisconnectedException(new BleDisconnectedException(gatt.getDevice().getAddress(), status)); } else if (status != BluetoothGatt.GATT_SUCCESS) { disconnectionRouter.onGattConnectionStateException( new BleGattException(gatt, status, BleGattOperationType.CONNECTION_STATE) ); } connectionStatePublishRelay.accept(mapConnectionStateToRxBleConnectionStatus(newState)); }
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { RxBleLog.d("onCharacteristicRead characteristic=%s status=%d", characteristic.getUuid(), status); nativeCallbackDispatcher.notifyNativeReadCallback(gatt, characteristic, status); super.onCharacteristicRead(gatt, characteristic, status); if (readCharacteristicOutput.hasObservers() && !propagateErrorIfOccurred( readCharacteristicOutput, gatt, characteristic, status, BleGattOperationType.CHARACTERISTIC_READ )) { readCharacteristicOutput.valueRelay.accept(new ByteAssociation<>(characteristic.getUuid(), characteristic.getValue())); } }
@Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { RxBleLog.d("onCharacteristicWrite characteristic=%s status=%d", characteristic.getUuid(), status); nativeCallbackDispatcher.notifyNativeWriteCallback(gatt, characteristic, status); super.onCharacteristicWrite(gatt, characteristic, status); if (writeCharacteristicOutput.hasObservers() && !propagateErrorIfOccurred( writeCharacteristicOutput, gatt, characteristic, status, BleGattOperationType.CHARACTERISTIC_WRITE )) { writeCharacteristicOutput.valueRelay.accept(new ByteAssociation<>(characteristic.getUuid(), characteristic.getValue())); } }
@Override public void run() { userCallBack.onServicesDiscovered(bluetoothGatt, BluetoothGatt.GATT_SUCCESS); }},CALLBACK_DELAY_MS); return true;