com.polidea.rxandroidble2.RxBleDeviceServices Java Examples

The following examples show how to use com.polidea.rxandroidble2.RxBleDeviceServices. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public Single<byte[]> readDescriptor(@NonNull final UUID serviceUuid, @NonNull final UUID characteristicUuid,
                                         @NonNull final UUID descriptorUuid) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, SingleSource<BluetoothGattDescriptor>>() {
                @Override
                public SingleSource<BluetoothGattDescriptor> apply(RxBleDeviceServices rxBleDeviceServices) {
                    return rxBleDeviceServices.getDescriptor(serviceUuid, characteristicUuid, descriptorUuid);
                }
            })
            .map(new Function<BluetoothGattDescriptor, byte[]>() {
                @Override
                public byte[] apply(BluetoothGattDescriptor bluetoothGattDescriptor) {
                    return bluetoothGattDescriptor.getValue();
                }
            });
}
 
Example #2
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public Completable writeDescriptor(@NonNull final UUID serviceUuid, @NonNull final UUID characteristicUuid,
                                          @NonNull final UUID descriptorUuid, @NonNull final byte[] data) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, SingleSource<BluetoothGattDescriptor>>() {
                @Override
                public SingleSource<BluetoothGattDescriptor> apply(RxBleDeviceServices rxBleDeviceServices) {
                    return rxBleDeviceServices.getDescriptor(serviceUuid, characteristicUuid, descriptorUuid);
                }
            })
            .doOnSuccess(new Consumer<BluetoothGattDescriptor>() {
                @Override
                public void accept(BluetoothGattDescriptor bluetoothGattDescriptor) throws Exception {
                    bluetoothGattDescriptor.setValue(data);
                }
            })
            .toCompletable();
}
 
Example #3
Source File: LeFunService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        enableNotification();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
    }
}
 
Example #4
Source File: MiBandService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        changeNextState();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
    }
}
 
Example #5
Source File: RxBleConnectionImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public Single<byte[]> readDescriptor(@NonNull final UUID serviceUuid, @NonNull final UUID characteristicUuid,
                                     @NonNull final UUID descriptorUuid) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, SingleSource<BluetoothGattDescriptor>>() {
                @Override
                public SingleSource<BluetoothGattDescriptor> apply(RxBleDeviceServices rxBleDeviceServices) {
                    return rxBleDeviceServices.getDescriptor(serviceUuid, characteristicUuid, descriptorUuid);
                }
            })
            .flatMap(new Function<BluetoothGattDescriptor, SingleSource<byte[]>>() {
                @Override
                public SingleSource<byte[]> apply(BluetoothGattDescriptor descriptor) {
                    return readDescriptor(descriptor);
                }
            });
}
 
Example #6
Source File: RxBleConnectionImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public Completable writeDescriptor(
        @NonNull final UUID serviceUuid, @NonNull final UUID characteristicUuid, @NonNull final UUID descriptorUuid,
        @NonNull final byte[] data
) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, SingleSource<BluetoothGattDescriptor>>() {
                @Override
                public SingleSource<BluetoothGattDescriptor> apply(RxBleDeviceServices rxBleDeviceServices) {
                    return rxBleDeviceServices.getDescriptor(serviceUuid, characteristicUuid, descriptorUuid);
                }
            })
            .flatMapCompletable(new Function<BluetoothGattDescriptor, CompletableSource>() {
                @Override
                public CompletableSource apply(BluetoothGattDescriptor bluetoothGattDescriptor) {
                    return writeDescriptor(bluetoothGattDescriptor, data);
                }
            });
}
 
Example #7
Source File: RxBleDeviceMock.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
public RxBleDeviceMock(String name,
                       String macAddress,
                       byte[] scanRecord,
                       Integer rssi,
                       RxBleDeviceServices rxBleDeviceServices,
                       Map<UUID, Observable<byte[]>> characteristicNotificationSources,
                       @Nullable BluetoothDevice bluetoothDevice) {
    this.name = name;
    this.macAddress = macAddress;
    this.rxBleConnection = new RxBleConnectionMock(rxBleDeviceServices,
            rssi,
            characteristicNotificationSources);
    this.rssi = rssi;
    this.scanRecord = scanRecord;
    this.advertisedUUIDs = new ArrayList<>();
    this.bluetoothDevice = bluetoothDevice;
}
 
Example #8
Source File: MiBandService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        changeNextState();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
    }
}
 
Example #9
Source File: LeFunService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        enableNotification();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
    }
}
 
