use of org.altbeacon.beacon.Beacon in project android-beacon-library by AltBeacon.
the class BeaconService method onCreate.
@Override
public void onCreate() {
LogManager.i(TAG, "beaconService version %s is starting up", BuildConfig.VERSION_NAME);
bluetoothCrashResolver = new BluetoothCrashResolver(this);
bluetoothCrashResolver.start();
// Create a private executor so we don't compete with threads used by AsyncTask
// This uses fewer threads than the default executor so it won't hog CPU
mExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
mCycledScanner = CycledLeScanner.createScanner(this, BeaconManager.DEFAULT_FOREGROUND_SCAN_PERIOD, BeaconManager.DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD, mBackgroundFlag, mCycledLeScanCallback, bluetoothCrashResolver);
beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
//flatMap all beacon parsers
boolean matchBeaconsByServiceUUID = true;
if (beaconManager.getBeaconParsers() != null) {
beaconParsers.addAll(beaconManager.getBeaconParsers());
for (BeaconParser beaconParser : beaconManager.getBeaconParsers()) {
if (beaconParser.getExtraDataParsers().size() > 0) {
matchBeaconsByServiceUUID = false;
beaconParsers.addAll(beaconParser.getExtraDataParsers());
}
}
}
//initialize the extra data beacon tracker
mExtraDataBeaconTracker = new ExtraDataBeaconTracker(matchBeaconsByServiceUUID);
defaultDistanceCalculator = new ModelSpecificDistanceCalculator(this, BeaconManager.getDistanceModelUpdateUrl());
Beacon.setDistanceCalculator(defaultDistanceCalculator);
monitoringStatus = MonitoringStatus.getInstanceForApplication(getApplicationContext());
// Look for simulated scan data
try {
Class klass = Class.forName("org.altbeacon.beacon.SimulatedScanData");
java.lang.reflect.Field f = klass.getField("beacons");
this.simulatedScanData = (List<Beacon>) f.get(null);
} catch (ClassNotFoundException e) {
LogManager.d(TAG, "No org.altbeacon.beacon.SimulatedScanData class exists.");
} catch (Exception e) {
LogManager.e(e, TAG, "Cannot get simulated Scan data. Make sure your org.altbeacon.beacon.SimulatedScanData class defines a field with the signature 'public static List<Beacon> beacons'");
}
}
use of org.altbeacon.beacon.Beacon in project android-beacon-library by AltBeacon.
the class ExtraDataBeaconTracker method trackGattBeacon.
// The following code is for dealing with merging data fields in beacons
private Beacon trackGattBeacon(Beacon beacon) {
Beacon trackedBeacon = null;
HashMap<Integer, Beacon> matchingTrackedBeacons = mBeaconsByKey.get(getBeaconKey(beacon));
if (matchingTrackedBeacons != null) {
for (Beacon matchingTrackedBeacon : matchingTrackedBeacons.values()) {
if (beacon.isExtraBeaconData()) {
matchingTrackedBeacon.setRssi(beacon.getRssi());
matchingTrackedBeacon.setExtraDataFields(beacon.getDataFields());
} else {
beacon.setExtraDataFields(matchingTrackedBeacon.getExtraDataFields());
// replace the tracked beacon instance with this one so it has updated values
trackedBeacon = beacon;
}
}
}
if (!beacon.isExtraBeaconData()) {
updateTrackingHashes(beacon, matchingTrackedBeacons);
}
if (trackedBeacon == null && !beacon.isExtraBeaconData()) {
trackedBeacon = beacon;
}
return trackedBeacon;
}
use of org.altbeacon.beacon.Beacon in project android-beacon-library by AltBeacon.
the class RangeState method finalizeBeacons.
// returns a list of beacons that are tracked, and then removes any from the list that should not
// be there for the next cycle
public synchronized Collection<Beacon> finalizeBeacons() {
Map<Beacon, RangedBeacon> newRangedBeacons = new HashMap<Beacon, RangedBeacon>();
ArrayList<Beacon> finalizedBeacons = new ArrayList<Beacon>();
synchronized (mRangedBeacons) {
for (Beacon beacon : mRangedBeacons.keySet()) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
if (rangedBeacon.isTracked()) {
// calculates accuracy
rangedBeacon.commitMeasurements();
if (!rangedBeacon.noMeasurementsAvailable()) {
finalizedBeacons.add(rangedBeacon.getBeacon());
}
}
// tracked anymore so we don't pass it on as visible unless it is seen again
if (!rangedBeacon.noMeasurementsAvailable() == true) {
//measurements for a certain amount of time
if (!UseTrackingCache || rangedBeacon.isExpired())
rangedBeacon.setTracked(false);
newRangedBeacons.put(beacon, rangedBeacon);
} else {
LogManager.d(TAG, "Dumping beacon from RangeState because it has no recent measurements.");
}
}
mRangedBeacons = newRangedBeacons;
}
return finalizedBeacons;
}
use of org.altbeacon.beacon.Beacon in project android-beacon-library by AltBeacon.
the class BeaconSimulatorTest method testSetBeacons.
@Test
public void testSetBeacons() {
StaticBeaconSimulator staticBeaconSimulator = new StaticBeaconSimulator();
byte[] beaconBytes = hexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509");
Beacon beacon = new AltBeaconParser().fromScanData(beaconBytes, -55, null);
ArrayList<Beacon> beacons = new ArrayList<Beacon>();
beacons.add(beacon);
staticBeaconSimulator.setBeacons(beacons);
assertEquals("getBeacons should match values entered with setBeacons", staticBeaconSimulator.getBeacons(), beacons);
}
use of org.altbeacon.beacon.Beacon in project android-beacon-library by AltBeacon.
the class ExtraDataBeaconTrackerTest method gattBeaconExtraDataIsNotReturned.
@Test
public void gattBeaconExtraDataIsNotReturned() {
Beacon extraDataBeacon = getGattBeaconExtraData();
ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
Beacon trackedBeacon = tracker.track(extraDataBeacon);
assertNull("trackedBeacon should be null", trackedBeacon);
}
Aggregations