diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index 88e10da1..b608d4e9 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -43,14 +43,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private static final int HEARTBEAT_URGENT_MS = 6_000; private static final int BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000; private static final int BATTERY_INPUT_QUIET_MS = 5_000; - private static final int WINDOW_SIZE = 5; private static final int IMAGE_FRAGMENT_SIZE = 3800; - private static final int IMAGE_RETRY_DELAY_MS = 10_000; + private static final int IMAGE_RETRY_DELAY_MS = 2_000; private static final boolean IMAGE_FRAGMENT_NO_ACK = false; private static final int MAX_CONSECUTIVE_ACK_TIMEOUTS = 8; private static final int EVEN_APP_WRITE_FAILURE_WINDOW_MS = 15_000; private static final int IDLE_SLEEP_MS = 100; - private static final int RECONNECT_DELAY_MS = 5_000; + private static final int RECONNECT_DELAY_MS = 2_000; private static final BleProtocol.ImageTileOptions[] DASHBOARD_TILES = new BleProtocol.ImageTileOptions[] { new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 288, 144), @@ -546,6 +545,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH); bleManager.requestMtu(address, DESIRED_MTU, CONNECT_TIMEOUT_MS); + if (!bleManager.discoverServices(address, SERVICES_TIMEOUT_MS)) { throw new IllegalStateException("discoverServices failed: " + address); } @@ -631,7 +631,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { return IDLE_SLEEP_MS; } - if (sessionReady && inFlightMessages.size() < WINDOW_SIZE && !pendingMessages.isEmpty()) { + if (sessionReady && inFlightMessages.size() < connectionOptions.WINDOW_SIZE && !pendingMessages.isEmpty()) { OutboundMessage pending = pendingMessages.peekFirst(); messageToWrite = pendingMessages.removeFirst(); Log.i(TAG, "sending pending message: " + messageToWrite.label); diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java index fbf3a510..69e54a61 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java @@ -222,20 +222,21 @@ public class FaceclawBleManager { if (frames == null || frames.isEmpty()) { return true; } - Log.i(TAG, "Called writeFrames with writeType=" + writeType + ", " + frames.size() + " frames totaling " + frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum() + " bytes"); + long startMs = System.currentTimeMillis(); synchronized (gattLock(address)) { BluetoothGatt gatt = requireGatt(address); BluetoothGattCharacteristic characteristic = requireCharacteristic(gatt, characteristicUuid); for (int i = 0; i < frames.size(); i++) { - Log.i(TAG, "writeFrames starting frame " + i); byte[] frame = frames.get(i); if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) { return false; } } } + int totalSize = frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum(); + Log.i(TAG, "writeFrames wrote " + frames.size() + " frames totaling " + totalSize + " bytes in " + (System.currentTimeMillis() - startMs) + "ms"); return true; } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/ConnectionOptions.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/ConnectionOptions.java index 85e103c8..5fa67a55 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/ConnectionOptions.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/ConnectionOptions.java @@ -1,6 +1,7 @@ package com.faceclaw.app; public class ConnectionOptions { - final boolean sendImagesToLeft = true; - final boolean skipSessionIds = true; + final boolean sendImagesToLeft = false; + final boolean skipSessionIds = false; + final int WINDOW_SIZE = 5; }