RS connection and status reading
This commit is contained in:
parent
a186ce6468
commit
86b11edd58
35 changed files with 460 additions and 324 deletions
|
@ -58,4 +58,7 @@ public class Constants {
|
||||||
|
|
||||||
//Autosens
|
//Autosens
|
||||||
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
||||||
|
|
||||||
|
// Pump
|
||||||
|
public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 5 * 60;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,16 +168,13 @@ public class MainApp extends Application {
|
||||||
|
|
||||||
startKeepAliveService();
|
startKeepAliveService();
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null);
|
||||||
if (pump != null)
|
|
||||||
pump.refreshDataFromPump("Initialization");
|
|
||||||
}
|
}
|
||||||
});
|
}).start();
|
||||||
t.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package info.nightscout.androidaps.interfaces;
|
package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 12.06.2017.
|
* Created by mike on 12.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface DanaRInterface {
|
public interface DanaRInterface {
|
||||||
boolean loadHistory(byte type);
|
PumpEnactResult loadHistory(byte type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,15 @@ public interface PumpInterface {
|
||||||
|
|
||||||
void connect(String reason);
|
void connect(String reason);
|
||||||
void disconnect(String reason);
|
void disconnect(String reason);
|
||||||
|
void stopConnecting();
|
||||||
|
|
||||||
|
void getPumpStatus();
|
||||||
|
|
||||||
// Upload to pump new basal profile
|
// Upload to pump new basal profile
|
||||||
PumpEnactResult setNewBasalProfile(Profile profile);
|
PumpEnactResult setNewBasalProfile(Profile profile);
|
||||||
boolean isThisProfileSet(Profile profile);
|
boolean isThisProfileSet(Profile profile);
|
||||||
|
|
||||||
Date lastDataTime();
|
Date lastDataTime();
|
||||||
void refreshDataFromPump(String reason);
|
|
||||||
|
|
||||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||||
|
|
||||||
|
|
|
@ -416,6 +416,18 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
activePump.disconnect(reason);
|
activePump.disconnect(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
if (activePump != null)
|
||||||
|
activePump.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (activePump != null)
|
||||||
|
activePump.getPumpStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -457,12 +469,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
else return new Date();
|
else return new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (activePump != null)
|
|
||||||
activePump.refreshDataFromPump(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
if (activePump != null)
|
if (activePump != null)
|
||||||
|
|
|
@ -601,12 +601,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
break;
|
break;
|
||||||
case R.id.overview_pumpstatus:
|
case R.id.overview_pumpstatus:
|
||||||
if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized())
|
if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized())
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -27,10 +28,12 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||||
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SetWarnColor;
|
import info.nightscout.utils.SetWarnColor;
|
||||||
|
@ -38,11 +41,14 @@ import info.nightscout.utils.SetWarnColor;
|
||||||
public class DanaRFragment extends SubscriberFragment {
|
public class DanaRFragment extends SubscriberFragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private Handler loopHandler = new Handler();
|
private Handler loopHandler = new Handler();
|
||||||
private Runnable refreshLoop = null;
|
private Runnable refreshLoop = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateGUI();
|
||||||
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TextView lastConnectionView;
|
TextView lastConnectionView;
|
||||||
TextView btConnectionView;
|
TextView btConnectionView;
|
||||||
|
@ -58,6 +64,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
TextView basalStepView;
|
TextView basalStepView;
|
||||||
TextView bolusStepView;
|
TextView bolusStepView;
|
||||||
TextView serialNumberView;
|
TextView serialNumberView;
|
||||||
|
TextView queueView;
|
||||||
Button viewProfileButton;
|
Button viewProfileButton;
|
||||||
Button historyButton;
|
Button historyButton;
|
||||||
Button statsButton;
|
Button statsButton;
|
||||||
|
@ -65,35 +72,19 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
LinearLayout pumpStatusLayout;
|
LinearLayout pumpStatusLayout;
|
||||||
TextView pumpStatusView;
|
TextView pumpStatusView;
|
||||||
|
|
||||||
static Runnable connectRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
public DanaRFragment() {
|
public DanaRFragment() {
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(DanaRFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (refreshLoop == null) {
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
refreshLoop = new Runnable() {
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
@Override
|
||||||
updateGUI();
|
public void onDestroy() {
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
super.onDestroy();
|
||||||
}
|
loopHandler.removeCallbacks(refreshLoop);
|
||||||
};
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,6 +109,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
||||||
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
||||||
serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber);
|
serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber);
|
||||||
|
queueView = (TextView) view.findViewById(R.id.danar_queue);
|
||||||
|
|
||||||
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
||||||
pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
||||||
|
@ -150,7 +142,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
log.debug("Clicked connect to pump");
|
log.debug("Clicked connect to pump");
|
||||||
sHandler.post(connectRunnable);
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -206,6 +198,11 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventQueueChanged s) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
// GUI functions
|
// GUI functions
|
||||||
@Override
|
@Override
|
||||||
protected void updateGUI() {
|
protected void updateGUI() {
|
||||||
|
@ -266,10 +263,17 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
basalStepView.setText("" + pump.basalStep);
|
basalStepView.setText("" + pump.basalStep);
|
||||||
bolusStepView.setText("" + pump.bolusStep);
|
bolusStepView.setText("" + pump.bolusStep);
|
||||||
serialNumberView.setText("" + pump.serialNumber);
|
serialNumberView.setText("" + pump.serialNumber);
|
||||||
|
if (queueView != null) {
|
||||||
|
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
|
||||||
|
if (status.toString().equals("")) {
|
||||||
|
queueView.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
queueView.setVisibility(View.VISIBLE);
|
||||||
|
queueView.setText(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,13 +302,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
connect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -685,6 +678,16 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -748,7 +751,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -513,9 +514,10 @@ public class DanaRExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connect("loadHistory");
|
connect("loadHistory");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -555,7 +557,9 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
|
|
|
@ -304,13 +304,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
connect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -682,6 +675,16 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -745,7 +748,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -458,9 +459,10 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connect("loadHistory");
|
connect("loadHistory");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -500,7 +502,9 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
|
|
|
@ -219,11 +219,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectIfNotConnected(String from) {
|
|
||||||
if (!isConnected())
|
|
||||||
connect(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String from) {
|
public void connect(String from) {
|
||||||
log.debug("RS connect from: " + from);
|
log.debug("RS connect from: " + from);
|
||||||
|
@ -231,22 +226,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
final Object o = new Object();
|
final Object o = new Object();
|
||||||
|
|
||||||
danaRSService.connect(from, mDeviceAddress, o);
|
danaRSService.connect(from, mDeviceAddress, o);
|
||||||
synchronized (o) {
|
|
||||||
try {
|
|
||||||
o.wait(20000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.error("InterruptedException " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pumpDescription.basalStep = pump.basalStep;
|
pumpDescription.basalStep = pump.basalStep;
|
||||||
pumpDescription.bolusStep = pump.bolusStep;
|
pumpDescription.bolusStep = pump.bolusStep;
|
||||||
if (isConnected())
|
|
||||||
log.debug("RS connected: " + from);
|
|
||||||
else {
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
|
||||||
danaRSService.stopConnecting();
|
|
||||||
log.debug("RS connect failed from: " + from);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,19 +246,23 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
if (danaRSService != null) danaRSService.disconnect(from);
|
if (danaRSService != null) danaRSService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(DanaRS_Packet message) {
|
@Override
|
||||||
if (danaRSService != null) danaRSService.sendMessage(message);
|
public void stopConnecting() {
|
||||||
|
if (danaRSService != null) danaRSService.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (danaRSService != null)
|
||||||
|
danaRSService.getPumpStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// DanaR interface
|
// DanaR interface
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
connectIfNotConnected("loadHistory");
|
return danaRSService.loadHistory(type);
|
||||||
danaRSService.loadHistory(type);
|
}
|
||||||
disconnect("LoadHistory");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constraints interface
|
// Constraints interface
|
||||||
|
|
||||||
|
@ -444,16 +429,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void refreshDataFromPump(String reason) {
|
|
||||||
log.debug("Refreshing data from pump");
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
connect(reason);
|
|
||||||
disconnect("RefreshDataFromPump");
|
|
||||||
} else
|
|
||||||
log.debug("Already connecting ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -491,7 +466,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
boolean connectionOK = false;
|
boolean connectionOK = false;
|
||||||
connectIfNotConnected("bolus");
|
|
||||||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||||
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, System.currentTimeMillis() + carbTime * 60 * 1000 + 1000, t); // +1000 to make the record different
|
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, System.currentTimeMillis() + carbTime * 60 * 1000 + 1000, t); // +1000 to make the record different
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -501,7 +475,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||||
disconnect("DeliverTreatment");
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -527,9 +500,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
|
||||||
connect("setTempBasalAbsolute old data");
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
}
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -631,7 +606,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
||||||
connectIfNotConnected("tempbasal");
|
|
||||||
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
|
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
|
||||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -644,7 +618,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = true;
|
result.isPercent = true;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setTempBasalPercent: OK");
|
log.debug("setTempBasalPercent: OK");
|
||||||
disconnect("setTempBasalPercent");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -656,7 +629,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connectIfNotConnected("hightempbasal");
|
|
||||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -668,7 +640,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = true;
|
result.isPercent = true;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setHighTempBasalPercent: OK");
|
log.debug("setHighTempBasalPercent: OK");
|
||||||
disconnect("setHighTempBasalPercent");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -699,7 +670,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
|
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
connectIfNotConnected("extendedBolus");
|
|
||||||
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
|
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
|
||||||
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
|
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -712,7 +682,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = false;
|
result.isPercent = false;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setExtendedBolus: OK");
|
log.debug("setExtendedBolus: OK");
|
||||||
disconnect("setExtendedBolus");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -727,11 +696,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (runningTB != null) {
|
if (runningTB != null) {
|
||||||
connectIfNotConnected("tempBasalStop");
|
|
||||||
danaRSService.tempBasalStop();
|
danaRSService.tempBasalStop();
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isTempCancel = true;
|
result.isTempCancel = true;
|
||||||
disconnect("cancelTempBasal");
|
|
||||||
}
|
}
|
||||||
if (!pump.isTempBasalInProgress) {
|
if (!pump.isTempBasalInProgress) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
@ -754,11 +721,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (runningEB != null) {
|
if (runningEB != null) {
|
||||||
connectIfNotConnected("extendedBolusStop");
|
|
||||||
danaRSService.extendedBolusStop();
|
danaRSService.extendedBolusStop();
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isTempCancel = true;
|
result.isTempCancel = true;
|
||||||
disconnect("extendedBolusStop");
|
|
||||||
}
|
}
|
||||||
if (!pump.isExtendedInProgress) {
|
if (!pump.isExtendedInProgress) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
||||||
private int min = 0;
|
private int min = 0;
|
||||||
private int sec = 0;
|
private int sec = 0;
|
||||||
|
|
||||||
public boolean done;
|
public static boolean done;
|
||||||
private int totalCount;
|
private static int totalCount;
|
||||||
|
|
||||||
public static long lastEventTimeLoaded = 0;
|
public static long lastEventTimeLoaded = 0;
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
||||||
// Last record
|
// Last record
|
||||||
if (recordCode == (byte) 0xFF) {
|
if (recordCode == (byte) 0xFF) {
|
||||||
done = true;
|
done = true;
|
||||||
|
log.debug("Last record received");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -59,8 +58,6 @@ public class BLEComm {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object mConfirmConnect = null;
|
|
||||||
|
|
||||||
private final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private ScheduledFuture<?> scheduledDisconnection = null;
|
private ScheduledFuture<?> scheduledDisconnection = null;
|
||||||
|
|
||||||
|
@ -116,7 +113,6 @@ public class BLEComm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(String from, String address, Object confirmConnect) {
|
public boolean connect(String from, String address, Object confirmConnect) {
|
||||||
mConfirmConnect = confirmConnect;
|
|
||||||
BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE));
|
BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE));
|
||||||
if (tBluetoothManager == null) {
|
if (tBluetoothManager == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -146,9 +142,9 @@ public class BLEComm {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("Trying to create a new connection.");
|
||||||
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
||||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||||
log.debug("Trying to create a new connection.");
|
|
||||||
mBluetoothDevice = device;
|
mBluetoothDevice = device;
|
||||||
mBluetoothDeviceAddress = address;
|
mBluetoothDeviceAddress = address;
|
||||||
mBluetoothDeviceName = device.getName();
|
mBluetoothDeviceName = device.getName();
|
||||||
|
@ -207,6 +203,7 @@ public class BLEComm {
|
||||||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
close();
|
close();
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
|
isConnecting = false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
||||||
log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected
|
log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected
|
||||||
}
|
}
|
||||||
|
@ -214,9 +211,6 @@ public class BLEComm {
|
||||||
|
|
||||||
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
||||||
log.debug("onServicesDiscovered");
|
log.debug("onServicesDiscovered");
|
||||||
|
|
||||||
isConnecting = false;
|
|
||||||
|
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
findCharacteristic();
|
findCharacteristic();
|
||||||
}
|
}
|
||||||
|
@ -486,18 +480,11 @@ public class BLEComm {
|
||||||
pass = pass ^ 3463;
|
pass = pass ^ 3463;
|
||||||
DanaRPump.getInstance().rs_password = Integer.toHexString(pass);
|
DanaRPump.getInstance().rs_password = Integer.toHexString(pass);
|
||||||
log.debug("Pump user password: " + Integer.toHexString(pass));
|
log.debug("Pump user password: " + Integer.toHexString(pass));
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
|
|
||||||
|
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
service.getPumpStatus();
|
log.debug("RS connected and status read");
|
||||||
scheduleDisconnection();
|
|
||||||
if (mConfirmConnect != null) {
|
|
||||||
synchronized (mConfirmConnect) {
|
|
||||||
mConfirmConnect.notify();
|
|
||||||
mConfirmConnect = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -527,7 +514,6 @@ public class BLEComm {
|
||||||
} else {
|
} else {
|
||||||
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
||||||
}
|
}
|
||||||
scheduleDisconnection();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -622,7 +608,6 @@ public class BLEComm {
|
||||||
if (!message.isReceived()) {
|
if (!message.isReceived()) {
|
||||||
log.warn("Reply not received " + message.getFriendlyName());
|
log.warn("Reply not received " + message.getFriendlyName());
|
||||||
}
|
}
|
||||||
scheduleDisconnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendPairingRequest() {
|
private void SendPairingRequest() {
|
||||||
|
@ -651,22 +636,4 @@ public class BLEComm {
|
||||||
writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes);
|
writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleDisconnection() {
|
|
||||||
|
|
||||||
class DisconnectRunnable implements Runnable {
|
|
||||||
public void run() {
|
|
||||||
disconnect("scheduleDisconnection");
|
|
||||||
scheduledDisconnection = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// prepare task for execution in 30 sec
|
|
||||||
// cancel waiting task to prevent sending multiple disconnections
|
|
||||||
if (scheduledDisconnection != null)
|
|
||||||
scheduledDisconnection.cancel(false);
|
|
||||||
Runnable task = new DisconnectRunnable();
|
|
||||||
final int sec = 30;
|
|
||||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
|
||||||
log.debug("Disconnection scheduled");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -122,7 +123,7 @@ public class DanaRSService extends Service {
|
||||||
bleComm.sendMessage(message);
|
bleComm.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
|
|
||||||
|
@ -172,10 +173,10 @@ public class DanaRSService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
log.debug("Pump status loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public void loadEvents() {
|
||||||
DanaRS_Packet_APS_History_Events msg;
|
DanaRS_Packet_APS_History_Events msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
msg = new DanaRS_Packet_APS_History_Events(0);
|
msg = new DanaRS_Packet_APS_History_Events(0);
|
||||||
|
@ -189,7 +190,7 @@ public class DanaRSService extends Service {
|
||||||
SystemClock.sleep(100);
|
SystemClock.sleep(100);
|
||||||
}
|
}
|
||||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||||
return true;
|
log.debug("Events loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,8 +359,9 @@ public class DanaRSService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
if (!isConnected()) return false;
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
if (!isConnected()) return result;
|
||||||
DanaRS_Packet_History_ msg = null;
|
DanaRS_Packet_History_ msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -400,7 +402,9 @@ public class DanaRSService extends Service {
|
||||||
SystemClock.sleep(200);
|
SystemClock.sleep(200);
|
||||||
bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(0));
|
bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(0));
|
||||||
}
|
}
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -289,13 +289,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
connect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -629,6 +622,16 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -692,7 +695,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -506,9 +507,10 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connect("loadHistory");
|
connect("loadHistory");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -548,7 +550,9 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public boolean loadEvents() {
|
||||||
|
|
|
@ -147,6 +147,14 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
||||||
public void disconnect(String reason) {
|
public void disconnect(String reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
|
@ -165,11 +173,6 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return 0d;
|
return 0d;
|
||||||
|
|
|
@ -196,12 +196,23 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
|
if (!BuildConfig.NSCLIENTOLNY)
|
||||||
|
NSUpload.uploadDeviceStatus();
|
||||||
|
lastDataTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(String reason) {
|
public void disconnect(String reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
lastDataTime = new Date();
|
lastDataTime = new Date();
|
||||||
|
@ -221,13 +232,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
return lastDataTime;
|
return lastDataTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!BuildConfig.NSCLIENTOLNY)
|
|
||||||
NSUpload.uploadDeviceStatus();
|
|
||||||
lastDataTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package info.nightscout.androidaps.queue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 09.11.2017.
|
|
||||||
*/
|
|
||||||
public abstract class Command {
|
|
||||||
enum CommandType {
|
|
||||||
BOLUS,
|
|
||||||
TEMPBASAL,
|
|
||||||
EXTENDEDBOLUS,
|
|
||||||
BASALPROFILE,
|
|
||||||
READSTATUS
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandType commandType;
|
|
||||||
Callback callback;
|
|
||||||
|
|
||||||
public abstract void execute();
|
|
||||||
|
|
||||||
public abstract String status();
|
|
||||||
}
|
|
|
@ -13,9 +13,48 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandLoadHistory;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandReadStatus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandSetProfile;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 08.11.2017.
|
* Created by mike on 08.11.2017.
|
||||||
|
*
|
||||||
|
* DATA FLOW:
|
||||||
|
* ---------
|
||||||
|
*
|
||||||
|
* (request) - > ConfigBuilder.getCommandQueue().bolus(...)
|
||||||
|
*
|
||||||
|
* app no longer waits for result but passes Callback
|
||||||
|
*
|
||||||
|
* request is added to queue, if another request of the same type already exists in queue, it's removed prior adding
|
||||||
|
* but if request of the same type is currently executed (probably important only for bolus which is running long time), new request is declined
|
||||||
|
* new QueueThread is created and started if current if finished
|
||||||
|
* CommandReadStatus is added automatically before command if queue is empty
|
||||||
|
*
|
||||||
|
* biggest change is we don't need exec pump commands in Handler because it's finished immediately
|
||||||
|
* command queueing if not realized by stacking in different Handlers and threads anymore but by internal queue with better control
|
||||||
|
*
|
||||||
|
* QueueThread calls ConfigBuilder#connect which is passed to getActivePump().connect
|
||||||
|
* connect should be executed on background and return immediately. afterwards isConnecting() is expected to be true
|
||||||
|
*
|
||||||
|
* while isConnecting() == true GUI is updated by posting connection progress
|
||||||
|
*
|
||||||
|
* if connect is successful: isConnected() becomes true, isConnecting() becomes false
|
||||||
|
* CommandQueue starts calling execute() of commands. execute() is expected to be blocking (return after finish).
|
||||||
|
* callback with result is called after finish automatically
|
||||||
|
* if connect failed: isConnected() becomes false, isConnecting() becomes false
|
||||||
|
* connect() is called again
|
||||||
|
*
|
||||||
|
* when queue is empty, disconnect is called
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CommandQueue {
|
public class CommandQueue {
|
||||||
|
@ -24,7 +63,7 @@ public class CommandQueue {
|
||||||
private LinkedList<Command> queue = new LinkedList<>();
|
private LinkedList<Command> queue = new LinkedList<>();
|
||||||
private Command performing;
|
private Command performing;
|
||||||
|
|
||||||
private QueueThread thread = new QueueThread(this);
|
private QueueThread thread = null;
|
||||||
|
|
||||||
private PumpEnactResult executingNowError() {
|
private PumpEnactResult executingNowError() {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -34,26 +73,8 @@ public class CommandQueue {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunningTempBasal() {
|
public boolean isRunning(Command.CommandType type) {
|
||||||
if (performing != null && performing.commandType == Command.CommandType.TEMPBASAL)
|
if (performing != null && performing.commandType == type)
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunningBolus() {
|
|
||||||
if (performing != null && performing.commandType == Command.CommandType.BOLUS)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunningExtendedBolus() {
|
|
||||||
if (performing != null && performing.commandType == Command.CommandType.EXTENDEDBOLUS)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunningProfile() {
|
|
||||||
if (performing != null && performing.commandType == Command.CommandType.BASALPROFILE)
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -67,14 +88,22 @@ public class CommandQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void add(Command command) {
|
private synchronized void add(Command command) {
|
||||||
|
// inject reading of status when adding first command to the queue
|
||||||
|
if (queue.size() == 0 && command.commandType != Command.CommandType.READSTATUS)
|
||||||
|
queue.add(new CommandReadStatus("Queue", null));
|
||||||
queue.add(command);
|
queue.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void pickup() {
|
synchronized void pickup() {
|
||||||
performing = queue.poll();
|
performing = queue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
synchronized void clear() {
|
||||||
|
performing = null;
|
||||||
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
queue.get(i).cancel();
|
||||||
|
}
|
||||||
|
|
||||||
queue.clear();
|
queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +119,20 @@ public class CommandQueue {
|
||||||
performing = null;
|
performing = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After new command added to the queue
|
||||||
|
// start thread again if not already running
|
||||||
private void notifyAboutNewCommand() {
|
private void notifyAboutNewCommand() {
|
||||||
if (!thread.isAlive())
|
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||||
|
thread = new QueueThread(this);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||||
if (isRunningBolus()) {
|
if (isRunning(Command.CommandType.BOLUS)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,12 +149,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean tempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
public boolean tempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||||
if (isRunningTempBasal()) {
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.TEMPBASAL);
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -133,12 +168,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||||
if (isRunningTempBasal()) {
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.TEMPBASAL);
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -151,12 +187,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean extendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
public boolean extendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
||||||
if (isRunningExtendedBolus()) {
|
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -169,12 +206,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean cancelTempBasal(boolean enforceNew, Callback callback) {
|
public boolean cancelTempBasal(boolean enforceNew, Callback callback) {
|
||||||
if (isRunningTempBasal()) {
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.TEMPBASAL);
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -187,12 +225,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean cancelExtended(Callback callback) {
|
public boolean cancelExtended(Callback callback) {
|
||||||
if (isRunningExtendedBolus()) {
|
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -205,12 +244,13 @@ public class CommandQueue {
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
public boolean setProfile(Profile profile, Callback callback) {
|
public boolean setProfile(Profile profile, Callback callback) {
|
||||||
if (isRunningProfile()) {
|
if (isRunning(Command.CommandType.BASALPROFILE)) {
|
||||||
callback.result(executingNowError()).run();
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unfinished boluese
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.BASALPROFILE);
|
removeAll(Command.CommandType.BASALPROFILE);
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
|
@ -221,13 +261,53 @@ public class CommandQueue {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spanned spannedStatus() {
|
// returns true if command is queued
|
||||||
|
public boolean readStatus(String reason, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.READSTATUS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.READSTATUS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandReadStatus(reason, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean loadHistory(byte type, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.LOADHISTORY)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.LOADHISTORY);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandLoadHistory(type, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spanned spannedStatus() {
|
||||||
String s = "";
|
String s = "";
|
||||||
if (performing != null) {
|
if (performing != null) {
|
||||||
s += "<b>" + performing.status() + "</b><br>";
|
s += "<b>" + performing.status() + "</b>";
|
||||||
}
|
}
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
s += queue.get(i).status() + "<br>";
|
if (i != 0)
|
||||||
|
s += "<br>";
|
||||||
|
s += queue.get(i).status();
|
||||||
}
|
}
|
||||||
return Html.fromHtml(s);
|
return Html.fromHtml(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ import android.os.SystemClock;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -18,8 +21,6 @@ public class QueueThread extends Thread {
|
||||||
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
||||||
|
|
||||||
CommandQueue queue;
|
CommandQueue queue;
|
||||||
boolean keepRunning = false;
|
|
||||||
|
|
||||||
|
|
||||||
private long connectionStartTime = 0;
|
private long connectionStartTime = 0;
|
||||||
|
|
||||||
|
@ -27,40 +28,60 @@ public class QueueThread extends Thread {
|
||||||
super(QueueThread.class.toString());
|
super(QueueThread.class.toString());
|
||||||
|
|
||||||
this.queue = queue;
|
this.queue = queue;
|
||||||
keepRunning = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run() {
|
public final void run() {
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
|
connectionStartTime = System.currentTimeMillis();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
while (keepRunning) {
|
while (true) {
|
||||||
|
log.debug("Looping ...");
|
||||||
|
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||||
if (pump.isConnecting()) {
|
if (pump.isConnecting()) {
|
||||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
log.debug("State: connecting");
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
||||||
|
log.debug("State: timed out");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
||||||
|
pump.stopConnecting();
|
||||||
|
queue.clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pump.isConnected()) {
|
if (!pump.isConnected()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING));
|
log.debug("State: connect");
|
||||||
pump.connect("Not connected");
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||||
connectionStartTime = System.currentTimeMillis();
|
pump.connect("Connection needed");
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue.performing() == null) {
|
if (queue.performing() == null) {
|
||||||
// Pickup 1st command and set performing variable
|
// Pickup 1st command and set performing variable
|
||||||
if (queue.size() > 0) {
|
if (queue.size() > 0) {
|
||||||
|
log.debug("State: performing");
|
||||||
queue.pickup();
|
queue.pickup();
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
queue.performing().execute();
|
queue.performing().execute();
|
||||||
queue.resetPerforming();
|
queue.resetPerforming();
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue.size() == 0 && queue.performing() == null) {
|
if (queue.size() == 0 && queue.performing() == null) {
|
||||||
|
log.debug("State: queue empty. disconnect");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
pump.disconnect("Queue empty");
|
pump.disconnect("Queue empty");
|
||||||
keepRunning = false;
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 09.11.2017.
|
||||||
|
*/
|
||||||
|
public abstract class Command {
|
||||||
|
public enum CommandType {
|
||||||
|
BOLUS,
|
||||||
|
TEMPBASAL,
|
||||||
|
EXTENDEDBOLUS,
|
||||||
|
BASALPROFILE,
|
||||||
|
READSTATUS,
|
||||||
|
LOADHISTORY // so far only Dana specific
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandType commandType;
|
||||||
|
protected Callback callback;
|
||||||
|
|
||||||
|
public abstract void execute();
|
||||||
|
|
||||||
|
public abstract String status();
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = false;
|
||||||
|
result.comment = MainApp.sResources.getString(R.string.connectiontimedout);
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(result).run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +13,7 @@ import info.nightscout.utils.DecimalFormatter;
|
||||||
public class CommandBolus extends Command {
|
public class CommandBolus extends Command {
|
||||||
DetailedBolusInfo detailedBolusInfo;
|
DetailedBolusInfo detailedBolusInfo;
|
||||||
|
|
||||||
CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||||
commandType = CommandType.BOLUS;
|
commandType = CommandType.BOLUS;
|
||||||
this.detailedBolusInfo = detailedBolusInfo;
|
this.detailedBolusInfo = detailedBolusInfo;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
@ -20,7 +21,7 @@ public class CommandBolus extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().deliverTreatment(detailedBolusInfo);
|
PumpEnactResult r = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -16,7 +17,7 @@ public class CommandCancelExtendedBolus extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().cancelExtendedBolus();
|
PumpEnactResult r = MainApp.getConfigBuilder().cancelExtendedBolus();
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -10,7 +11,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
public class CommandCancelTempBasal extends Command {
|
public class CommandCancelTempBasal extends Command {
|
||||||
boolean enforceNew;
|
boolean enforceNew;
|
||||||
|
|
||||||
CommandCancelTempBasal(boolean enforceNew, Callback callback) {
|
public CommandCancelTempBasal(boolean enforceNew, Callback callback) {
|
||||||
commandType = CommandType.TEMPBASAL;
|
commandType = CommandType.TEMPBASAL;
|
||||||
this.enforceNew = enforceNew;
|
this.enforceNew = enforceNew;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
@ -18,7 +19,7 @@ public class CommandCancelTempBasal extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().cancelTempBasal(enforceNew);
|
PumpEnactResult r = MainApp.getConfigBuilder().cancelTempBasal(enforceNew);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -1,15 +1,16 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CommandExtendedBolus extends Command {
|
public class CommandExtendedBolus extends Command {
|
||||||
double insulin;
|
private double insulin;
|
||||||
int durationInMinutes;
|
private int durationInMinutes;
|
||||||
|
|
||||||
public CommandExtendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
public CommandExtendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
||||||
commandType = CommandType.EXTENDEDBOLUS;
|
commandType = CommandType.EXTENDEDBOLUS;
|
||||||
|
@ -20,7 +21,7 @@ public class CommandExtendedBolus extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setExtendedBolus(insulin, durationInMinutes);
|
PumpEnactResult r = MainApp.getConfigBuilder().setExtendedBolus(insulin, durationInMinutes);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 10.11.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CommandLoadHistory extends Command {
|
||||||
|
byte type;
|
||||||
|
|
||||||
|
public CommandLoadHistory(byte type, Callback callback) {
|
||||||
|
commandType = CommandType.LOADHISTORY;
|
||||||
|
this.type = type;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
if (pump instanceof DanaRInterface) {
|
||||||
|
DanaRInterface danaPump = (DanaRInterface) pump;
|
||||||
|
PumpEnactResult r = danaPump.loadHistory(type);
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(r).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String status() {
|
||||||
|
return "LOADHISTORY " + type;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +1,30 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CommandReadStatus extends Command {
|
public class CommandReadStatus extends Command {
|
||||||
|
String reason;
|
||||||
|
|
||||||
CommandReadStatus(Callback callback) {
|
public CommandReadStatus(String reason, Callback callback) {
|
||||||
commandType = CommandType.READSTATUS;
|
commandType = CommandType.READSTATUS;
|
||||||
|
this.reason = reason;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
// do nothing by default. Status is read on connection
|
MainApp.getConfigBuilder().getPumpStatus();
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(null).run();
|
callback.result(null).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String status() {
|
public String status() {
|
||||||
return "READ STATUS";
|
return "READSTATUS " + reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -11,7 +12,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
public class CommandSetProfile extends Command {
|
public class CommandSetProfile extends Command {
|
||||||
Profile profile;
|
Profile profile;
|
||||||
|
|
||||||
CommandSetProfile(Profile profile, Callback callback) {
|
public CommandSetProfile(Profile profile, Callback callback) {
|
||||||
commandType = CommandType.BASALPROFILE;
|
commandType = CommandType.BASALPROFILE;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
@ -19,7 +20,7 @@ public class CommandSetProfile extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setNewBasalProfile(profile);
|
PumpEnactResult r = MainApp.getConfigBuilder().setNewBasalProfile(profile);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -12,7 +13,7 @@ public class CommandTempBasalAbsolute extends Command {
|
||||||
double absoluteRate;
|
double absoluteRate;
|
||||||
boolean enforceNew;
|
boolean enforceNew;
|
||||||
|
|
||||||
CommandTempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
public CommandTempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||||
commandType = CommandType.TEMPBASAL;
|
commandType = CommandType.TEMPBASAL;
|
||||||
this.absoluteRate = absoluteRate;
|
this.absoluteRate = absoluteRate;
|
||||||
this.durationInMinutes = durationInMinutes;
|
this.durationInMinutes = durationInMinutes;
|
||||||
|
@ -22,7 +23,7 @@ public class CommandTempBasalAbsolute extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
|
PumpEnactResult r = MainApp.getConfigBuilder().setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package info.nightscout.androidaps.queue;
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.11.2017.
|
* Created by mike on 09.11.2017.
|
||||||
|
@ -11,7 +12,7 @@ public class CommandTempBasalPercent extends Command {
|
||||||
int durationInMinutes;
|
int durationInMinutes;
|
||||||
int percent;
|
int percent;
|
||||||
|
|
||||||
CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
public CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||||
commandType = CommandType.TEMPBASAL;
|
commandType = CommandType.TEMPBASAL;
|
||||||
this.percent = percent;
|
this.percent = percent;
|
||||||
this.durationInMinutes = durationInMinutes;
|
this.durationInMinutes = durationInMinutes;
|
||||||
|
@ -20,7 +21,7 @@ public class CommandTempBasalPercent extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes);
|
PumpEnactResult r = MainApp.getConfigBuilder().setTempBasalPercent(percent, durationInMinutes);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(r).run();
|
callback.result(r).run();
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package info.nightscout.androidaps.queue.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 11.11.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class EventQueueChanged {
|
||||||
|
}
|
|
@ -47,29 +47,11 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) {
|
if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) {
|
||||||
Thread t = new Thread(new Runnable() {
|
MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
pump.setNewBasalProfile(profile);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.start();
|
|
||||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||||
Thread t = new Thread(new Runnable() {
|
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
pump.refreshDataFromPump("KeepAlive. Status outdated.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.start();
|
|
||||||
} else if (isBasalOutdated && !pump.isBusy()) {
|
} else if (isBasalOutdated && !pump.isBusy()) {
|
||||||
Thread t = new Thread(new Runnable() {
|
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
pump.refreshDataFromPump("KeepAlive. Basal outdated.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,13 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/danar_queue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="content"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="2dip"
|
android:layout_height="2dip"
|
||||||
|
|
Loading…
Reference in a new issue