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());
}
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());
}
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());
}
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));
}
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;
}
}
Aggregations