MartinZaubitzer
04/01/2020, 11:59 AMgsala
04/01/2020, 12:45 PMMartinZaubitzer
04/01/2020, 12:46 PMgsala
04/01/2020, 12:47 PMMartinZaubitzer
04/01/2020, 12:51 PMMartinZaubitzer
04/01/2020, 1:05 PMsuspend fun sendMessageWithResponse(msg : ByteArray): ByteArray? {
sendBleMsg(msg, DeviceUUID.toString())
return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
receiveUpdate()
}
}
private suspend fun receiveUpdate(): ByteArray? =
suspendCoroutine { cont ->
object : BluetoothGattServerCallback {
override fun onCharacteristicWriteRequest(
device: BluetoothDevice?,
requestId: Int,
characteristic: BluetoothGattCharacteristic?,
preparedWrite: Boolean,
responseNeeded: Boolean,
offset: Int,
value: ByteArray?
) {
if (characteristic != null) {
when (characteristic.uuid) {
BycomProfile.buildUUIDfromBase(Profile.DATA_IN_CHAR) -> {
cont.resume(value)
}
}
}
}
}
}
gsala
04/01/2020, 2:53 PMMartinZaubitzer
04/01/2020, 2:55 PM