Skip to content

Commit

Permalink
feat: shorted BLE advertisements to max 31 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
matejglejtek committed Sep 4, 2023
1 parent 2288dd1 commit 8da4ea2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ class BluetoothScanner(
if (result.getPrimaryPhy() == BluetoothDevice.PHY_LE_CODED)
source = Pigeon.MessageSource.BLUETOOTH_LONG_RANGE;
}

// if using BLE, max size of data is MAX_BLE_ADV_SIZE
// if using BT5, data can be longer up to 256 bytes
val isBLE = maxAdvDataLen() <= MAX_BLE_ADV_SIZE
receiveData(
offsetData(bytes, BT_OFFSET),
if(isBLE) getDataFromIndex(bytes, BT_OFFSET, MAX_BLE_ADV_SIZE) else offsetData(bytes, BT_OFFSET),
result.device.address,
source,
result.rssi.toLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class ODIDScanner(
companion object {
const val MAX_MESSAGE_SIZE = 25
const val BT_OFFSET = 6
const val MAX_BLE_ADV_SIZE = 31
const val WIFI_BEACON_OFFSET = 5
const val WIFI_NAN_OFFSET = 1
}
Expand Down Expand Up @@ -62,4 +63,7 @@ abstract class ODIDScanner(

/// returns ByteArray without first offset elements
inline fun offsetData(data: ByteArray, offset: Int) : ByteArray = data.copyOfRange(offset, data.size)

/// returns ByteArray with bytes from start to end
inline fun getDataFromIndex(data: ByteArray, start: Int, end: Int) : ByteArray = data.copyOfRange(start, end)
}

0 comments on commit 8da4ea2

Please sign in to comment.