Java Code Examples for com.polidea.rxandroidble2.internal.RxBleLog#d()

The following examples show how to use com.polidea.rxandroidble2.internal.RxBleLog#d() . 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: LegacyScanOperation.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
BluetoothAdapter.LeScanCallback createScanCallback(final ObservableEmitter<RxBleInternalScanResultLegacy> emitter) {
    return new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
            if (filterUuids != null && RxBleLog.isAtLeast(LogConstants.DEBUG)) {
                RxBleLog.d("%s, name=%s, rssi=%d, data=%s",
                        LoggerUtil.commonMacMessage(device.getAddress()),
                        device.getName(),
                        rssi,
                        LoggerUtil.bytesToHex(scanRecord)
                );
            }
            if (filterUuids == null || uuidUtil.extractUUIDs(scanRecord).containsAll(filterUuids)) {
                emitter.onNext(new RxBleInternalScanResultLegacy(device, rssi, scanRecord));
            }
        }
    };
}
 
Example 2
Source File: ScanOperationApi18.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
BluetoothAdapter.LeScanCallback createScanCallback(final ObservableEmitter<RxBleInternalScanResult> emitter) {
    return new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
            if (!scanFilterMatcher.isEmpty() && RxBleLog.isAtLeast(LogConstants.DEBUG) && RxBleLog.getShouldLogScannedPeripherals()) {
                RxBleLog.d("%s, name=%s, rssi=%d, data=%s",
                        LoggerUtil.commonMacMessage(device.getAddress()),
                        device.getName(),
                        rssi,
                        LoggerUtil.bytesToHex(scanRecord)
                );
            }
            final RxBleInternalScanResult internalScanResult = scanResultCreator.create(device, rssi, scanRecord);
            if (scanFilterMatcher.matches(internalScanResult)) {
                emitter.onNext(internalScanResult);
            }
        }
    };
}
 
Example 3
Source File: ConnectionOperationQueueImpl.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void terminate(BleException disconnectException) {
    if (this.disconnectionException != null) {
        // already terminated
        return;
    }
    RxBleLog.d(disconnectException, "Connection operations queue to be terminated (%s)", commonMacMessage(deviceMacAddress));
    shouldRun = false;
    disconnectionException = disconnectException;
    runnableFuture.cancel(true);
}
 
Example 4
Source File: ScanSetupBuilderImplApi23.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
@Override
public ScanSetup build(ScanSettings scanSettings, ScanFilter... scanFilters) {
    boolean areFiltersSpecified = areFiltersSpecified(scanFilters);
    boolean isFilteringCallbackType = scanSettings.getCallbackType() != ScanSettings.CALLBACK_TYPE_ALL_MATCHES;

    ObservableTransformer<RxBleInternalScanResult, RxBleInternalScanResult> resultTransformer = ObservableUtil.identityTransformer();
    ScanSettings resultScanSettings = scanSettings;

    // native matching (when a device is first seen or no longer seen) does not work with no filters specified —
    // see https://issuetracker.google.com/issues/37127640
    // so we will use a callback type that will work and emulate the desired behaviour
    boolean shouldEmulateCallbackType = isFilteringCallbackType && !areFiltersSpecified;
    if (shouldEmulateCallbackType) {
        RxBleLog.d("ScanSettings.callbackType != CALLBACK_TYPE_ALL_MATCHES but no (or only empty) filters are specified. "
            + "Falling back to callbackType emulation.");
        resultTransformer = scanSettingsEmulator.emulateCallbackType(scanSettings.getCallbackType());
        resultScanSettings = scanSettings.copyWithCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
    }

    return new ScanSetup(
            new ScanOperationApi21(
                    rxBleAdapterWrapper,
                    internalScanResultCreator,
                    androidScanObjectsConverter,
                    resultScanSettings,
                    new EmulatedScanFilterMatcher(),
                    scanFilters),
            resultTransformer
    );
}
 
Example 5
Source File: LegacyScanOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
boolean startScan(RxBleAdapterWrapper rxBleAdapterWrapper, BluetoothAdapter.LeScanCallback scanCallback) {
    if (this.filterUuids == null) {
        RxBleLog.d("No library side filtering —> debug logs of scanned devices disabled");
    }
    return rxBleAdapterWrapper.startLegacyLeScan(scanCallback);
}
 
Example 6
Source File: ScanOperationApi18.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
boolean startScan(RxBleAdapterWrapper rxBleAdapterWrapper, BluetoothAdapter.LeScanCallback scanCallback) {
    if (this.scanFilterMatcher.isEmpty()) {
        RxBleLog.d("No library side filtering —> debug logs of scanned devices disabled");
    }
    return rxBleAdapterWrapper.startLegacyLeScan(scanCallback);
}
 
Example 7
Source File: ScanOperationApi21.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
boolean startScan(RxBleAdapterWrapper rxBleAdapterWrapper, ScanCallback scanCallback) {
    if (this.emulatedScanFilterMatcher.isEmpty()) {
        RxBleLog.d("No library side filtering —> debug logs of scanned devices disabled");
    }
    rxBleAdapterWrapper.startLeScan(
            androidScanObjectsConverter.toNativeFilters(scanFilters),
            androidScanObjectsConverter.toNativeSettings(scanSettings),
            scanCallback
    );
    return true;
}
 
Example 8
Source File: CharacteristicLongWriteOperation.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
void writeData(byte[] bytesBatch, IntSupplier batchIndexGetter) {
    if (RxBleLog.isAtLeast(LogConstants.DEBUG)) {
        RxBleLog.d("Writing batch #%04d: %s", batchIndexGetter.get(), LoggerUtil.bytesToHex(bytesBatch));
    }
    bluetoothGattCharacteristic.setValue(bytesBatch);
    final boolean success = bluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic);
    if (!success) {
        throw new BleGattCannotStartException(bluetoothGatt, BleGattOperationType.CHARACTERISTIC_LONG_WRITE);
    }
}
 
Example 9
Source File: LoggerUtil.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
public static void logOperationStarted(Operation operation) {
    if (RxBleLog.isAtLeast(LogConstants.DEBUG)) {
        RxBleLog.d("STARTED  %s(%d)", operation.getClass().getSimpleName(), System.identityHashCode(operation));
    }
}
 
Example 10
Source File: LoggerUtil.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
public static void logOperationRemoved(Operation operation) {
    if (RxBleLog.isAtLeast(LogConstants.DEBUG)) {
        RxBleLog.d("REMOVED  %s(%d)", operation.getClass().getSimpleName(), System.identityHashCode(operation));
    }
}
 
Example 11
Source File: LoggerUtil.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
public static void logOperationQueued(Operation operation) {
    if (RxBleLog.isAtLeast(LogConstants.DEBUG)) {
        RxBleLog.d("QUEUED   %s(%d)", operation.getClass().getSimpleName(), System.identityHashCode(operation));
    }
}
 
Example 12
Source File: LoggerUtil.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
public static void logOperationFinished(Operation operation, long startTime, long endTime) {
    if (RxBleLog.isAtLeast(LogConstants.DEBUG)) {
        RxBleLog.d("FINISHED %s(%d) in %d ms", operation.getClass().getSimpleName(),
                System.identityHashCode(operation), (endTime - startTime));
    }
}