use of com.polidea.rxandroidble2.scan.ScanResult in project xDrip by NightscoutFoundation.
the class ScanMeister method onScanResult.
// Successful result from our bluetooth scan
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);
}
}
}
use of com.polidea.rxandroidble2.scan.ScanResult in project xDrip-plus by jamorham.
the class BackgroundScanReceiver method onReceive.
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
android.util.Log.d("BackgroundScanReceiver", "GOT SCAN INTENT!! " + action);
if (action != null && action.equals(ACTION_NAME)) {
String caller = intent.getStringExtra(CALLING_CLASS);
if (caller == null)
caller = this.getClass().getSimpleName();
// TODO by class name?
final BackgroundScanner backgroundScanner = RxBleProvider.getSingleton().getBackgroundScanner();
try {
final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
final String matchedMac = scanResults.get(0).getBleDevice().getMacAddress();
final String matchedName = scanResults.get(0).getBleDevice().getName();
final boolean calledBack = processCallbacks(caller, matchedMac, matchedName, SCAN_FOUND_CALLBACK);
UserError.Log.d(caller, "Scan results received: " + matchedMac + " " + scanResults);
if (!calledBack) {
try {
// bit of an ugly fix to system wide persistent nature of background scans and lack of proper support for one hit over various android devices
backgroundScanner.stopBackgroundBleScan(// must match original
PendingIntent.getBroadcast(// must match original
xdrip.getAppContext(), // must match original
142, intent, PendingIntent.FLAG_UPDATE_CURRENT));
} catch (Exception e) {
//
}
}
} catch (NullPointerException | BleScanException exception) {
UserError.Log.e(caller, "Failed to scan devices" + exception);
}
}
// ignore invalid actions
}
use of com.polidea.rxandroidble2.scan.ScanResult in project xDrip-plus by jamorham.
the class ScanMeister method onScanResult.
// Successful result from our bluetooth scan
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);
}
}
}
use of com.polidea.rxandroidble2.scan.ScanResult in project xDrip by NightscoutFoundation.
the class BackgroundScanReceiver method onReceive.
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
android.util.Log.d("BackgroundScanReceiver", "GOT SCAN INTENT!! " + action);
if (action != null && action.equals(ACTION_NAME)) {
String caller = intent.getStringExtra(CALLING_CLASS);
if (caller == null)
caller = this.getClass().getSimpleName();
// TODO by class name?
final BackgroundScanner backgroundScanner = RxBleProvider.getSingleton().getBackgroundScanner();
try {
final List<ScanResult> scanResults = backgroundScanner.onScanResultReceived(intent);
final String matchedMac = scanResults.get(0).getBleDevice().getMacAddress();
final String matchedName = scanResults.get(0).getBleDevice().getName();
final boolean calledBack = processCallbacks(caller, matchedMac, matchedName, SCAN_FOUND_CALLBACK);
UserError.Log.d(caller, "Scan results received: " + matchedMac + " " + scanResults);
if (!calledBack) {
try {
// bit of an ugly fix to system wide persistent nature of background scans and lack of proper support for one hit over various android devices
backgroundScanner.stopBackgroundBleScan(// must match original
PendingIntent.getBroadcast(// must match original
xdrip.getAppContext(), // must match original
142, intent, PendingIntent.FLAG_UPDATE_CURRENT));
} catch (Exception e) {
//
}
}
} catch (NullPointerException | BleScanException exception) {
UserError.Log.e(caller, "Failed to scan devices" + exception);
}
}
// ignore invalid actions
}
Aggregations