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 Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionImpl.java    License: 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 #2
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionImpl.java    License: 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 #3
Source Project: RxAndroidBle   Author: Polidea   File: RxBleDeviceMock.java    License: 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 #4
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionMock.java    License: 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 #5
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionMock.java    License: 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 #6
Source Project: xDrip   Author: NightscoutFoundation   File: MiBandService.java    License: 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 #7
Source Project: xDrip   Author: NightscoutFoundation   File: LeFunService.java    License: 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 #8
Source Project: xDrip-plus   Author: jamorham   File: MiBandService.java    License: 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 Project: xDrip-plus   Author: jamorham   File: LeFunService.java    License: 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 Project: RxAndroidBle   Author: Polidea   File: ServiceDiscoveryOperation.java    License: 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 #11
Source Project: RxAndroidBle   Author: Polidea   File: ServiceDiscoveryOperation.java    License: 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 #12
Source Project: RxAndroidBle   Author: Polidea   File: RxBleGattCallback.java    License: 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 #13
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionImpl.java    License: 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 #14
Source Project: RxAndroidBle   Author: Polidea   File: ServiceDiscoveryManager.java    License: 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 #15
Source Project: RxAndroidBle   Author: Polidea   File: ServiceDiscoveryManager.java    License: 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 #16
Source Project: RxAndroidBle   Author: Polidea   File: ServiceDiscoveryManager.java    License: 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 #17
Source Project: RxAndroidBle   Author: Polidea   File: LoggerUtilBluetoothServices.java    License: 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();
}
 
Example #18
Source Project: RxAndroidBle   Author: Polidea   File: DiscoveryResultsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
void swapScanResult(RxBleDeviceServices services) {
    data.clear();

    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        // Add service
        data.add(new AdapterItem(AdapterItem.SERVICE, getServiceType(service), service.getUuid()));
        final List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();

        for (BluetoothGattCharacteristic characteristic : characteristics) {
            data.add(new AdapterItem(AdapterItem.CHARACTERISTIC, describeProperties(characteristic), characteristic.getUuid()));
        }
    }

    notifyDataSetChanged();
}
 
Example #19
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionMock.java    License: Apache License 2.0 5 votes vote down vote up
public RxBleConnectionMock(RxBleDeviceServices rxBleDeviceServices,
                           int rssi,
                           Map<UUID, Observable<byte[]>> characteristicNotificationSources) {
    this.rxBleDeviceServices = rxBleDeviceServices;
    this.rssi = rssi;
    this.characteristicNotificationSources = characteristicNotificationSources;
}
 
Example #20
Source Project: RxAndroidBle   Author: Polidea   File: RxBleConnectionMock.java    License: 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 #21
Source Project: xDrip   Author: NightscoutFoundation   File: Ob1G5CollectionService.java    License: 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 #22
Source Project: xDrip   Author: NightscoutFoundation   File: Ob1G5CollectionService.java    License: 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 #23
Source Project: xDrip   Author: NightscoutFoundation   File: JamBaseBluetoothSequencer.java    License: 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 #24
Source Project: xDrip   Author: NightscoutFoundation   File: BlueJayService.java    License: 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 #25
Source Project: xDrip   Author: NightscoutFoundation   File: PendiqService.java    License: 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 #26
Source Project: xDrip   Author: NightscoutFoundation   File: InPenService.java    License: 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 #27
Source Project: xDrip-plus   Author: jamorham   File: Ob1G5CollectionService.java    License: 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 #28
Source Project: xDrip-plus   Author: jamorham   File: Ob1G5CollectionService.java    License: 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 #29
Source Project: xDrip-plus   Author: jamorham   File: JamBaseBluetoothSequencer.java    License: 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 #30
Source Project: xDrip-plus   Author: jamorham   File: BlueJayService.java    License: 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();
    }
}