Search in sources :

Example 21 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 = 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)

Example 22 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)

Example 23 with Beacon

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

the class BeaconSimulatorTest method testSetBeacons.

@Test
public void testSetBeacons() {
    StaticBeaconSimulator staticBeaconSimulator = new StaticBeaconSimulator();
    byte[] beaconBytes = hexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509");
    Beacon beacon = new AltBeaconParser().fromScanData(beaconBytes, -55, null, 123456L);
    ArrayList<Beacon> beacons = new ArrayList<Beacon>();
    beacons.add(beacon);
    staticBeaconSimulator.setBeacons(beacons);
    assertEquals("getBeacons should match values entered with setBeacons", staticBeaconSimulator.getBeacons(), beacons);
}
Also used : StaticBeaconSimulator(org.altbeacon.beacon.simulator.StaticBeaconSimulator) AltBeaconParser(org.altbeacon.beacon.AltBeaconParser) Beacon(org.altbeacon.beacon.Beacon) AltBeacon(org.altbeacon.beacon.AltBeacon) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with Beacon

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

the class RunningAverageRssiFilterTest method legacySetSampleExpirationMillisecondsWorksText.

@Test
public void legacySetSampleExpirationMillisecondsWorksText() {
    RangedBeacon.setSampleExpirationMilliseconds(20000);
    RunningAverageRssiFilter.setSampleExpirationMilliseconds(20000);
    Beacon beacon = new Beacon.Builder().setId1("1").build();
    RangedBeacon.setSampleExpirationMilliseconds(33l);
    RangedBeacon rb = new RangedBeacon(beacon);
    assertEquals("RunningAverageRssiFilter sampleExprirationMilliseconds should not be altered by constructing RangedBeacon", 33l, RunningAverageRssiFilter.getSampleExpirationMilliseconds());
}
Also used : Beacon(org.altbeacon.beacon.Beacon) Test(org.junit.Test)

Aggregations

Beacon (org.altbeacon.beacon.Beacon)24 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)8 Region (org.altbeacon.beacon.Region)4 Bundle (android.os.Bundle)3 Context (android.content.Context)2 AltBeacon (org.altbeacon.beacon.AltBeacon)2 BeaconParser (org.altbeacon.beacon.BeaconParser)2 Identifier (org.altbeacon.beacon.Identifier)2 StaticBeaconSimulator (org.altbeacon.beacon.simulator.StaticBeaconSimulator)2 MainThread (androidx.annotation.MainThread)1 Nullable (androidx.annotation.Nullable)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 AltBeaconParser (org.altbeacon.beacon.AltBeaconParser)1 BeaconManager (org.altbeacon.beacon.BeaconManager)1 DistanceCalculator (org.altbeacon.beacon.distance.DistanceCalculator)1 ModelSpecificDistanceCalculator (org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator)1 ProcessUtils (org.altbeacon.beacon.utils.ProcessUtils)1 BluetoothCrashResolver (org.altbeacon.bluetooth.BluetoothCrashResolver)1