Example #10
Source File: InPenService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    super.onServicesDiscovered(services);
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (D) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            if (D)
                UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        loadInfos();
        changeState(mState.next());
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
        tryGattRefresh();
    }
}
 
Example #11
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example #12
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example #13
Source File: JamBaseBluetoothSequencer.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
protected void onServicesDiscovered(RxBleDeviceServices services) {
    UserError.Log.d(TAG, "Services discovered okay in base sequencer");
    final Object obj = new Object();
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            I.characteristics.put(characteristic.getUuid(), obj);
        }
    }
}
 
Example #14
Source File: BlueJayService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    super.onServicesDiscovered(services);
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (D) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            if (D)
                UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    found = true; // test only TODO update to filter
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        changeNextState();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
        tryGattRefresh();
    }
}
 
Example #15
Source File: PendiqService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        //  UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(Const.PENDIQ_SERVICE)) {

            enableNotification();
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate Pendiq service during discovery on " + address + " called: " + name);
}
 
Example #16
Source File: ServiceDiscoveryOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
/**
 * Sometimes it happens that the {@link BluetoothGatt} will receive all {@link BluetoothGattService}'s,
 * {@link android.bluetooth.BluetoothGattCharacteristic}'s and {@link android.bluetooth.BluetoothGattDescriptor}
 * but it won't receive the final callback that the service discovery was completed. This is a potential workaround.
 * <p>
 * There is a change in Android 7.0.0_r1 where all data is received at once - in this situation returned services size will be always 0
 * https://android.googlesource.com/platform/frameworks/base/+/android-7.0.0_r1/core/java/android/bluetooth/BluetoothGatt.java#206
 * https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r72/core/java/android/bluetooth/BluetoothGatt.java#205
 *
 * @param bluetoothGatt     the BluetoothGatt to use
 * @param rxBleGattCallback the RxBleGattCallback to use
 * @param timeoutScheduler  the Scheduler for timeout to use
 * @return Observable that may emit {@link RxBleDeviceServices} or {@link TimeoutException}
 */
@NonNull
@Override
protected Single<RxBleDeviceServices> timeoutFallbackProcedure(
        final BluetoothGatt bluetoothGatt,
        final RxBleGattCallback rxBleGattCallback,
        final Scheduler timeoutScheduler
) {
    return Single.defer(new Callable<SingleSource<? extends RxBleDeviceServices>>() {
        @Override
        public SingleSource<? extends RxBleDeviceServices> call() {
            final List<BluetoothGattService> services = bluetoothGatt.getServices();
            if (services.size() == 0) {
                // if after the timeout services are empty we have no other option to declare a failed discovery
                return Single.error(new BleGattCallbackTimeoutException(bluetoothGatt, BleGattOperationType.SERVICE_DISCOVERY));
            } else {
            /*
            it is observed that usually the Android OS is returning services, characteristics and descriptors in a short period of time
            if there are some services available we will wait for 5 more seconds just to be sure that
            the timeout was not triggered right in the moment of filling the services and then emit a value.
             */
                return Single
                        .timer(5, TimeUnit.SECONDS, timeoutScheduler)
                        .flatMap(new Function<Long, Single<RxBleDeviceServices>>() {
                            @Override
                            public Single<RxBleDeviceServices> apply(Long delayedSeconds) {
                                return Single.fromCallable(new Callable<RxBleDeviceServices>() {
                                    @Override
                                    public RxBleDeviceServices call() {
                                        return new RxBleDeviceServices(bluetoothGatt.getServices());
                                    }
                                });
                            }
                        });
            }
        }
    });
}
 
Example #17
Source File: Ob1G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example #18
Source File: Ob1G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example #19
Source File: JamBaseBluetoothSequencer.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
protected void onServicesDiscovered(RxBleDeviceServices services) {
    UserError.Log.d(TAG, "Services discovered okay in base sequencer");
    final Object obj = new Object();
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            I.characteristics.put(characteristic.getUuid(), obj);
        }
    }
}
 
Example #20
Source File: BlueJayService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    super.onServicesDiscovered(services);
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (D) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            if (D)
                UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    found = true; // test only TODO update to filter
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        changeNextState();
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
        tryGattRefresh();
    }
}
 
Example #21
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        //  UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(Const.PENDIQ_SERVICE)) {

            enableNotification();
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate Pendiq service during discovery on " + address + " called: " + name);
}
 
