Search in sources :

Example 6 with BeaconParser

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);
}
Also used : BeaconParser(org.altbeacon.beacon.BeaconParser) AltBeaconParser(org.altbeacon.beacon.AltBeaconParser) ScanFilterUtils(org.altbeacon.beacon.service.scanner.ScanFilterUtils) Test(org.junit.Test)

Example 7 with BeaconParser

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);
}
Also used : BeaconParser(org.altbeacon.beacon.BeaconParser) AltBeaconParser(org.altbeacon.beacon.AltBeaconParser) AltBeaconParser(org.altbeacon.beacon.AltBeaconParser) ScanFilterUtils(org.altbeacon.beacon.service.scanner.ScanFilterUtils) Test(org.junit.Test)

Example 8 with BeaconParser

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;
    }
}
Also used : BeaconParser(org.altbeacon.beacon.BeaconParser) Beacon(org.altbeacon.beacon.Beacon)

Example 9 with BeaconParser

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'");
    }
}
Also used : DistanceCalculator(org.altbeacon.beacon.distance.DistanceCalculator) ModelSpecificDistanceCalculator(org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator) BluetoothCrashResolver(org.altbeacon.bluetooth.BluetoothCrashResolver) ProcessUtils(org.altbeacon.beacon.utils.ProcessUtils) BeaconParser(org.altbeacon.beacon.BeaconParser) BeaconManager(org.altbeacon.beacon.BeaconManager) Beacon(org.altbeacon.beacon.Beacon) Region(org.altbeacon.beacon.Region) ModelSpecificDistanceCalculator(org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator) MainThread(androidx.annotation.MainThread)

Example 10 with BeaconParser

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);
}
Also used : BeaconParser(org.altbeacon.beacon.BeaconParser) HashSet(java.util.HashSet)

Aggregations

BeaconParser (org.altbeacon.beacon.BeaconParser)12 ScanFilterUtils (org.altbeacon.beacon.service.scanner.ScanFilterUtils)6 AltBeaconParser (org.altbeacon.beacon.AltBeaconParser)5 Test (org.junit.Test)5 ScanFilter (android.bluetooth.le.ScanFilter)3 ArrayList (java.util.ArrayList)3 ParcelUuid (android.os.ParcelUuid)2 Beacon (org.altbeacon.beacon.Beacon)2 BeaconManager (org.altbeacon.beacon.BeaconManager)2 Region (org.altbeacon.beacon.Region)2 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothManager (android.bluetooth.BluetoothManager)1 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)1 ScanSettings (android.bluetooth.le.ScanSettings)1 MainThread (androidx.annotation.MainThread)1 RequiresApi (androidx.annotation.RequiresApi)1 HashSet (java.util.HashSet)1 Identifier (org.altbeacon.beacon.Identifier)1 DistanceCalculator (org.altbeacon.beacon.distance.DistanceCalculator)1 ModelSpecificDistanceCalculator (org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator)1