use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class ScanFilterUtilsTest method testEddystoneScanFilterData.
@Test
public void testEddystoneScanFilterData() throws Exception {
org.robolectric.shadows.ShadowLog.stream = System.err;
BeaconParser parser = new BeaconParser();
parser.setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT);
// no manifest available in robolectric
BeaconManager.setManifestCheckingDisabled(true);
List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser, null);
assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
assertEquals("serviceUuid should be right", new Long(0xfeaa), sfd.serviceUuid);
}
use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class ScanFilterUtilsTest method testGetAltBeaconScanFilter.
@Test
public void testGetAltBeaconScanFilter() throws Exception {
org.robolectric.shadows.ShadowLog.stream = System.err;
BeaconParser parser = new AltBeaconParser();
// no manifest available in robolectric
BeaconManager.setManifestCheckingDisabled(true);
List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser, null);
assertEquals("scanFilters should be of correct size", 1, scanFilterDatas.size());
ScanFilterUtils.ScanFilterData sfd = scanFilterDatas.get(0);
assertEquals("manufacturer should be right", 0x0118, sfd.manufacturer);
assertEquals("mask length should be right", 2, sfd.mask.length);
assertArrayEquals("mask should be right", new byte[] { (byte) 0xff, (byte) 0xff }, sfd.mask);
assertArrayEquals("filter should be right", new byte[] { (byte) 0xbe, (byte) 0xac }, sfd.filter);
}
use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class EddystoneTelemetryAccessor method getTelemetryBytes.
/**
* Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon.
* This is useful for passing the telemetry to Google's backend services.
* @param beacon
* @return the bytes of the telemetry frame
*/
public byte[] getTelemetryBytes(Beacon beacon) {
if (beacon.getExtraDataFields().size() >= 5) {
Beacon telemetryBeacon = new Beacon.Builder().setDataFields(beacon.getExtraDataFields()).build();
BeaconParser telemetryParser = new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT);
byte[] telemetryBytes = telemetryParser.getBeaconAdvertisementData(telemetryBeacon);
Log.d(TAG, "Rehydrated telemetry bytes are :" + byteArrayToString(telemetryBytes));
return telemetryBytes;
} else {
return null;
}
}
use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class BeaconService method onCreate.
@MainThread
@Override
public void onCreate() {
this.startForegroundIfConfigured();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
bluetoothCrashResolver = new BluetoothCrashResolver(this);
bluetoothCrashResolver.start();
}
mScanHelper = new ScanHelper(this);
if (mScanHelper.getCycledScanner() == null) {
mScanHelper.createCycledLeScanner(false, bluetoothCrashResolver);
}
mScanHelper.setMonitoringStatus(MonitoringStatus.getInstanceForApplication(this));
mScanHelper.setRangedRegionState(new HashMap<Region, RangeState>());
mScanHelper.setBeaconParsers(new HashSet<BeaconParser>());
mScanHelper.setExtraDataBeaconTracker(new ExtraDataBeaconTracker());
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
beaconManager.setScannerInSameProcess(true);
if (beaconManager.isMainProcess()) {
LogManager.i(TAG, "beaconService version %s is starting up on the main process", BuildConfig.VERSION_NAME);
// if we are on the main process, we use local broadcast notifications to deliver results.
ensureNotificationProcessorSetup();
} else {
LogManager.i(TAG, "beaconService version %s is starting up on a separate process", BuildConfig.VERSION_NAME);
ProcessUtils processUtils = new ProcessUtils(this);
LogManager.i(TAG, "beaconService PID is " + processUtils.getPid() + " with process name " + processUtils.getProcessName());
}
String longScanForcingEnabled = getManifestMetadataValue("longScanForcingEnabled");
if (longScanForcingEnabled != null && longScanForcingEnabled.equals("true")) {
LogManager.i(TAG, "longScanForcingEnabled to keep scans going on Android N for > 30 minutes");
if (mScanHelper.getCycledScanner() != null) {
mScanHelper.getCycledScanner().setLongScanForcingEnabled(true);
}
}
mScanHelper.reloadParsers();
DistanceCalculator defaultDistanceCalculator = new ModelSpecificDistanceCalculator(this, BeaconManager.getDistanceModelUpdateUrl());
Beacon.setDistanceCalculator(defaultDistanceCalculator);
// Look for simulated scan data
try {
Class klass = Class.forName("org.altbeacon.beacon.SimulatedScanData");
java.lang.reflect.Field f = klass.getField("beacons");
mScanHelper.setSimulatedScanData((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.BeaconParser in project android-beacon-library by AltBeacon.
the class ScanHelper method reloadParsers.
void reloadParsers() {
HashSet<BeaconParser> newBeaconParsers = new HashSet<>();
// flatMap all beacon parsers
boolean matchBeaconsByServiceUUID = true;
newBeaconParsers.addAll(mBeaconManager.getBeaconParsers());
for (BeaconParser beaconParser : mBeaconManager.getBeaconParsers()) {
if (beaconParser.getExtraDataParsers().size() > 0) {
matchBeaconsByServiceUUID = false;
newBeaconParsers.addAll(beaconParser.getExtraDataParsers());
}
}
mBeaconParsers = newBeaconParsers;
// initialize the extra data beacon tracker
mExtraDataBeaconTracker = new ExtraDataBeaconTracker(matchBeaconsByServiceUUID);
}
Aggregations