Example #22
Source File: InPenService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onServicesDiscovered(RxBleDeviceServices services) {
    boolean found = false;
    super.onServicesDiscovered(services);
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (D) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
            if (D)
                UserError.Log.d(TAG, "-- Character: " + getUUIDName(characteristic.getUuid()));

            for (final UUID check : huntCharacterstics) {
                if (characteristic.getUuid().equals(check)) {
                    I.readCharacteristic = check;
                    found = true;
                }
            }
        }
    }
    if (found) {
        I.isDiscoveryComplete = true;
        I.discoverOnce = true;
        loadInfos();
        changeState(mState.next());
    } else {
        UserError.Log.e(TAG, "Could not find characteristic during service discovery. This is very unusual");
        tryGattRefresh();
    }
}
 
Example #23
Source File: ServiceDiscoveryManager.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@NonNull
private Function<TimeoutConfiguration, Single<RxBleDeviceServices>> scheduleActualDiscoveryWithTimeout() {
    return new Function<TimeoutConfiguration, Single<RxBleDeviceServices>>() {
        @Override
        public Single<RxBleDeviceServices> apply(TimeoutConfiguration timeoutConf) {
            final ServiceDiscoveryOperation operation = operationProvider
                    .provideServiceDiscoveryOperation(timeoutConf.timeout, timeoutConf.timeoutTimeUnit);
            return operationQueue.queue(operation)
                    .firstOrError();
        }
    };
}
 
Example #24
Source File: ServiceDiscoveryOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected Single<RxBleDeviceServices> getCallback(RxBleGattCallback rxBleGattCallback) {
    return rxBleGattCallback.getOnServicesDiscovered().firstOrError()
            .doOnSuccess(new Consumer<RxBleDeviceServices>() {
                @Override
                public void accept(RxBleDeviceServices rxBleDeviceServices) {
                    bleServicesLogger.log(rxBleDeviceServices, bluetoothGatt.getDevice());
                }
            });
}
 
Example #25
Source File: RxBleGattCallback.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    LoggerUtil.logCallback("onServicesDiscovered", gatt, 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()));
    }
}
 
Example #26
Source File: RxBleConnectionImpl.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
public Single<BluetoothGattCharacteristic> getCharacteristic(@NonNull final UUID characteristicUuid) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, Single<? extends BluetoothGattCharacteristic>>() {
                @Override
                public Single<? extends BluetoothGattCharacteristic> apply(RxBleDeviceServices rxBleDeviceServices) {
                    return rxBleDeviceServices.getCharacteristic(characteristicUuid);
                }
            });
}
 
Example #27
Source File: ServiceDiscoveryManager.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
Single<RxBleDeviceServices> getDiscoverServicesSingle(final long timeout, final TimeUnit timeoutTimeUnit) {
    if (hasCachedResults) {
        // optimisation to decrease the number of allocations
        return deviceServicesObservable;
    } else {
        return deviceServicesObservable.doOnSubscribe(
                new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) {
                        timeoutBehaviorSubject.onNext(new TimeoutConfiguration(timeout, timeoutTimeUnit, Schedulers.computation()));
                    }
                });
    }
}
 
Example #28
Source File: ServiceDiscoveryManager.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Function<List<BluetoothGattService>, RxBleDeviceServices> wrapIntoRxBleDeviceServices() {
    return new Function<List<BluetoothGattService>, RxBleDeviceServices>() {
        @Override
        public RxBleDeviceServices apply(List<BluetoothGattService> bluetoothGattServices) {
            return new RxBleDeviceServices(bluetoothGattServices);
        }
    };
}
 
Example #29
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public Single<BluetoothGattCharacteristic> getCharacteristic(@NonNull final UUID characteristicUuid) {
    return discoverServices()
            .flatMap(new Function<RxBleDeviceServices, SingleSource<? extends BluetoothGattCharacteristic>>() {
                @Override
                public SingleSource<? extends BluetoothGattCharacteristic> apply(RxBleDeviceServices rxBleDeviceServices)
                        throws Exception {
                    return rxBleDeviceServices.getCharacteristic(characteristicUuid);
                }
            });
}
 
Example #30
Source File: LoggerUtilBluetoothServices.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
private String prepareServicesDescription(RxBleDeviceServices rxBleDeviceServices, BluetoothDevice device) {
    StringBuilder descriptionBuilder = new StringBuilder();
    appendDeviceHeader(device, descriptionBuilder);
    for (BluetoothGattService bluetoothGattService : rxBleDeviceServices.getBluetoothGattServices()) {
        descriptionBuilder.append('\n'); // New line before each service description
        appendServiceDescription(descriptionBuilder, bluetoothGattService);
    }
    descriptionBuilder.append("\n--------------- ====== Finished peripheral content ====== ---------------");
    return descriptionBuilder.toString();
}