@Override protected Void doInBackground(ScanData... params) { ScanData scanData = params[0]; IBeacon iBeacon = IBeacon.fromScanData(scanData.scanRecord, scanData.rssi); if (iBeacon != null) { lastIBeaconDetectionTime = new Date(); trackedBeacons.add(iBeacon); Log.d( TAG, "iBeacon detected :" + iBeacon.getProximityUuid() + " " + iBeacon.getMajor() + " " + iBeacon.getMinor() + " accuracy: " + iBeacon.getAccuracy() + " proximity: " + iBeacon.getProximity()); List<Region> matchedRegions = matchingRegions(iBeacon, monitoredRegionState.keySet()); Iterator<Region> matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); MonitorState state = monitoredRegionState.get(region); if (state.markInside()) { state .getCallback() .call( IBeaconService.this, "monitoringData", new MonitoringData(state.isInside(), region)); } } Log.d(TAG, "looking for ranging region matches for this ibeacon"); matchedRegions = matchingRegions(iBeacon, rangedRegionState.keySet()); matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); Log.d(TAG, "matches ranging region: " + region); RangeState rangeState = rangedRegionState.get(region); rangeState.addIBeacon(iBeacon); } } // I see a device: 00:02:72:C5:EC:33 with scan data: 02 01 1A 1A FF 4C 00 02 15 84 2A F9 C4 08 // F5 11 E3 92 82 F2 3C 91 AE C0 5E D0 00 00 69 C5 // 0000000000000000000000000000000000000000000000000000000000000000 // // 9: proximityUuid (16 bytes) 84 2A F9 C4 08 F5 11 E3 92 82 F2 3C 91 AE C0 5E // 25: major (2 bytes unsigned int) // 27: minor (2 bytes unsigned int) // 29: tx power (1 byte signed int) return null; }
private void processExpiredMonitors() { Iterator<Region> monitoredRegionIterator = monitoredRegionState.keySet().iterator(); while (monitoredRegionIterator.hasNext()) { Region region = monitoredRegionIterator.next(); MonitorState state = monitoredRegionState.get(region); if (state.isNewlyOutside()) { Log.d(TAG, "found a monitor that expired: " + region); state .getCallback() .call( IBeaconService.this, "monitoringData", new MonitoringData(state.isInside(), region)); } } }
private void processIBeaconFromScan(IBeacon iBeacon) { lastIBeaconDetectionTime = new Date(); trackedBeacons.add(iBeacon); Log.d( TAG, "iBeacon detected :" + iBeacon.getProximityUuid() + " " + iBeacon.getMajor() + " " + iBeacon.getMinor() + " accuracy: " + iBeacon.getAccuracy() + " proximity: " + iBeacon.getProximity()); List<Region> matchedRegions = matchingRegions(iBeacon, monitoredRegionState.keySet()); Iterator<Region> matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); MonitorState state = monitoredRegionState.get(region); if (state.markInside()) { state .getCallback() .call( IBeaconService.this, "monitoringData", new MonitoringData(state.isInside(), region)); } } Log.d(TAG, "looking for ranging region matches for this ibeacon"); matchedRegions = matchingRegions(iBeacon, rangedRegionState.keySet()); matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); Log.d(TAG, "matches ranging region: " + region); RangeState rangeState = rangedRegionState.get(region); rangeState.addIBeacon(iBeacon); } }
private void processIBeaconFromScan(IBeacon iBeacon) { lastIBeaconDetectionTime = new Date(); trackedBeaconsPacketCount++; if (trackedBeacons.contains(iBeacon)) { if (IBeaconManager.LOG_DEBUG) Log.d( TAG, "iBeacon detected multiple times in scan cycle :" + iBeacon.getProximityUuid() + " " + iBeacon.getMajor() + " " + iBeacon.getMinor() + " accuracy: " + iBeacon.getAccuracy() + " proximity: " + iBeacon.getProximity()); } trackedBeacons.add(iBeacon); if (IBeaconManager.LOG_DEBUG) Log.d( TAG, "iBeacon detected :" + iBeacon.getProximityUuid() + " " + iBeacon.getMajor() + " " + iBeacon.getMinor() + " accuracy: " + iBeacon.getAccuracy() + " proximity: " + iBeacon.getProximity()); List<Region> matchedRegions = null; synchronized (monitoredRegionState) { matchedRegions = matchingRegions(iBeacon, monitoredRegionState.keySet()); } Iterator<Region> matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); MonitorState state = monitoredRegionState.get(region); if (state.markInside()) { state .getCallback() .call( IBeaconService.this, "monitoringData", new MonitoringData(state.isInside(), region)); } } if (IBeaconManager.LOG_DEBUG) Log.d(TAG, "looking for ranging region matches for this ibeacon"); synchronized (rangedRegionState) { matchedRegions = matchingRegions(iBeacon, rangedRegionState.keySet()); } matchedRegionIterator = matchedRegions.iterator(); while (matchedRegionIterator.hasNext()) { Region region = matchedRegionIterator.next(); if (IBeaconManager.LOG_DEBUG) Log.d(TAG, "matches ranging region: " + region); RangeState rangeState = rangedRegionState.get(region); rangeState.addIBeacon(iBeacon); } }