Fix connection handshake for DanaR pumps
This commit is contained in:
parent
cd90bab877
commit
32d9a8b4d6
17 changed files with 121 additions and 13 deletions
|
@ -10,9 +10,10 @@ import info.nightscout.androidaps.R;
|
||||||
public class EventPumpStatusChanged extends Event {
|
public class EventPumpStatusChanged extends Event {
|
||||||
public static final int CONNECTING = 0;
|
public static final int CONNECTING = 0;
|
||||||
public static final int CONNECTED = 1;
|
public static final int CONNECTED = 1;
|
||||||
public static final int PERFORMING = 2;
|
public static final int HANDSHAKING = 2;
|
||||||
public static final int DISCONNECTING = 3;
|
public static final int PERFORMING = 3;
|
||||||
public static final int DISCONNECTED = 4;
|
public static final int DISCONNECTING = 4;
|
||||||
|
public static final int DISCONNECTED = 5;
|
||||||
|
|
||||||
public int sStatus = DISCONNECTED;
|
public int sStatus = DISCONNECTED;
|
||||||
public int sSecondsElapsed = 0;
|
public int sSecondsElapsed = 0;
|
||||||
|
@ -47,6 +48,8 @@ public class EventPumpStatusChanged extends Event {
|
||||||
public String textStatus() {
|
public String textStatus() {
|
||||||
if (sStatus == CONNECTING)
|
if (sStatus == CONNECTING)
|
||||||
return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed);
|
return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed);
|
||||||
|
else if (sStatus == HANDSHAKING)
|
||||||
|
return MainApp.gs(R.string.handshaking);
|
||||||
else if (sStatus == CONNECTED)
|
else if (sStatus == CONNECTED)
|
||||||
return MainApp.gs(R.string.connected);
|
return MainApp.gs(R.string.connected);
|
||||||
else if (sStatus == PERFORMING)
|
else if (sStatus == PERFORMING)
|
||||||
|
|
|
@ -11,11 +11,13 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
*/
|
*/
|
||||||
public interface PumpInterface {
|
public interface PumpInterface {
|
||||||
|
|
||||||
boolean isInitialized();
|
boolean isInitialized(); // true if pump status has been read and is ready to accept commands
|
||||||
boolean isSuspended();
|
boolean isSuspended(); // true if suspended (not delivering insulin)
|
||||||
boolean isBusy();
|
boolean isBusy(); // if true pump is not ready to accept commands right now
|
||||||
boolean isConnected();
|
boolean isConnected(); // true if BT connection is established
|
||||||
boolean isConnecting();
|
boolean isConnecting(); // true if BT connection is in progress
|
||||||
|
boolean isHandshakeInProgress(); // true if BT is connected but initial handshake is still in progress
|
||||||
|
void finishHandshaking(); // set initial handshake completed
|
||||||
|
|
||||||
void connect(String reason);
|
void connect(String reason);
|
||||||
void disconnect(String reason);
|
void disconnect(String reason);
|
||||||
|
|
|
@ -250,6 +250,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
// ruffyscripter establishes a connection as needed.
|
// ruffyscripter establishes a connection as needed.
|
||||||
|
|
|
@ -175,6 +175,16 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0;
|
return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return sExecutionService != null && sExecutionService.isHandshakeInProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
sExecutionService.finishHandshaking();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +35,9 @@ public class MsgInitConnStatusOption extends MessageBase {
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Pump password: " + DanaRPump.getInstance().password);
|
log.debug("Pump password: " + DanaRPump.getInstance().password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is last message of initial sequence
|
||||||
|
ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,8 @@ public abstract class AbstractDanaRExecutionService extends Service {
|
||||||
protected DanaRPump mDanaRPump = DanaRPump.getInstance();
|
protected DanaRPump mDanaRPump = DanaRPump.getInstance();
|
||||||
protected Treatment mBolusingTreatment = null;
|
protected Treatment mBolusingTreatment = null;
|
||||||
|
|
||||||
protected Boolean mConnectionInProgress = false;
|
protected boolean mConnectionInProgress = false;
|
||||||
|
protected boolean mHandshakeInProgress = false;
|
||||||
|
|
||||||
protected AbstractSerialIOThread mSerialIOThread;
|
protected AbstractSerialIOThread mSerialIOThread;
|
||||||
|
|
||||||
|
@ -131,6 +132,15 @@ public abstract class AbstractDanaRExecutionService extends Service {
|
||||||
return mConnectionInProgress;
|
return mConnectionInProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return isConnected() && mHandshakeInProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finishHandshaking() {
|
||||||
|
mHandshakeInProgress = false;
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
||||||
|
}
|
||||||
|
|
||||||
public void disconnect(String from) {
|
public void disconnect(String from) {
|
||||||
if (mSerialIOThread != null)
|
if (mSerialIOThread != null)
|
||||||
mSerialIOThread.disconnect(from);
|
mSerialIOThread.disconnect(from);
|
||||||
|
|
|
@ -111,6 +111,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
mHandshakeInProgress = false;
|
||||||
mConnectionInProgress = true;
|
mConnectionInProgress = true;
|
||||||
getBTSocketForSelectedPump();
|
getBTSocketForSelectedPump();
|
||||||
if (mRfcommSocket == null || mBTDevice == null) {
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
|
@ -132,7 +133,8 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
mHandshakeInProgress = true;
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mConnectionInProgress = false;
|
mConnectionInProgress = false;
|
||||||
|
|
|
@ -179,6 +179,16 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
|
return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return sExecutionService != null && sExecutionService.isHandshakeInProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
sExecutionService.finishHandshaking();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
mHandshakeInProgress = false;
|
||||||
mConnectionInProgress = true;
|
mConnectionInProgress = true;
|
||||||
getBTSocketForSelectedPump();
|
getBTSocketForSelectedPump();
|
||||||
if (mRfcommSocket == null || mBTDevice == null) {
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
|
@ -136,7 +137,8 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
mHandshakeInProgress = true;
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mConnectionInProgress = false;
|
mConnectionInProgress = false;
|
||||||
|
|
|
@ -221,6 +221,15 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
return danaRSService != null && danaRSService.isConnecting();
|
return danaRSService != null && danaRSService.isConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(String from) {
|
public void disconnect(String from) {
|
||||||
if (L.isEnabled(L.PUMP))
|
if (L.isEnabled(L.PUMP))
|
||||||
|
|
|
@ -144,6 +144,16 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0;
|
return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return sExecutionService != null && sExecutionService.isHandshakeInProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
sExecutionService.finishHandshaking();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) {
|
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) {
|
||||||
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false);
|
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false);
|
||||||
|
|
|
@ -134,6 +134,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
mHandshakeInProgress = false;
|
||||||
mConnectionInProgress = true;
|
mConnectionInProgress = true;
|
||||||
getBTSocketForSelectedPump();
|
getBTSocketForSelectedPump();
|
||||||
if (mRfcommSocket == null || mBTDevice == null) {
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
|
@ -155,7 +156,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
mHandshakeInProgress = true;
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mConnectionInProgress = false;
|
mConnectionInProgress = false;
|
||||||
|
|
|
@ -259,6 +259,15 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
return Connector.get().isPumpConnecting();
|
return Connector.get().isPumpConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
log("InsightPlugin::connect()");
|
log("InsightPlugin::connect()");
|
||||||
|
|
|
@ -88,6 +88,15 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,15 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHandshakeInProgress() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT)
|
||||||
|
|
|
@ -101,6 +101,14 @@ public class QueueThread extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pump.isHandshakeInProgress()) {
|
||||||
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
|
log.debug("handshaking " + secondsElapsed);
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, (int) secondsElapsed));
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (pump.isConnecting()) {
|
if (pump.isConnecting()) {
|
||||||
if (L.isEnabled(L.PUMPQUEUE))
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
log.debug("connecting " + secondsElapsed);
|
log.debug("connecting " + secondsElapsed);
|
||||||
|
@ -109,7 +117,6 @@ public class QueueThread extends Thread {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!pump.isConnected()) {
|
if (!pump.isConnected()) {
|
||||||
if (L.isEnabled(L.PUMPQUEUE))
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
log.debug("connect");
|
log.debug("connect");
|
||||||
|
|
|
@ -1187,6 +1187,7 @@
|
||||||
<string name="setupwizard_preferred_aps_mode">Preferred APS mode</string>
|
<string name="setupwizard_preferred_aps_mode">Preferred APS mode</string>
|
||||||
<string name="treatments_wizard_total_label">Total</string>
|
<string name="treatments_wizard_total_label">Total</string>
|
||||||
<string name="calculation_short">Calc</string>
|
<string name="calculation_short">Calc</string>
|
||||||
|
<string name="handshaking">Handshaking</string>
|
||||||
|
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
|
|
Loading…
Reference in a new issue