Started correcting the iBeacon data display
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
android:id="@+id/tvDetails"
|
android:id="@+id/tvDetails"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="12sp"
|
||||||
android:typeface="monospace" />
|
android:typeface="monospace" />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class DetailsActivity extends Activity{
|
|||||||
append(sb, device.getScanRecord());
|
append(sb, device.getScanRecord());
|
||||||
|
|
||||||
append(sb, "", null);
|
append(sb, "", null);
|
||||||
append(sb, "Ad Records", null);
|
append(sb, "Raw Ad Records As String", null);
|
||||||
append(sb, "-----------------", null);
|
append(sb, "-----------------", null);
|
||||||
|
|
||||||
|
|
||||||
@@ -71,12 +71,12 @@ public class DetailsActivity extends Activity{
|
|||||||
|
|
||||||
if(isIBeacon){
|
if(isIBeacon){
|
||||||
final ManufacturerDataIBeacon iBeaconData = new ManufacturerDataIBeacon(device);
|
final ManufacturerDataIBeacon iBeaconData = new ManufacturerDataIBeacon(device);
|
||||||
append(sb, "Company ID", iBeaconData.getCompanyIdentifier());
|
append(sb, "Company ID", iBeaconData.getCompanyIdentifier() + " (" + Integer.toHexString( iBeaconData.getCompanyIdentifier() ) + ")");
|
||||||
append(sb, "iBeacon Advertisment", iBeaconData.getIBeaconAdvertisement());
|
append(sb, "iBeacon Advertisment", iBeaconData.getIBeaconAdvertisement() + " (" + Integer.toHexString( iBeaconData.getIBeaconAdvertisement() ) + ")");
|
||||||
append(sb, "UUID", iBeaconData.getUUID());
|
append(sb, "UUID", iBeaconData.getUUID().toString());
|
||||||
append(sb, "Major", iBeaconData.getMajor());
|
append(sb, "Major", iBeaconData.getMajor() + " (" + Integer.toHexString( iBeaconData.getMajor() ) + ")");
|
||||||
append(sb, "Minor", iBeaconData.getMinor());
|
append(sb, "Minor", iBeaconData.getMinor() + " (" + Integer.toHexString( iBeaconData.getMinor() ) + ")");
|
||||||
append(sb, "TX Power", iBeaconData.getCalibratedTxPower());
|
append(sb, "TX Power", iBeaconData.getCalibratedTxPower() + " (" + Integer.toHexString( iBeaconData.getCalibratedTxPower() ) + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,37 @@
|
|||||||
package uk.co.alt236.btlescan.containers;
|
package uk.co.alt236.btlescan.containers;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import uk.co.alt236.btlescan.util.ByteUtils;
|
import uk.co.alt236.btlescan.util.ByteUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public final class ManufacturerDataIBeacon {
|
public final class ManufacturerDataIBeacon {
|
||||||
// 0 4C # Byte 1 (LSB) of Company identifier code
|
// 0 4C # Byte 1 (LSB) of Company identifier code
|
||||||
// 1 00 # Byte 0 (MSB) of Company identifier code (0x004C == Apple)
|
// 1 00 # Byte 0 (MSB) of Company identifier code (0x004C == Apple)
|
||||||
// 2 02 # Byte 0 of iBeacon advertisement indicator
|
// 2 02 # Byte 0 of iBeacon advertisement indicator
|
||||||
// 3 15 # Byte 1 of iBeacon advertisement indicator
|
// 3 15 # Byte 1 of iBeacon advertisement indicator
|
||||||
// 4 e2 |\
|
// 4 e2 |\
|
||||||
// 5 c5 |\\
|
// 5 c5 |\\
|
||||||
// 6 6d |#\\
|
// 6 6d |#\\
|
||||||
// 7 b5 |##\\
|
// 7 b5 |##\\
|
||||||
// 8 df |###\\
|
// 8 df |###\\
|
||||||
// 9 fb |####\\
|
// 9 fb |####\\
|
||||||
// 10 48 |#####\\
|
// 10 48 |#####\\
|
||||||
// 11 d2 |#####|| iBeacon proximity UUID
|
// 11 d2 |#####|| iBeacon proximity UUID
|
||||||
// 12 b0 |#####||
|
// 12 b0 |#####||
|
||||||
// 13 60 |#####//
|
// 13 60 |#####//
|
||||||
// 14 d0 |####//
|
// 14 d0 |####//
|
||||||
// 15 f5 |###//
|
// 15 f5 |###//
|
||||||
// 16 a7 |##//
|
// 16 a7 |##//
|
||||||
// 17 10 |#//
|
// 17 10 |#//
|
||||||
// 18 96 |//
|
// 18 96 |//
|
||||||
// 19 e0 |/
|
// 19 e0 |/
|
||||||
// 20 00 # major
|
// 20 00 # major
|
||||||
// 21 00
|
// 21 00
|
||||||
// 22 00# minor
|
// 22 00 # minor
|
||||||
// 23 00
|
// 23 00
|
||||||
// 24 c5 # The 2's complement of the calibrated Tx Power
|
// 24 c5 # The 2's complement of the calibrated Tx Power
|
||||||
|
|
||||||
private final byte[] mData;
|
private final byte[] mData;
|
||||||
private final int mCalibratedTxPower;
|
private final int mCalibratedTxPower;
|
||||||
@@ -38,7 +39,7 @@ public final class ManufacturerDataIBeacon {
|
|||||||
private final int mIBeaconAdvertisment;
|
private final int mIBeaconAdvertisment;
|
||||||
private final int mMajor;
|
private final int mMajor;
|
||||||
private final int mMinor;
|
private final int mMinor;
|
||||||
private final long mUUID;
|
private final UUID mUUID;
|
||||||
|
|
||||||
public ManufacturerDataIBeacon(BluetoothLeDevice device){
|
public ManufacturerDataIBeacon(BluetoothLeDevice device){
|
||||||
this(device.getAdRecordStore().getRecord(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getData());
|
this(device.getAdRecordStore().getRecord(AdRecord.TYPE_MANUFACTURER_SPECIFIC_DATA).getData());
|
||||||
@@ -48,9 +49,12 @@ public final class ManufacturerDataIBeacon {
|
|||||||
mData = data;
|
mData = data;
|
||||||
Log.d("TAG", "~ Reading iBeacon Data: " + ByteUtils.byteArrayToHexString(data));
|
Log.d("TAG", "~ Reading iBeacon Data: " + ByteUtils.byteArrayToHexString(data));
|
||||||
|
|
||||||
mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 0, 2));
|
mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray(
|
||||||
|
ByteUtils.invertArray(
|
||||||
|
Arrays.copyOfRange(mData, 0, 2)));
|
||||||
|
|
||||||
mIBeaconAdvertisment = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 2, 4));
|
mIBeaconAdvertisment = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 2, 4));
|
||||||
mUUID = ByteUtils.getLongFromByteArray(Arrays.copyOfRange(mData, 4, 19));
|
mUUID = UUID.nameUUIDFromBytes(Arrays.copyOfRange(mData, 4, 20));
|
||||||
mMajor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 20, 22));
|
mMajor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 20, 22));
|
||||||
mMinor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 22, 24));
|
mMinor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 22, 24));
|
||||||
mCalibratedTxPower = ByteUtils.getIntFromByte(data[24]);
|
mCalibratedTxPower = ByteUtils.getIntFromByte(data[24]);
|
||||||
@@ -76,7 +80,7 @@ public final class ManufacturerDataIBeacon {
|
|||||||
return mMinor;
|
return mMinor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUUID(){
|
public UUID getUUID(){
|
||||||
return mUUID;
|
return mUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,20 @@ public class ByteUtils {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] invertArray(byte[] array){
|
||||||
|
final int size = array.length;
|
||||||
|
byte temp;
|
||||||
|
|
||||||
|
for (int i = 0; i < size/2; i++)
|
||||||
|
{
|
||||||
|
temp = array[i];
|
||||||
|
array[i] = array[size-1 - i];
|
||||||
|
array[size-1 - i] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getIntFrom2ByteArray(byte[] input){
|
public static int getIntFrom2ByteArray(byte[] input){
|
||||||
final byte[] result = new byte[4];
|
final byte[] result = new byte[4];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user