Search in sources :

Example 16 with Beacon

use of org.altbeacon.beacon.Beacon 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 = ShadowApplication.getInstance().getApplicationContext();
    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).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++) {
        Parcel parcel = Parcel.obtain();
        data.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);
        RangingData data2 = new RangingData(parcel);
    }
    long time2 = System.currentTimeMillis();
    System.out.println("*** Ranging Data Serialization benchmark: " + (time2 - time1));
}
Also used : Context(android.content.Context) RangingData(org.altbeacon.beacon.service.RangingData) Identifier(org.altbeacon.beacon.Identifier) Parcel(android.os.Parcel) ArrayList(java.util.ArrayList) Beacon(org.altbeacon.beacon.Beacon) Region(org.altbeacon.beacon.Region) Test(org.junit.Test)

Example 17 with Beacon

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

the class EddystoneTelemetryAccessorTest method testAllowsAccessToBase64EncodedTelemetryBytes.

@Test
public void testAllowsAccessToBase64EncodedTelemetryBytes() throws MalformedURLException {
    ArrayList<Long> telemetryFields = new ArrayList<Long>();
    // version
    telemetryFields.add(0x01l);
    // battery level
    telemetryFields.add(0x0212l);
    // temperature
    telemetryFields.add(0x0313l);
    // pdu count
    telemetryFields.add(0x04142434l);
    // uptime
    telemetryFields.add(0x05152535l);
    Beacon beaconWithTelemetry = new Beacon.Builder().setId1("0x0102030405060708090a").setId2("0x01020304050607").setTxPower(-59).setExtraDataFields(telemetryFields).build();
    byte[] telemetryBytes = new EddystoneTelemetryAccessor().getTelemetryBytes(beaconWithTelemetry);
    String encodedTelemetryBytes = new EddystoneTelemetryAccessor().getBase64EncodedTelemetry(beaconWithTelemetry);
    assertNotNull(telemetryBytes);
}
Also used : ArrayList(java.util.ArrayList) Beacon(org.altbeacon.beacon.Beacon) Test(org.junit.Test)

Aggregations

Beacon (org.altbeacon.beacon.Beacon)17 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)7 Context (android.content.Context)2 Parcel (android.os.Parcel)2 AltBeacon (org.altbeacon.beacon.AltBeacon)2 BeaconParser (org.altbeacon.beacon.BeaconParser)2 Identifier (org.altbeacon.beacon.Identifier)2 Region (org.altbeacon.beacon.Region)2 RangingData (org.altbeacon.beacon.service.RangingData)2 StaticBeaconSimulator (org.altbeacon.beacon.simulator.StaticBeaconSimulator)2 HashMap (java.util.HashMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AltBeaconParser (org.altbeacon.beacon.AltBeaconParser)1 ModelSpecificDistanceCalculator (org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator)1 BluetoothCrashResolver (org.altbeacon.bluetooth.BluetoothCrashResolver)1