RS connection and status reading
This commit is contained in:
parent
a186ce6468
commit
86b11edd58
|
@ -58,4 +58,7 @@ public class Constants {
|
|||
|
||||
//Autosens
|
||||
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();
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemClock.sleep(5000);
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
if (pump != null)
|
||||
pump.refreshDataFromPump("Initialization");
|
||||
ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null);
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
|
||||
/**
|
||||
* Created by mike on 12.06.2017.
|
||||
*/
|
||||
|
||||
public interface DanaRInterface {
|
||||
boolean loadHistory(byte type);
|
||||
PumpEnactResult loadHistory(byte type);
|
||||
}
|
||||
|
|
|
@ -21,13 +21,15 @@ public interface PumpInterface {
|
|||
|
||||
void connect(String reason);
|
||||
void disconnect(String reason);
|
||||
void stopConnecting();
|
||||
|
||||
void getPumpStatus();
|
||||
|
||||
// Upload to pump new basal profile
|
||||
PumpEnactResult setNewBasalProfile(Profile profile);
|
||||
boolean isThisProfileSet(Profile profile);
|
||||
|
||||
Date lastDataTime();
|
||||
void refreshDataFromPump(String reason);
|
||||
|
||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||
|
||||
|
|
|
@ -416,6 +416,18 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
activePump.disconnect(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
if (activePump != null)
|
||||
activePump.stopConnecting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
if (activePump != null)
|
||||
activePump.getPumpStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -457,12 +469,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
else return new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (activePump != null)
|
||||
activePump.refreshDataFromPump(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
if (activePump != null)
|
||||
|
|
|
@ -601,12 +601,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
break;
|
||||
case R.id.overview_pumpstatus:
|
||||
if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized())
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
|
||||
}
|
||||
});
|
||||
ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
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.EventTempBasalChange;
|
||||
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.activities.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SetWarnColor;
|
||||
|
@ -38,11 +41,14 @@ import info.nightscout.utils.SetWarnColor;
|
|||
public class DanaRFragment extends SubscriberFragment {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
||||
|
||||
private static Handler sHandler;
|
||||
private static HandlerThread sHandlerThread;
|
||||
|
||||
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 btConnectionView;
|
||||
|
@ -58,6 +64,7 @@ public class DanaRFragment extends SubscriberFragment {
|
|||
TextView basalStepView;
|
||||
TextView bolusStepView;
|
||||
TextView serialNumberView;
|
||||
TextView queueView;
|
||||
Button viewProfileButton;
|
||||
Button historyButton;
|
||||
Button statsButton;
|
||||
|
@ -65,35 +72,19 @@ public class DanaRFragment extends SubscriberFragment {
|
|||
LinearLayout pumpStatusLayout;
|
||||
TextView pumpStatusView;
|
||||
|
||||
static Runnable connectRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public DanaRFragment() {
|
||||
if (sHandlerThread == null) {
|
||||
sHandlerThread = new HandlerThread(DanaRFragment.class.getSimpleName());
|
||||
sHandlerThread.start();
|
||||
sHandler = new Handler(sHandlerThread.getLooper());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (refreshLoop == null) {
|
||||
refreshLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI();
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||
}
|
||||
};
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||
}
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
loopHandler.removeCallbacks(refreshLoop);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,6 +109,7 @@ public class DanaRFragment extends SubscriberFragment {
|
|||
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
||||
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
||||
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.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
||||
|
@ -150,7 +142,7 @@ public class DanaRFragment extends SubscriberFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
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();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventQueueChanged s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
// GUI functions
|
||||
@Override
|
||||
protected void updateGUI() {
|
||||
|
@ -266,10 +263,17 @@ public class DanaRFragment extends SubscriberFragment {
|
|||
basalStepView.setText("" + pump.basalStep);
|
||||
bolusStepView.setText("" + pump.bolusStep);
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (!isConnected() && !isConnecting()) {
|
||||
connect(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return pump.currentBasal;
|
||||
|
@ -685,6 +678,16 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
|||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
|
@ -748,7 +751,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
|||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
|
@ -513,9 +514,10 @@ public class DanaRExecutionService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
connect("loadHistory");
|
||||
if (!isConnected()) return false;
|
||||
if (!isConnected()) return result;
|
||||
MessageBase msg = null;
|
||||
switch (type) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
|
@ -555,7 +557,9 @@ public class DanaRExecutionService extends Service {
|
|||
}
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||
return true;
|
||||
result.success = true;
|
||||
result.comment = "OK";
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean updateBasalsInPump(final Profile profile) {
|
||||
|
|
|
@ -304,13 +304,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
|||
return pump.lastConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (!isConnected() && !isConnecting()) {
|
||||
connect(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return pump.currentBasal;
|
||||
|
@ -682,6 +675,16 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
|||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
|
@ -745,7 +748,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
|||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
|
@ -458,9 +459,10 @@ public class DanaRKoreanExecutionService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
connect("loadHistory");
|
||||
if (!isConnected()) return false;
|
||||
if (!isConnected()) return result;
|
||||
MessageBase msg = null;
|
||||
switch (type) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
|
@ -500,7 +502,9 @@ public class DanaRKoreanExecutionService extends Service {
|
|||
}
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||
return true;
|
||||
result.success = true;
|
||||
result.comment = "OK";
|
||||
return result;
|
||||
}
|
||||
|
||||
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, "");
|
||||
}
|
||||
|
||||
public void connectIfNotConnected(String from) {
|
||||
if (!isConnected())
|
||||
connect(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(String from) {
|
||||
log.debug("RS connect from: " + from);
|
||||
|
@ -231,22 +226,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
final Object o = new Object();
|
||||
|
||||
danaRSService.connect(from, mDeviceAddress, o);
|
||||
synchronized (o) {
|
||||
try {
|
||||
o.wait(20000);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("InterruptedException " + e);
|
||||
}
|
||||
}
|
||||
pumpDescription.basalStep = pump.basalStep;
|
||||
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);
|
||||
}
|
||||
|
||||
public static void sendMessage(DanaRS_Packet message) {
|
||||
if (danaRSService != null) danaRSService.sendMessage(message);
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
if (danaRSService != null) danaRSService.stopConnecting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
if (danaRSService != null)
|
||||
danaRSService.getPumpStatus();
|
||||
}
|
||||
|
||||
// DanaR interface
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
connectIfNotConnected("loadHistory");
|
||||
danaRSService.loadHistory(type);
|
||||
disconnect("LoadHistory");
|
||||
return true;
|
||||
}
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
return danaRSService.loadHistory(type);
|
||||
}
|
||||
|
||||
// Constraints interface
|
||||
|
||||
|
@ -444,16 +429,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
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
|
||||
public double getBaseBasalRate() {
|
||||
return pump.currentBasal;
|
||||
|
@ -491,7 +466,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
|
||||
Treatment t = new Treatment();
|
||||
boolean connectionOK = false;
|
||||
connectIfNotConnected("bolus");
|
||||
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
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -501,7 +475,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (Config.logPumpActions)
|
||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
disconnect("DeliverTreatment");
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -527,9 +500,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
@Override
|
||||
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||
// 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();
|
||||
|
||||
|
@ -631,7 +606,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
return result;
|
||||
}
|
||||
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
||||
connectIfNotConnected("tempbasal");
|
||||
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
|
||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||
result.enacted = true;
|
||||
|
@ -644,7 +618,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
disconnect("setTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -656,7 +629,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
|
||||
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
connectIfNotConnected("hightempbasal");
|
||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||
result.enacted = true;
|
||||
|
@ -668,7 +640,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setHighTempBasalPercent: OK");
|
||||
disconnect("setHighTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
connectIfNotConnected("extendedBolus");
|
||||
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
|
||||
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
|
||||
result.enacted = true;
|
||||
|
@ -712,7 +682,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = false;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setExtendedBolus: OK");
|
||||
disconnect("setExtendedBolus");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -727,11 +696,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
PumpEnactResult result = new PumpEnactResult();
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
connectIfNotConnected("tempBasalStop");
|
||||
danaRSService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("cancelTempBasal");
|
||||
}
|
||||
if (!pump.isTempBasalInProgress) {
|
||||
result.success = true;
|
||||
|
@ -754,11 +721,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
PumpEnactResult result = new PumpEnactResult();
|
||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null) {
|
||||
connectIfNotConnected("extendedBolusStop");
|
||||
danaRSService.extendedBolusStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("extendedBolusStop");
|
||||
}
|
||||
if (!pump.isExtendedInProgress) {
|
||||
result.success = true;
|
||||
|
|
|
@ -30,8 +30,8 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
private int min = 0;
|
||||
private int sec = 0;
|
||||
|
||||
public boolean done;
|
||||
private int totalCount;
|
||||
public static boolean done;
|
||||
private static int totalCount;
|
||||
|
||||
public static long lastEventTimeLoaded = 0;
|
||||
|
||||
|
@ -77,6 +77,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
// Last record
|
||||
if (recordCode == (byte) 0xFF) {
|
||||
done = true;
|
||||
log.debug("Last record received");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.UUID;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -59,8 +58,6 @@ public class BLEComm {
|
|||
return instance;
|
||||
}
|
||||
|
||||
private Object mConfirmConnect = null;
|
||||
|
||||
private final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||
private ScheduledFuture<?> scheduledDisconnection = null;
|
||||
|
||||
|
@ -116,7 +113,6 @@ public class BLEComm {
|
|||
}
|
||||
|
||||
public boolean connect(String from, String address, Object confirmConnect) {
|
||||
mConfirmConnect = confirmConnect;
|
||||
BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE));
|
||||
if (tBluetoothManager == null) {
|
||||
return false;
|
||||
|
@ -146,9 +142,9 @@ public class BLEComm {
|
|||
return false;
|
||||
}
|
||||
|
||||
log.debug("Trying to create a new connection.");
|
||||
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||
log.debug("Trying to create a new connection.");
|
||||
mBluetoothDevice = device;
|
||||
mBluetoothDeviceAddress = address;
|
||||
mBluetoothDeviceName = device.getName();
|
||||
|
@ -207,6 +203,7 @@ public class BLEComm {
|
|||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
close();
|
||||
isConnected = false;
|
||||
isConnecting = false;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.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) {
|
||||
log.debug("onServicesDiscovered");
|
||||
|
||||
isConnecting = false;
|
||||
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
findCharacteristic();
|
||||
}
|
||||
|
@ -486,18 +480,11 @@ public class BLEComm {
|
|||
pass = pass ^ 3463;
|
||||
DanaRPump.getInstance().rs_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;
|
||||
isConnecting = false;
|
||||
service.getPumpStatus();
|
||||
scheduleDisconnection();
|
||||
if (mConfirmConnect != null) {
|
||||
synchronized (mConfirmConnect) {
|
||||
mConfirmConnect.notify();
|
||||
mConfirmConnect = null;
|
||||
}
|
||||
}
|
||||
log.debug("RS connected and status read");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -527,7 +514,6 @@ public class BLEComm {
|
|||
} else {
|
||||
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
||||
}
|
||||
scheduleDisconnection();
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -622,7 +608,6 @@ public class BLEComm {
|
|||
if (!message.isReceived()) {
|
||||
log.warn("Reply not received " + message.getFriendlyName());
|
||||
}
|
||||
scheduleDisconnection();
|
||||
}
|
||||
|
||||
private void SendPairingRequest() {
|
||||
|
@ -651,22 +636,4 @@ public class BLEComm {
|
|||
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.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
|
@ -122,7 +123,7 @@ public class DanaRSService extends Service {
|
|||
bleComm.sendMessage(message);
|
||||
}
|
||||
|
||||
protected boolean getPumpStatus() {
|
||||
public void getPumpStatus() {
|
||||
try {
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||
|
||||
|
@ -172,10 +173,10 @@ public class DanaRSService extends Service {
|
|||
} catch (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;
|
||||
if (lastHistoryFetched == 0) {
|
||||
msg = new DanaRS_Packet_APS_History_Events(0);
|
||||
|
@ -189,7 +190,7 @@ public class DanaRSService extends Service {
|
|||
SystemClock.sleep(100);
|
||||
}
|
||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||
return true;
|
||||
log.debug("Events loaded");
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,8 +359,9 @@ public class DanaRSService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean loadHistory(byte type) {
|
||||
if (!isConnected()) return false;
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (!isConnected()) return result;
|
||||
DanaRS_Packet_History_ msg = null;
|
||||
switch (type) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
|
@ -400,7 +402,9 @@ public class DanaRSService extends Service {
|
|||
SystemClock.sleep(200);
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (!isConnected() && !isConnecting()) {
|
||||
connect(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return pump.currentBasal;
|
||||
|
@ -629,6 +622,16 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus() {
|
||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
|
@ -692,7 +695,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
|
@ -506,9 +507,10 @@ public class DanaRv2ExecutionService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean loadHistory(byte type) {
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
connect("loadHistory");
|
||||
if (!isConnected()) return false;
|
||||
if (!isConnected()) return result;
|
||||
MessageBase msg = null;
|
||||
switch (type) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
|
@ -548,7 +550,9 @@ public class DanaRv2ExecutionService extends Service {
|
|||
}
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||
return true;
|
||||
result.success = true;
|
||||
result.comment = "OK";
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean loadEvents() {
|
||||
|
|
|
@ -147,6 +147,14 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
|||
public void disconnect(String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
|
@ -165,11 +173,6 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
|||
return new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return 0d;
|
||||
|
|
|
@ -196,12 +196,23 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public void connect(String reason) {
|
||||
if (!BuildConfig.NSCLIENTOLNY)
|
||||
NSUpload.uploadDeviceStatus();
|
||||
lastDataTime = new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopConnecting() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
lastDataTime = new Date();
|
||||
|
@ -221,13 +232,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
return lastDataTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
if (!BuildConfig.NSCLIENTOLNY)
|
||||
NSUpload.uploadDeviceStatus();
|
||||
lastDataTime = new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
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.Profile;
|
||||
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.
|
||||
*
|
||||
* 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 {
|
||||
|
@ -24,7 +63,7 @@ public class CommandQueue {
|
|||
private LinkedList<Command> queue = new LinkedList<>();
|
||||
private Command performing;
|
||||
|
||||
private QueueThread thread = new QueueThread(this);
|
||||
private QueueThread thread = null;
|
||||
|
||||
private PumpEnactResult executingNowError() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -34,26 +73,8 @@ public class CommandQueue {
|
|||
return result;
|
||||
}
|
||||
|
||||
public boolean isRunningTempBasal() {
|
||||
if (performing != null && performing.commandType == Command.CommandType.TEMPBASAL)
|
||||
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)
|
||||
public boolean isRunning(Command.CommandType type) {
|
||||
if (performing != null && performing.commandType == type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -67,14 +88,22 @@ public class CommandQueue {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected synchronized void pickup() {
|
||||
synchronized void pickup() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -90,15 +119,20 @@ public class CommandQueue {
|
|||
performing = null;
|
||||
}
|
||||
|
||||
// After new command added to the queue
|
||||
// start thread again if not already running
|
||||
private void notifyAboutNewCommand() {
|
||||
if (!thread.isAlive())
|
||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||
thread = new QueueThread(this);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if command is queued
|
||||
public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||
if (isRunningBolus()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.BOLUS)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -115,12 +149,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean tempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||
if (isRunningTempBasal()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.TEMPBASAL);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -133,12 +168,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||
if (isRunningTempBasal()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.TEMPBASAL);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -151,12 +187,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean extendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
||||
if (isRunningExtendedBolus()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -169,12 +206,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean cancelTempBasal(boolean enforceNew, Callback callback) {
|
||||
if (isRunningTempBasal()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.TEMPBASAL);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -187,12 +225,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean cancelExtended(Callback callback) {
|
||||
if (isRunningExtendedBolus()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -205,12 +244,13 @@ public class CommandQueue {
|
|||
|
||||
// returns true if command is queued
|
||||
public boolean setProfile(Profile profile, Callback callback) {
|
||||
if (isRunningProfile()) {
|
||||
callback.result(executingNowError()).run();
|
||||
if (isRunning(Command.CommandType.BASALPROFILE)) {
|
||||
if (callback != null)
|
||||
callback.result(executingNowError()).run();
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove all unfinished boluese
|
||||
// remove all unfinished
|
||||
removeAll(Command.CommandType.BASALPROFILE);
|
||||
|
||||
// add new command to queue
|
||||
|
@ -221,13 +261,53 @@ public class CommandQueue {
|
|||
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 = "";
|
||||
if (performing != null) {
|
||||
s += "<b>" + performing.status() + "</b><br>";
|
||||
s += "<b>" + performing.status() + "</b>";
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -5,10 +5,13 @@ import android.os.SystemClock;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -18,8 +21,6 @@ public class QueueThread extends Thread {
|
|||
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
||||
|
||||
CommandQueue queue;
|
||||
boolean keepRunning = false;
|
||||
|
||||
|
||||
private long connectionStartTime = 0;
|
||||
|
||||
|
@ -27,40 +28,60 @@ public class QueueThread extends Thread {
|
|||
super(QueueThread.class.toString());
|
||||
|
||||
this.queue = queue;
|
||||
keepRunning = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
MainApp.bus().post(new EventQueueChanged());
|
||||
connectionStartTime = System.currentTimeMillis();
|
||||
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
|
||||
while (keepRunning) {
|
||||
while (true) {
|
||||
log.debug("Looping ...");
|
||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||
if (pump.isConnecting()) {
|
||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||
log.debug("State: connecting");
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||
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()) {
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING));
|
||||
pump.connect("Not connected");
|
||||
connectionStartTime = System.currentTimeMillis();
|
||||
log.debug("State: connect");
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||
pump.connect("Connection needed");
|
||||
SystemClock.sleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (queue.performing() == null) {
|
||||
// Pickup 1st command and set performing variable
|
||||
if (queue.size() > 0) {
|
||||
log.debug("State: performing");
|
||||
queue.pickup();
|
||||
MainApp.bus().post(new EventQueueChanged());
|
||||
queue.performing().execute();
|
||||
queue.resetPerforming();
|
||||
MainApp.bus().post(new EventQueueChanged());
|
||||
SystemClock.sleep(100);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (queue.size() == 0 && queue.performing() == null) {
|
||||
log.debug("State: queue empty. disconnect");
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||
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.PumpEnactResult;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +13,7 @@ import info.nightscout.utils.DecimalFormatter;
|
|||
public class CommandBolus extends Command {
|
||||
DetailedBolusInfo detailedBolusInfo;
|
||||
|
||||
CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||
public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||
commandType = CommandType.BOLUS;
|
||||
this.detailedBolusInfo = detailedBolusInfo;
|
||||
this.callback = callback;
|
||||
|
@ -20,7 +21,7 @@ public class CommandBolus extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().deliverTreatment(detailedBolusInfo);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
|
||||
if (callback != null)
|
||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -16,7 +17,7 @@ public class CommandCancelExtendedBolus extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().cancelExtendedBolus();
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().cancelExtendedBolus();
|
||||
if (callback != null)
|
||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -10,7 +11,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|||
public class CommandCancelTempBasal extends Command {
|
||||
boolean enforceNew;
|
||||
|
||||
CommandCancelTempBasal(boolean enforceNew, Callback callback) {
|
||||
public CommandCancelTempBasal(boolean enforceNew, Callback callback) {
|
||||
commandType = CommandType.TEMPBASAL;
|
||||
this.enforceNew = enforceNew;
|
||||
this.callback = callback;
|
||||
|
@ -18,7 +19,7 @@ public class CommandCancelTempBasal extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().cancelTempBasal(enforceNew);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().cancelTempBasal(enforceNew);
|
||||
if (callback != null)
|
||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
*/
|
||||
|
||||
public class CommandExtendedBolus extends Command {
|
||||
double insulin;
|
||||
int durationInMinutes;
|
||||
private double insulin;
|
||||
private int durationInMinutes;
|
||||
|
||||
public CommandExtendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
||||
commandType = CommandType.EXTENDEDBOLUS;
|
||||
|
@ -20,7 +21,7 @@ public class CommandExtendedBolus extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setExtendedBolus(insulin, durationInMinutes);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().setExtendedBolus(insulin, durationInMinutes);
|
||||
if (callback != null)
|
||||
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.
|
||||
*/
|
||||
|
||||
public class CommandReadStatus extends Command {
|
||||
String reason;
|
||||
|
||||
CommandReadStatus(Callback callback) {
|
||||
public CommandReadStatus(String reason, Callback callback) {
|
||||
commandType = CommandType.READSTATUS;
|
||||
this.reason = reason;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
// do nothing by default. Status is read on connection
|
||||
MainApp.getConfigBuilder().getPumpStatus();
|
||||
if (callback != null)
|
||||
callback.result(null).run();
|
||||
}
|
||||
|
||||
@Override
|
||||
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.PumpEnactResult;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -11,7 +12,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|||
public class CommandSetProfile extends Command {
|
||||
Profile profile;
|
||||
|
||||
CommandSetProfile(Profile profile, Callback callback) {
|
||||
public CommandSetProfile(Profile profile, Callback callback) {
|
||||
commandType = CommandType.BASALPROFILE;
|
||||
this.profile = profile;
|
||||
this.callback = callback;
|
||||
|
@ -19,7 +20,7 @@ public class CommandSetProfile extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setNewBasalProfile(profile);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().setNewBasalProfile(profile);
|
||||
if (callback != null)
|
||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -12,7 +13,7 @@ public class CommandTempBasalAbsolute extends Command {
|
|||
double absoluteRate;
|
||||
boolean enforceNew;
|
||||
|
||||
CommandTempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||
public CommandTempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||
commandType = CommandType.TEMPBASAL;
|
||||
this.absoluteRate = absoluteRate;
|
||||
this.durationInMinutes = durationInMinutes;
|
||||
|
@ -22,7 +23,7 @@ public class CommandTempBasalAbsolute extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
|
||||
if (callback != null)
|
||||
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.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
||||
/**
|
||||
* Created by mike on 09.11.2017.
|
||||
|
@ -11,7 +12,7 @@ public class CommandTempBasalPercent extends Command {
|
|||
int durationInMinutes;
|
||||
int percent;
|
||||
|
||||
CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||
public CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||
commandType = CommandType.TEMPBASAL;
|
||||
this.percent = percent;
|
||||
this.durationInMinutes = durationInMinutes;
|
||||
|
@ -20,7 +21,7 @@ public class CommandTempBasalPercent extends Command {
|
|||
|
||||
@Override
|
||||
public void execute() {
|
||||
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes);
|
||||
PumpEnactResult r = MainApp.getConfigBuilder().setTempBasalPercent(percent, durationInMinutes);
|
||||
if (callback != null)
|
||||
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());
|
||||
if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pump.setNewBasalProfile(profile);
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null);
|
||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pump.refreshDataFromPump("KeepAlive. Status outdated.");
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||
} else if (isBasalOutdated && !pump.isBusy()) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pump.refreshDataFromPump("KeepAlive. Basal outdated.");
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,6 +124,13 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_queue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="content"
|
||||
android:textAlignment="center" />
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
|
|
Loading…
Reference in a new issue