Java Code Examples for com.polidea.rxandroidble2.scan.ScanResult#getRssi()

The following examples show how to use com.polidea.rxandroidble2.scan.ScanResult#getRssi() . 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: PendiqService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanResult(ScanResult bleScanResult) {
    final int rssi = bleScanResult.getRssi();
    if (rssi > MINIMUM_RSSI) {
        final String this_name = bleScanResult.getBleDevice().getName();
        final boolean matches = isPendiqName(this_name);

        // TODO build list of candidates for processing and start inevitable task to poll them
        // TODO use AutoConnect if only one?
        UserError.Log.d(TAG, "Found a device with name: " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
        if (matches) {
            stopScan();
            address = bleScanResult.getBleDevice().getMacAddress();
            name = this_name;
            UserError.Log.d(TAG, "Set address to: " + address);
            if (auto_connect) {
                changeState(CONNECT);
            } else {
                changeState(CONNECT_NOW);
            }
        }
    } else {
        if (JoH.quietratelimit("log-low-rssi", 2)) {
            UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress());
        }
    }
}
 
Example 2
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanResult(ScanResult bleScanResult) {
    final int rssi = bleScanResult.getRssi();
    if (rssi > MINIMUM_RSSI) {
        final String this_name = bleScanResult.getBleDevice().getName();
        final boolean matches = isPendiqName(this_name);

        // TODO build list of candidates for processing and start inevitable task to poll them
        // TODO use AutoConnect if only one?
        UserError.Log.d(TAG, "Found a device with name: " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
        if (matches) {
            stopScan();
            address = bleScanResult.getBleDevice().getMacAddress();
            name = this_name;
            UserError.Log.d(TAG, "Set address to: " + address);
            if (auto_connect) {
                changeState(CONNECT);
            } else {
                changeState(CONNECT_NOW);
            }
        }
    } else {
        if (JoH.quietratelimit("log-low-rssi", 2)) {
            UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress());
        }
    }
}
 
Example 3
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example 4
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example 5
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }
 
Example 6
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
protected synchronized void onScanResult(ScanResult bleScanResult) {

        if (!wideSearch && address == null && name == null) {
            UserError.Log.d(TAG, "Address has been set to null, stopping scan.");
            stopScan("Address nulled");
            return;
        }

        try {
            for (ParcelUuid p : bleScanResult.getScanRecord().getServiceUuids()) {
                UserError.Log.d(TAG,"SERVICE: "+p.getUuid());
            }

        } catch (Exception e) {
            //
        }
        final int rssi = bleScanResult.getRssi();
        if (rssi > MINIMUM_RSSI) {
            //final String this_name = bleScanResult.getBleDevice().getName();
            final String this_address = bleScanResult.getBleDevice().getMacAddress();
            String this_name = "";
            if (name != null || customFilter != null) {
                this_name = bleScanResult.getBleDevice().getName();
            }
            final boolean matches = (customFilter != null)
                    || ((address != null && address.equalsIgnoreCase(this_address))
                    || (name != null && this_name != null && name.contains(this_name)));
            if (matches || JoH.quietratelimit("scanmeister-show-result", 2)) {
                UserError.Log.d(TAG, "Found a device: " + this_address + " " + this_name + " rssi: " + rssi + "  " + (matches ? "-> MATCH" : ""));
            }
            if (matches && stopOnFirstMatch) {
                stopScan("Got match");
                JoH.threadSleep(500);
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
                releaseWakeLock();
            }
            if (matches && !stopOnFirstMatch) {
                // TODO deposit good information in bundle - TODO: dry
                processCallBacks(this_address, SCAN_FOUND_CALLBACK, this_name, null);
            }

        } else {
            if (JoH.quietratelimit("log-low-rssi", 2)) {
                UserError.Log.d(TAG, "Low rssi device: " + bleScanResult.getBleDevice().getMacAddress() + " rssi: " + rssi);
            }
        }
    }