Search in sources :

Example 1 with Beacon

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

the class ExtraDataBeaconTrackerTest method multiFrameBeaconDifferentServiceUUIDFieldsNotUpdated.

@Test
public void multiFrameBeaconDifferentServiceUUIDFieldsNotUpdated() {
    Beacon beacon = getMultiFrameBeacon();
    Beacon beaconUpdate = getMultiFrameBeaconUpdateDifferentServiceUUID();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    tracker.track(beacon);
    tracker.track(beaconUpdate);
    Beacon trackedBeacon = tracker.track(beacon);
    assertNotEquals("rssi should NOT be updated", beaconUpdate.getRssi(), trackedBeacon.getRssi());
    assertNotEquals("data fields should NOT be updated", beaconUpdate.getDataFields(), trackedBeacon.getExtraDataFields());
}
Also used : Beacon(org.altbeacon.beacon.Beacon) Test(org.junit.Test)

Example 2 with Beacon

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

the class ExtraDataBeaconTrackerTest method gattBeaconFieldsAreNotUpdated.

@Test
public void gattBeaconFieldsAreNotUpdated() {
    Beacon beacon = getGattBeacon();
    final int originalRssi = beacon.getRssi();
    final List<Long> originalData = beacon.getDataFields();
    final List<Long> originalExtra = beacon.getExtraDataFields();
    Beacon beaconUpdate = getGattBeaconUpdate();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    tracker.track(beacon);
    tracker.track(beaconUpdate);
    Beacon trackedBeacon = tracker.track(beacon);
    assertEquals("rssi should NOT be updated", originalRssi, trackedBeacon.getRssi());
    assertEquals("data should NOT be updated", originalData, trackedBeacon.getDataFields());
    assertEquals("extra data should NOT be updated", originalExtra, trackedBeacon.getExtraDataFields());
}
Also used : Beacon(org.altbeacon.beacon.Beacon) Test(org.junit.Test)

Example 3 with Beacon

use of org.altbeacon.beacon.Beacon 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 4 with Beacon

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

the class EddystoneTelemetryAccessorTest method testAllowsAccessToTelemetryBytes.

@Test
public void testAllowsAccessToTelemetryBytes() 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);
    byte[] expectedBytes = { 0x20, 0x01, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x24, 0x34, 0x05, 0x15, 0x25, 0x35 };
    assertEquals(byteArrayToHexString(telemetryBytes), byteArrayToHexString(expectedBytes));
}
Also used : ArrayList(java.util.ArrayList) Beacon(org.altbeacon.beacon.Beacon) Test(org.junit.Test)

Example 5 with Beacon

use of org.altbeacon.beacon.Beacon 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)

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