mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 06:22:55 +01:00
Pebble: try to get rid of the sleep and rely on countdownlatch instead.
Could help with #494
This commit is contained in:
parent
c1abaaa4e0
commit
1fda1ba1b2
@ -111,6 +111,11 @@ class PebbleGATTServer extends BluetoothGattServerCallback {
|
|||||||
int serial = header >> 3;
|
int serial = header >> 3;
|
||||||
if (command == 0x01) {
|
if (command == 0x01) {
|
||||||
LOG.info("got ACK for serial = " + serial);
|
LOG.info("got ACK for serial = " + serial);
|
||||||
|
if (mPebbleLESupport.mPPAck != null) {
|
||||||
|
mPebbleLESupport.mPPAck.countDown();
|
||||||
|
} else {
|
||||||
|
LOG.warn("mPPAck countdownlatch is not present but it probably should");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (command == 0x02) { // some request?
|
if (command == 0x02) { // some request?
|
||||||
LOG.info("got command 0x02");
|
LOG.info("got command 0x02");
|
||||||
|
@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ public class PebbleLESupport {
|
|||||||
private int mMTU = 20;
|
private int mMTU = 20;
|
||||||
private int mMTULimit = Integer.MAX_VALUE;
|
private int mMTULimit = Integer.MAX_VALUE;
|
||||||
boolean mIsConnected = false;
|
boolean mIsConnected = false;
|
||||||
|
public CountDownLatch mPPAck;
|
||||||
|
|
||||||
public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException {
|
public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException {
|
||||||
mBtDevice = btDevice;
|
mBtDevice = btDevice;
|
||||||
@ -135,6 +137,7 @@ public class PebbleLESupport {
|
|||||||
|
|
||||||
int payloadToSend = bytesRead + 4;
|
int payloadToSend = bytesRead + 4;
|
||||||
int srcPos = 0;
|
int srcPos = 0;
|
||||||
|
mPPAck = new CountDownLatch(1);
|
||||||
while (payloadToSend > 0) {
|
while (payloadToSend > 0) {
|
||||||
int chunkSize = (payloadToSend < (mMTU - 4)) ? payloadToSend : mMTU - 4;
|
int chunkSize = (payloadToSend < (mMTU - 4)) ? payloadToSend : mMTU - 4;
|
||||||
byte[] outBuf = new byte[chunkSize + 1];
|
byte[] outBuf = new byte[chunkSize + 1];
|
||||||
@ -145,7 +148,9 @@ public class PebbleLESupport {
|
|||||||
payloadToSend -= chunkSize;
|
payloadToSend -= chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(500); // FIXME ugly wait 0.5s after each pebble package send to the pebble (we do not wait for the GATT chunks)
|
mPPAck.await();
|
||||||
|
mPPAck = null;
|
||||||
|
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
LOG.info(e.getMessage());
|
LOG.info(e.getMessage());
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
Loading…
Reference in New Issue
Block a user