Merge remote-tracking branch 'origin/dev' into combo-scripter-v2

* origin/dev:
  fix objective 1
  upload aps status and iob when loop is suspended
  fully offline CP
  Queue: synchronize creating queue thread to avoid multiple threads.
  Wear: No guard for RS
This commit is contained in:
Johannes Mockenhaupt 2017-12-31 11:41:41 +01:00
commit 8ee95077a8
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
5 changed files with 36 additions and 29 deletions

View file

@ -260,7 +260,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
**/
@Override
public boolean isLoopEnabled() {
return objectives.get(1).started.getTime() > 0;
return objectives.get(0).started.getTime() > 0;
}
@Override

View file

@ -259,18 +259,6 @@ public class LoopPlugin implements PluginBase {
if (!isEnabled(PluginBase.LOOP))
return;
if (isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.loopsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopsuspended)));
return;
}
if (pump.isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
return;
}
if (MainApp.getConfigBuilder().getProfile() == null) {
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
@ -280,7 +268,7 @@ public class LoopPlugin implements PluginBase {
// Check if pump info is loaded
if (pump.getBaseBasalRate() < 0.01d) return;
APSInterface usedAPS = MainApp.getConfigBuilder().getActiveAPS();
APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS();
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) {
usedAPS.invoke(initiator);
result = usedAPS.getLastAPSResult();
@ -303,6 +291,20 @@ public class LoopPlugin implements PluginBase {
lastRun.source = ((PluginBase) usedAPS).getName();
lastRun.setByPump = null;
NSUpload.uploadDeviceStatus();
if (isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.loopsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopsuspended)));
return;
}
if (pump.isSuspended()) {
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
return;
}
if (constraintsInterface.isClosedModeEnabled()) {
if (result.changeRequested) {
final PumpEnactResult waiting = new PumpEnactResult();
@ -363,7 +365,6 @@ public class LoopPlugin implements PluginBase {
}
MainApp.bus().post(new EventLoopUpdateGui());
NSUpload.uploadDeviceStatus();
} finally {
if (Config.logFunctionCalls)
log.debug("invoke end");

View file

@ -30,14 +30,6 @@ public class DBAccessReceiver extends BroadcastReceiver {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
DBAccessReceiver.class.getSimpleName());
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
return;
}
if (SP.getBoolean(R.string.key_ns_noupload, false)) {
log.debug("Upload disabled. Message dropped");
return;
}
wakeLock.acquire();
try {
Bundle bundles = intent.getExtras();
@ -83,16 +75,22 @@ public class DBAccessReceiver extends BroadcastReceiver {
}
if (action.equals("dbRemove")) {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
UploadQueue.add(dbr);
if (shouldUpload()) {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
UploadQueue.add(dbr);
}
} else {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
// this is not used as mongo _id but only for searching in UploadQueue database
// if record has to be removed from queue before upload
dbr._id = nsclientid.toString();
UploadQueue.add(dbr);
if (collection.equals("treatments"))
if (shouldUpload()) {
UploadQueue.add(dbr);
}
if (collection.equals("treatments")) {
genereateTreatmentOfflineBroadcast(dbr);
}
}
} finally {
@ -101,6 +99,11 @@ public class DBAccessReceiver extends BroadcastReceiver {
}
public boolean shouldUpload() {
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
return nsClientInternalPlugin.isEnabled(PluginBase.GENERAL) && !SP.getBoolean(R.string.key_ns_noupload, false);
}
public void genereateTreatmentOfflineBroadcast(DbRequest request) {
if (request.action.equals("dbAdd")) {
try {

View file

@ -38,6 +38,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard;
@ -268,13 +269,15 @@ public class ActionStringHandler {
} else if ("tddstats".equals(act[0])) {
Object activePump = MainApp.getConfigBuilder().getActivePump();
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class);
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
if ((dana == null || dana != activePump) &&
(danaV2 == null || danaV2 != activePump) &&
(danaKorean == null || danaKorean != activePump)
(danaKorean == null || danaKorean != activePump) &&
(danaRS == null || danaRS != activePump)
) {
sendError("Pump does not support TDDs!");
return;

View file

@ -128,7 +128,7 @@ public class CommandQueue {
// After new command added to the queue
// start thread again if not already running
private void notifyAboutNewCommand() {
private synchronized void notifyAboutNewCommand() {
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
thread = new QueueThread(this);
thread.start();