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;
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
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,
bolus.amount,
agoHours,
getString(R.string.hoursago),
bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago),
DateUtil.timeString(bolus.timestamp)));
} else {
lastBolusView.setText("");

View file

@ -542,7 +542,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
log.debug("cancelTempBasal: hard-cancelling TBR since user requested");
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.durationInMinutes = 0;
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.");
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.durationInMinutes = 15;
tempBasal.source = Source.USER;
@ -584,7 +584,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (commandResult != null) {
pumpEnactResult.success = commandResult.success;
pumpEnactResult.enacted = commandResult.enacted;
pumpEnactResult.enacted = true;
}
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.
*/
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;
try {
if (activity != null) {
@ -622,6 +625,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
pump.lastCmdResult = commandResult;
pump.lastConnectionAttempt = System.currentTimeMillis();
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;
}
} finally {

View file

@ -13,6 +13,7 @@ import android.content.SharedPreferences;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import org.mozilla.javascript.ast.Loop;
import org.slf4j.Logger;
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.DatabaseHelper;
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.events.EventNewNotification;
import info.nightscout.utils.SP;
@ -67,7 +69,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
private void checkPump() {
final PumpInterface pump = MainApp.getConfigBuilder();
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();
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 {
/** Whether the command was executed successfully. */
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. */
public Exception exception;
/** State of the pump *after* command execution. */
@ -46,11 +41,6 @@ public class CommandResult {
return this;
}
public CommandResult enacted(boolean enacted) {
this.enacted = enacted;
return this;
}
public CommandResult duration(String duration) {
this.duration = duration;
return this;
@ -80,7 +70,6 @@ public class CommandResult {
public String toString() {
return "CommandResult{" +
", success=" + success +
", enacted=" + enacted +
", exception=" + exception +
", state=" + state +
", history=" + history +

View file

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

View file

@ -78,7 +78,6 @@ public class BolusCommand extends BaseCommand {
// confirm bolus
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
scripter.pressCheckKey();
result.enacted = true;
// the pump displays the entered bolus and waits a few seconds to let user check and cancel
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
// the TBR was cancelled by that. In that case not cancelling anything is fine.
result.success = true;
result.enacted = false;
return;
}