Can now parse IBeacon Manufacturer data (need to flip the byte order of
a few fields)
This commit is contained in:
@@ -3,6 +3,7 @@ package uk.co.alt236.btlescan.containers;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import uk.co.alt236.btlescan.util.ByteUtils;
|
import uk.co.alt236.btlescan.util.ByteUtils;
|
||||||
|
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
|
||||||
@@ -45,19 +46,14 @@ public final class ManufacturerDataIBeacon {
|
|||||||
|
|
||||||
public ManufacturerDataIBeacon(byte[] data){
|
public ManufacturerDataIBeacon(byte[] data){
|
||||||
mData = data;
|
mData = data;
|
||||||
mCompanyIdentidier = convert2ByteArrayToInt(Arrays.copyOfRange(mData, 0, 2));
|
Log.d("TAG", "~ Reading iBeacon Data: " + ByteUtils.byteArrayToHexString(data));
|
||||||
mIBeaconAdvertisment = convert2ByteArrayToInt(Arrays.copyOfRange(mData, 2, 2));
|
|
||||||
mUUID = ByteUtils.getLongFromByteArray(Arrays.copyOfRange(mData, 4, 16));
|
|
||||||
mMajor = convert2ByteArrayToInt(Arrays.copyOfRange(mData, 20, 2));
|
|
||||||
mMinor = convert2ByteArrayToInt(Arrays.copyOfRange(mData, 22, 2));
|
|
||||||
mCalibratedTxPower = ByteUtils.getIntFromByte(data[24]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int convert2ByteArrayToInt(byte[] array){
|
mCompanyIdentidier = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 0, 2));
|
||||||
final byte[] result = new byte[4];
|
mIBeaconAdvertisment = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 2, 4));
|
||||||
result[2] = array[0];
|
mUUID = ByteUtils.getLongFromByteArray(Arrays.copyOfRange(mData, 4, 19));
|
||||||
result[3] = array[1];
|
mMajor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 20, 22));
|
||||||
return ByteUtils.getIntFromByteArray(result);
|
mMinor = ByteUtils.getIntFrom2ByteArray(Arrays.copyOfRange(mData, 22, 24));
|
||||||
|
mCalibratedTxPower = ByteUtils.getIntFromByte(data[24]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCalibratedTxPower(){
|
public int getCalibratedTxPower(){
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ public class ByteUtils {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getIntFrom2ByteArray(byte[] input){
|
||||||
|
final byte[] result = new byte[4];
|
||||||
|
|
||||||
|
result[0] = 0;
|
||||||
|
result[1] = 0;
|
||||||
|
result[2] = input[0];
|
||||||
|
result[3] = input[1];
|
||||||
|
|
||||||
|
return ByteUtils.getIntFromByteArray(result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a byte to an int, preserving the sign.
|
* Converts a byte to an int, preserving the sign.
|
||||||
*
|
*
|
||||||
@@ -53,6 +64,7 @@ public class ByteUtils {
|
|||||||
return ByteBuffer.wrap(bytes).getInt();
|
return ByteBuffer.wrap(bytes).getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a byte array to a long;
|
* Converts a byte array to a long;
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user