Search in sources :

Example 1 with Identifier

use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.

the class RangingDataTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Context context = RuntimeEnvironment.application;
    ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
    identifiers.add(Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"));
    identifiers.add(Identifier.parse("1"));
    identifiers.add(Identifier.parse("2"));
    Region region = new Region("testRegion", identifiers);
    ArrayList<Beacon> beacons = new ArrayList<Beacon>();
    Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build();
    beacon.setRssiMeasurementCount(1);
    beacon.setPacketCount(2);
    for (int i = 0; i < 10; i++) {
        beacons.add(beacon);
    }
    RangingData data = new RangingData(beacons, region);
    Bundle bundle = data.toBundle();
    RangingData data2 = RangingData.fromBundle(bundle);
    assertEquals("beacon count shouild be restored", 10, data2.getBeacons().size());
    assertEquals("region identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", data2.getRegion().getId1().toString());
    Beacon restoredBeacon = data2.getBeacons().iterator().next();
    assertEquals("beacon identifier 1 shouild be restored", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", restoredBeacon.getId1().toString());
    assertEquals("RSSI is restored", -1, restoredBeacon.getRssi());
    assertEquals("Average RSSI is restored", -2.0, restoredBeacon.getRunningAverageRssi(), 0.0);
    assertEquals("TXPower is restored", -50, restoredBeacon.getTxPower());
    assertEquals("Measurement count is restored", 1, restoredBeacon.getMeasurementCount());
    assertEquals("Packet count is restored", 2, restoredBeacon.getPacketCount());
}
Also used : Context(android.content.Context) Identifier(org.altbeacon.beacon.Identifier) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Beacon(org.altbeacon.beacon.Beacon) Region(org.altbeacon.beacon.Region) Test(org.junit.Test)

Example 2 with Identifier

use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.

the class ScanFilterUtilsTest method testScanFilterWithIdentifiers.

@Test
public void testScanFilterWithIdentifiers() throws Exception {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    BeaconParser parser = new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
    parser.setHardwareAssistManufacturerCodes(new int[] { 0x004c });
    // no manifest available in robolectric
    BeaconManager.setManifestCheckingDisabled(true);
    ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
    identifiers.add(Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"));
    identifiers.add(Identifier.parse("0x0102"));
    identifiers.add(Identifier.parse("0x0304"));
    List<ScanFilterUtils.ScanFilterData> scanFilterDatas = new ScanFilterUtils().createScanFilterDataForBeaconParser(parser, identifiers);
    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", 22, sfd.mask.length);
    assertArrayEquals("mask should be right", new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }, sfd.mask);
    assertArrayEquals("filter should be right", new byte[] { (byte) 0x02, (byte) 0x15, (byte) 0x2F, (byte) 0x23, (byte) 0x44, (byte) 0x54, (byte) 0xCF, (byte) 0x6D, (byte) 0x4A, (byte) 0x0F, (byte) 0xAD, (byte) 0xF2, (byte) 0xF4, (byte) 0x91, (byte) 0x1B, (byte) 0xA9, (byte) 0xFF, (byte) 0xA6, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 }, sfd.filter);
}
Also used : BeaconParser(org.altbeacon.beacon.BeaconParser) AltBeaconParser(org.altbeacon.beacon.AltBeaconParser) Identifier(org.altbeacon.beacon.Identifier) ArrayList(java.util.ArrayList) ScanFilterUtils(org.altbeacon.beacon.service.scanner.ScanFilterUtils) Test(org.junit.Test)

Example 3 with Identifier

use of org.altbeacon.beacon.Identifier in project android-beacon-library by AltBeacon.

the class RangingDataTest method testSerializationBenchmark.

@Test
public // On MacBookPro 2.5 GHz Core I7, 10000 serialization/deserialiation cycles of RangingData took 22ms
void testSerializationBenchmark() throws Exception {
    Context context = RuntimeEnvironment.application;
    ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
    identifiers.add(Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"));
    identifiers.add(Identifier.parse("1"));
    identifiers.add(Identifier.parse("2"));
    Region region = new Region("testRegion", identifiers);
    ArrayList<Beacon> beacons = new ArrayList<Beacon>();
    Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build();
    for (int i = 0; i < 10; i++) {
        beacons.add(beacon);
    }
    RangingData data = new RangingData(beacons, region);
    long time1 = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
        Bundle bundle = data.toBundle();
        RangingData data2 = RangingData.fromBundle(bundle);
    }
    long time2 = System.currentTimeMillis();
    System.out.println("*** Ranging Data Serialization benchmark: " + (time2 - time1));
}
Also used : Context(android.content.Context) Identifier(org.altbeacon.beacon.Identifier) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Beacon(org.altbeacon.beacon.Beacon) Region(org.altbeacon.beacon.Region) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 Identifier (org.altbeacon.beacon.Identifier)3 Test (org.junit.Test)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 Beacon (org.altbeacon.beacon.Beacon)2 Region (org.altbeacon.beacon.Region)2 AltBeaconParser (org.altbeacon.beacon.AltBeaconParser)1 BeaconParser (org.altbeacon.beacon.BeaconParser)1 ScanFilterUtils (org.altbeacon.beacon.service.scanner.ScanFilterUtils)1