Skip to content
Permalink
Browse files

Merge pull request #2 from jotomo/experimental

Fix race condition
  • Loading branch information...
jotomo committed Jan 31, 2018
2 parents b41216f + fc5ea6a commit c8049d531e61e708211eeffab4aa307d04e42e80
@@ -56,5 +56,6 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:design:25.+'
compile 'org.apache.commons:commons-lang3:3.7'
testCompile 'junit:junit:4.12'
}
@@ -47,7 +47,6 @@ private static void sendData(ByteBuffer payload, boolean reliable,BTConnection b
List<Byte> packet = Packet.buildPacket(sendR, payload, true,btConn); //Add the payload, set the address if valid

if(reliable) {
int seq = btConn.seqNo;
packet.set(1, setSeqRel(packet.get(1), true,btConn)); //Set the sequence and reliable bits
}
Packet.adjustLength(packet, payload.capacity()); //Set the payload length
@@ -161,11 +160,12 @@ public static void sendAppCommand(Command command, BTConnection btConn){
break;

case CMD_PING:
payload = ByteBuffer.allocate(4);
payload.put((byte)16);
payload.put((byte)0xB7);
payload.put((byte) (0x9AAA & 0xFF));
payload.put((byte) ((0x9AAA>>8) & 0xFF));
reliable = false;
reliable = true;
break;

default:
@@ -8,7 +8,10 @@
import android.content.SharedPreferences;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.monkey.d.ruffy.ruffy.driver.display.DisplayParser;
import org.monkey.d.ruffy.ruffy.driver.display.DisplayParserHandler;
import org.monkey.d.ruffy.ruffy.driver.display.Menu;
@@ -36,7 +39,7 @@
private BTConnection btConn;
private PumpData pumpData;

private boolean rtModeRunning = false;
private volatile boolean rtModeRunning = false;
private long lastRtMessageSent = 0;

private final Object rtSequenceSemaphore = new Object();
@@ -214,7 +217,8 @@ public void requestBlueTooth() {
private void stopRT()
{
rtModeRunning = false;
rtSequence =0;
SystemClock.sleep(500 + 250);
rtSequence = 0;
}

private void startRT() {
@@ -287,9 +291,9 @@ public void noMenuFound() {
}
} catch (Exception e) {
if (rtModeRunning) {
fail("Error sending keep alive while rtModeRunning is still true");
fail("Error sending keep alive while rtModeRunning is still true: " + ExceptionUtils.getStackTrace(e));
} else {
fail("Error sending keep alive. rtModeRunning is false, so this is most likely a race condition during disconnect");
fail("Error sending keep alive. rtModeRunning is false, so this is most likely a race condition during disconnect: " + ExceptionUtils.getStackTrace(e));
}
}
try{

0 comments on commit c8049d5

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.