use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class ScanFilterUtilsTest method testGenericScanFilter.
@Test
public void testGenericScanFilter() throws Exception {
org.robolectric.shadows.ShadowLog.stream = System.err;
BeaconParser parser = new BeaconParser();
parser.setBeaconLayout("m:2-3=1111,i:4-6,p:24-24");
// 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", 0x004c, 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) 0x11, (byte) 0x11 }, sfd.filter);
assertNull("serviceUuid should be null", sfd.serviceUuid);
}
use of org.altbeacon.beacon.BeaconParser in project android-beacon-library by AltBeacon.
the class ScanFilterUtils method createScanFiltersForBeaconParsers.
public List<ScanFilter> createScanFiltersForBeaconParsers(List<BeaconParser> beaconParsers, List<Region> regions) {
ArrayList<Region> nonNullRegions = new ArrayList<>();
if (regions == null) {
nonNullRegions.add(null);
} else {
nonNullRegions.addAll(regions);
}
List<ScanFilter> scanFilters = new ArrayList<ScanFilter>();
for (Region region : nonNullRegions) {
for (BeaconParser beaconParser : beaconParsers) {
List<ScanFilterData> sfds = createScanFilterDataForBeaconParser(beaconParser, region == null ? null : region.getIdentifiers());
for (ScanFilterData sfd : sfds) {
ScanFilter.Builder builder = new ScanFilter.Builder();
if (sfd.serviceUuid != null) {
// Use a 16 bit service UUID in a 128 bit form
String serviceUuidString = String.format("0000%04X-0000-1000-8000-00805f9b34fb", sfd.serviceUuid);
String serviceUuidMaskString = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
ParcelUuid parcelUuid = ParcelUuid.fromString(serviceUuidString);
ParcelUuid parcelUuidMask = ParcelUuid.fromString(serviceUuidMaskString);
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "making scan filter for service: " + serviceUuidString + " " + parcelUuid);
LogManager.d(TAG, "making scan filter with service mask: " + serviceUuidMaskString + " " + parcelUuidMask);
}
builder.setServiceUuid(parcelUuid, parcelUuidMask);
} else if (sfd.serviceUuid128Bit.length != 0) {
String serviceUuidString = Identifier.fromBytes(sfd.serviceUuid128Bit, 0, 16, true).toString();
String serviceUuidMaskString = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
ParcelUuid parcelUuid = ParcelUuid.fromString(serviceUuidString);
ParcelUuid parcelUuidMask = ParcelUuid.fromString(serviceUuidMaskString);
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "making scan filter for service: " + serviceUuidString + " " + parcelUuid);
LogManager.d(TAG, "making scan filter with service mask: " + serviceUuidMaskString + " " + parcelUuidMask);
}
builder.setServiceUuid(parcelUuid, parcelUuidMask);
} else {
builder.setServiceUuid(null);
builder.setManufacturerData((int) sfd.manufacturer, sfd.filter, sfd.mask);
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "making scan filter for manufacturer: " + sfd.manufacturer + " " + sfd.filter);
}
}
ScanFilter scanFilter = builder.build();
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "Set up a scan filter: " + scanFilter);
}
scanFilters.add(scanFilter);
}
}
}
return scanFilters;
}
Aggregations