diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java index b6a54f4ec1..a333faecea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java @@ -9,10 +9,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; @@ -29,9 +25,6 @@ public class SerialIOThread extends Thread { private OutputStream mOutputStream = null; private BluetoothSocket mRfCommSocket; - private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); - private static ScheduledFuture scheduledDisconnection = null; - private boolean mKeepRunning = true; private byte[] mReadBuff = new byte[0]; @@ -64,7 +57,8 @@ public class SerialIOThread extends Thread { // process all messages we already got while (mReadBuff.length > 3) { // 3rd byte is packet size. continue only if we an determine packet size byte[] extractedBuff = cutMessageFromBuffer(); - if (extractedBuff == null) break; // message is not complete in buffer (wrong packet calls disconnection) + if (extractedBuff == null) + break; // message is not complete in buffer (wrong packet calls disconnection) int command = (extractedBuff[5] & 0xFF) | ((extractedBuff[4] << 8) & 0xFF00); @@ -85,7 +79,6 @@ public class SerialIOThread extends Thread { synchronized (message) { message.notify(); } - scheduleDisconnection(); } } } catch (Exception e) { @@ -177,23 +170,6 @@ public class SerialIOThread extends Thread { log.debug("Old firmware detected"); } } - scheduleDisconnection(); - } - - public void scheduleDisconnection() { - class DisconnectRunnable implements Runnable { - public void run() { - disconnect("scheduleDisconnection"); - scheduledDisconnection = null; - } - } - // prepare task for execution in 10 sec - // cancel waiting task to prevent sending multiple disconnections - if (scheduledDisconnection != null) - scheduledDisconnection.cancel(false); - Runnable task = new DisconnectRunnable(); - final int sec = 10; - scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS); } public void disconnect(String reason) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java index 566b32831f..8672afdcb0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java @@ -9,10 +9,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -30,9 +26,6 @@ public class SerialIOThread extends Thread { private OutputStream mOutputStream = null; private BluetoothSocket mRfCommSocket; - private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); - private static ScheduledFuture scheduledDisconnection = null; - private boolean mKeepRunning = true; private byte[] mReadBuff = new byte[0]; @@ -65,7 +58,8 @@ public class SerialIOThread extends Thread { // process all messages we already got while (mReadBuff.length > 3) { // 3rd byte is packet size. continue only if we an determine packet size byte[] extractedBuff = cutMessageFromBuffer(); - if (extractedBuff == null) break; // message is not complete in buffer (wrong packet calls disconnection) + if (extractedBuff == null) + break; // message is not complete in buffer (wrong packet calls disconnection) int command = (extractedBuff[5] & 0xFF) | ((extractedBuff[4] << 8) & 0xFF00); @@ -86,7 +80,6 @@ public class SerialIOThread extends Thread { synchronized (message) { message.notify(); } - scheduleDisconnection(); } } } catch (Exception e) { @@ -178,23 +171,6 @@ public class SerialIOThread extends Thread { log.debug("Old firmware detected"); } } - scheduleDisconnection(); - } - - public void scheduleDisconnection() { - class DisconnectRunnable implements Runnable { - public void run() { - disconnect("scheduleDisconnection"); - scheduledDisconnection = null; - } - } - // prepare task for execution in 5 sec - // cancel waiting task to prevent sending multiple disconnections - if (scheduledDisconnection != null) - scheduledDisconnection.cancel(false); - Runnable task = new DisconnectRunnable(); - final int sec = 5; - scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS); } public void disconnect(String reason) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java index da9e44f925..343a176e56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java @@ -9,10 +9,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -30,9 +26,6 @@ public class SerialIOThread extends Thread { private OutputStream mOutputStream = null; private BluetoothSocket mRfCommSocket; - private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); - private static ScheduledFuture scheduledDisconnection = null; - private boolean mKeepRunning = true; private byte[] mReadBuff = new byte[0]; @@ -65,7 +58,8 @@ public class SerialIOThread extends Thread { // process all messages we already got while (mReadBuff.length > 3) { // 3rd byte is packet size. continue only if we an determine packet size byte[] extractedBuff = cutMessageFromBuffer(); - if (extractedBuff == null) break; // message is not complete in buffer (wrong packet calls disconnection) + if (extractedBuff == null) + break; // message is not complete in buffer (wrong packet calls disconnection) int command = (extractedBuff[5] & 0xFF) | ((extractedBuff[4] << 8) & 0xFF00); @@ -86,7 +80,6 @@ public class SerialIOThread extends Thread { synchronized (message) { message.notify(); } - scheduleDisconnection(); } } } catch (Exception e) { @@ -178,23 +171,6 @@ public class SerialIOThread extends Thread { log.debug("Old firmware detected"); } } - scheduleDisconnection(); - } - - public void scheduleDisconnection() { - class DisconnectRunnable implements Runnable { - public void run() { - disconnect("scheduleDisconnection"); - scheduledDisconnection = null; - } - } - // prepare task for execution in 10 sec - // cancel waiting task to prevent sending multiple disconnections - if (scheduledDisconnection != null) - scheduledDisconnection.cancel(false); - Runnable task = new DisconnectRunnable(); - final int sec = 10; - scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS); } public void disconnect(String reason) {