This commit is contained in:
Johannes Mockenhaupt 2017-11-04 17:42:47 +01:00
parent 011409a6e5
commit 7c44761f25
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
7 changed files with 18 additions and 22 deletions

View file

@ -153,11 +153,12 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
Bolus bolus = plugin.getPump().lastBolus; Bolus bolus = plugin.getPump().lastBolus;
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
long agoMsc = System.currentTimeMillis() - bolus.timestamp; long agoMsc = System.currentTimeMillis() - bolus.timestamp;
double agoHours = agoMsc / 60d / 60d / 1000d; double bolusMinAgo = agoMsc / 60d / 1000d;
double bolusHoursAgo = agoMsc / 60d / 60d / 1000d;
lastBolusView.setText(getString(R.string.combo_last_bolus, lastBolusView.setText(getString(R.string.combo_last_bolus,
bolus.amount, bolus.amount,
agoHours, bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
getString(R.string.hoursago), bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago),
DateUtil.timeString(bolus.timestamp))); DateUtil.timeString(bolus.timestamp)));
} else { } else {
lastBolusView.setText(""); lastBolusView.setText("");

View file

@ -542,7 +542,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
log.debug("cancelTempBasal: hard-cancelling TBR since user requested"); log.debug("cancelTempBasal: hard-cancelling TBR since user requested");
commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr); commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr);
if (commandResult.enacted) { if (!commandResult.state.tbrActive) {
tempBasal = new TemporaryBasal(System.currentTimeMillis()); tempBasal = new TemporaryBasal(System.currentTimeMillis());
tempBasal.durationInMinutes = 0; tempBasal.durationInMinutes = 0;
tempBasal.source = Source.USER; tempBasal.source = Source.USER;
@ -565,7 +565,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins."); log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins.");
commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15)); commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15));
if (commandResult.enacted) { if (!commandResult.state.tbrActive) {
tempBasal = new TemporaryBasal(System.currentTimeMillis()); tempBasal = new TemporaryBasal(System.currentTimeMillis());
tempBasal.durationInMinutes = 15; tempBasal.durationInMinutes = 15;
tempBasal.source = Source.USER; tempBasal.source = Source.USER;
@ -584,7 +584,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (commandResult != null) { if (commandResult != null) {
pumpEnactResult.success = commandResult.success; pumpEnactResult.success = commandResult.success;
pumpEnactResult.enacted = commandResult.enacted; pumpEnactResult.enacted = true;
} }
return pumpEnactResult; return pumpEnactResult;
} }
@ -599,6 +599,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* NO history, reservoir level fields are updated, this make be done separately if desired. * NO history, reservoir level fields are updated, this make be done separately if desired.
*/ */
private synchronized CommandResult runCommand(String activity, int retries, CommandExecution commandExecution) { private synchronized CommandResult runCommand(String activity, int retries, CommandExecution commandExecution) {
// TODO keep stats of how many commansd failed; if >50% fail raise an alert;
// otherwise all commands could fail, but since we can connect to the pump no 'pump unrechable alert' would be raised.
CommandResult commandResult; CommandResult commandResult;
try { try {
if (activity != null) { if (activity != null) {
@ -622,6 +625,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
pump.lastCmdResult = commandResult; pump.lastCmdResult = commandResult;
pump.lastConnectionAttempt = System.currentTimeMillis(); pump.lastConnectionAttempt = System.currentTimeMillis();
if (commandResult.success) { if (commandResult.success) {
// TOdO is this valid? saying a successful command execution means a successful connect?
// or is the distinction between being able to connect and execute a command successfuly not really meaningful here?
pump.lastSuccessfulConnection = pump.lastConnectionAttempt; pump.lastSuccessfulConnection = pump.lastConnectionAttempt;
} }
} finally { } finally {

View file

@ -13,6 +13,7 @@ import android.content.SharedPreferences;
import android.os.PowerManager; import android.os.PowerManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.mozilla.javascript.ast.Loop;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -25,6 +26,7 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -67,7 +69,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
private void checkPump() { private void checkPump() {
final PumpInterface pump = MainApp.getConfigBuilder(); final PumpInterface pump = MainApp.getConfigBuilder();
final Profile profile = MainApp.getConfigBuilder().getProfile(); final Profile profile = MainApp.getConfigBuilder().getProfile();
if (pump != null && profile != null && profile.getBasal() != null) { // TODO suspended?
if (pump != null && profile != null && profile.getBasal() != null && !LoopPlugin.getPlugin().isSuspended()) {
Date lastConnection = pump.lastDataTime(); Date lastConnection = pump.lastDataTime();
boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis(); boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis();

View file

@ -8,11 +8,6 @@ import de.jotomo.ruffy.spi.history.PumpHistory;
public class CommandResult { public class CommandResult {
/** Whether the command was executed successfully. */ /** Whether the command was executed successfully. */
public boolean success; public boolean success;
/** Whether any changes were made, e.g. if a the request was to cancel a running TBR,
* but not TBR was active, this will be false.
* @deprecated for bolus, set tbr, set basal profile, set time: check with a second command, don't rely on this*/
@Deprecated
public boolean enacted;
/** Null unless an unhandled exception was raised. */ /** Null unless an unhandled exception was raised. */
public Exception exception; public Exception exception;
/** State of the pump *after* command execution. */ /** State of the pump *after* command execution. */
@ -46,11 +41,6 @@ public class CommandResult {
return this; return this;
} }
public CommandResult enacted(boolean enacted) {
this.enacted = enacted;
return this;
}
public CommandResult duration(String duration) { public CommandResult duration(String duration) {
this.duration = duration; this.duration = duration;
return this; return this;
@ -80,7 +70,6 @@ public class CommandResult {
public String toString() { public String toString() {
return "CommandResult{" + return "CommandResult{" +
", success=" + success + ", success=" + success +
", enacted=" + enacted +
", exception=" + exception + ", exception=" + exception +
", state=" + state + ", state=" + state +
", history=" + history + ", history=" + history +

View file

@ -728,13 +728,13 @@ public class RuffyScripter implements RuffyCommands {
@Override @Override
public CommandResult getDateAndTime() { public CommandResult getDateAndTime() {
return new CommandResult().success(false).enacted(false); return new CommandResult().success(false);
} }
@Override @Override
public CommandResult setDateAndTime(Date date) { public CommandResult setDateAndTime(Date date) {
// TODO // TODO
return new CommandResult().success(false).enacted(false); return new CommandResult().success(false);
} }
@Override @Override

View file

@ -78,7 +78,6 @@ public class BolusCommand extends BaseCommand {
// confirm bolus // confirm bolus
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER); scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
scripter.pressCheckKey(); scripter.pressCheckKey();
result.enacted = true;
// the pump displays the entered bolus and waits a few seconds to let user check and cancel // the pump displays the entered bolus and waits a few seconds to let user check and cancel
while (scripter.getCurrentMenu().getType() == MenuType.BOLUS_ENTER) { while (scripter.getCurrentMenu().getType() == MenuType.BOLUS_ENTER) {

View file

@ -26,7 +26,6 @@ public class CancelTbrCommand extends BaseCommand {
// This is non-critical; when cancelling a TBR and the connection was interrupted // This is non-critical; when cancelling a TBR and the connection was interrupted
// the TBR was cancelled by that. In that case not cancelling anything is fine. // the TBR was cancelled by that. In that case not cancelling anything is fine.
result.success = true; result.success = true;
result.enacted = false;
return; return;
} }