Skip to content

Commit

Permalink
fix(ble): fix ios->android long write
Browse files Browse the repository at this point in the history
When android connect to an iOS device it set the mtu and the callback onMTUchanged is called on the android side, with an iphone 6S+ for example it'll set the mtu to 185, even through on the iOS part we will still retrieve 512 when we call maximumWriteValueLengthForType cause iOS automaticly chunck the data to fit in the correct MTU for the android device, in order to iOS to know what was read we need to send back the value when we send the gatt response, on the android side we can either send the chunk to yamux since it'll buffer it as long as it hasn't received the whole frame or buffer it and send it when the onExecuteWrite is called with the execute parameter set to true, i've choose the 1st option in order to not taking more time on this issue

Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Nov 15, 2018
1 parent 7cde4ff commit 6cbd363
Showing 1 changed file with 13 additions and 1 deletion.
Expand Up @@ -290,6 +290,14 @@ public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, i
}
}

@Override
public void onExecuteWrite (BluetoothDevice device,
int requestId,
boolean execute) {
Log.e(TAG, "EXECUTE WRITE " + requestId + " EXECUTE " + execute);
super.onExecuteWrite(device, requestId, execute);
}

@Override
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
UUID charID = characteristic.getUuid();
Expand All @@ -304,8 +312,12 @@ public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
} catch (Exception e) {
Log.e(TAG, "FAIL AWAIT " + e.getMessage());
}
Log.e(TAG, "rep needed" + responseNeeded+ "prepared " + preparedWrite + " transid " + requestId + " offset " + offset + " len: " + value.length);
Core.bytesToConn(bDevice.ma, value);
mBluetoothGattServer.sendResponse(device, requestId, GATT_SUCCESS, offset, null);
if (responseNeeded) {
mBluetoothGattServer.sendResponse(device, requestId, GATT_SUCCESS, offset, value);
}

} else if (charID.equals(CLOSER_UUID)) {
// TODO
} else if (charID.equals(IS_READY_UUID)) {
Expand Down

0 comments on commit 6cbd363

Please sign in to comment.