Merge branch 'no-history-for-you' into combo-scripter-v2

* no-history-for-you:
  When bolusing, only read history in case of error or cancellation.
  Cleanups.
  Remove lastBolus, reservoirLevel.
  Use timestamp for TBR, not pump minutes.
  Rework checkAndResolveTbrMismatch to update from pump to AAPS only.
  ComboFragment: move forced history read to long-pressing the TDD button.
  More steps towards reducing comms amount.
  Don't check pump history, clean up usage of pumpHistoryLastChecked, mark stuff to disable.
  Remove last bolus, units display of reservoir level from Combo fragment.

# Conflicts:
#	app/src/main/res/values/strings.xml
This commit is contained in:
Johannes Mockenhaupt 2017-12-05 00:34:22 +01:00
commit e7d49f2300
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
9 changed files with 114 additions and 170 deletions

View file

@ -20,7 +20,7 @@ public class ComboAlertHistoryDialog extends DialogFragment {
TextView text = (TextView) layout.findViewById(R.id.combo_error_history_text);
List<PumpAlert> errors = ComboPlugin.getPlugin().getPump().errorHistory;
if (errors.isEmpty()) {
text.setText(R.string.combo_empty_alert_history_note);
text.setText(R.string.combo_empty_history_note);
} else {
StringBuilder sb = new StringBuilder();
DateFormat dateTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

View file

@ -14,7 +14,6 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.history.Bolus;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
@ -40,7 +39,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery);
reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate);
lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
//lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
buttonsLayout = (LinearLayout) view.findViewById(R.id.combo_buttons_layout);
@ -78,7 +77,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
@Override
public boolean onLongClick(View view) {
switch (view.getId()) {
case R.id.combo_refresh:
case R.id.combo_tdd_history:
new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start();
return true;
}
@ -86,7 +85,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
}
@Subscribe
public void onStatusEvent(final EventComboPumpUpdateGUI ev) {
public void onStatusEvent(final EventComboPumpUpdateGUI ignored) {
updateGUI();
}
@ -130,14 +129,15 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
}
// reservoir
int reservoirLevel = plugin.getPump().reservoirLevel;
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
if (ps.insulinState == PumpState.LOW) {
reservoirView.setTextColor(Color.YELLOW);
reservoirView.setText(R.string.combo_reservoir_low);
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setTextColor(Color.RED);
reservoirView.setText(R.string.combo_reservoir_empty);
} else {
reservoirView.setTextColor(Color.WHITE);
reservoirView.setText(R.string.combo_reservoir_normal);
}
// last connection
@ -154,6 +154,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
lastConnectionView.setTextColor(Color.WHITE);
}
/* reading the data that would be displayed here triggers pump bug
// last bolus
Bolus bolus = plugin.getPump().lastBolus;
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
@ -175,6 +176,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
} else {
lastBolusView.setText("");
}
*/
// TBR
String tbrStr = "";

View file

@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import de.jotomo.ruffy.spi.BasalProfile;
import de.jotomo.ruffy.spi.BolusProgressReporter;
@ -17,11 +16,11 @@ import de.jotomo.ruffy.spi.CommandResult;
import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.PumpWarningCodes;
import de.jotomo.ruffy.spi.RuffyCommands;
import de.jotomo.ruffy.spi.WarningOrErrorCode;
import de.jotomo.ruffy.spi.history.Bolus;
import de.jotomo.ruffy.spi.history.PumpHistory;
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
import de.jotomo.ruffy.spi.history.Tbr;
import de.jotomo.ruffy.spi.WarningOrErrorCode;
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
@ -47,7 +46,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProg
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP;
import static de.jotomo.ruffy.spi.BolusProgressReporter.State.FINISHED;
@ -241,24 +239,20 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return PumpInterface.FAILED;
}
/* don't re-read basal profile to not trigger pump bug; setBasalProfile command checks the total at the end, which must suffice
CommandResult readResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_setting_basal_profile), 2,
ruffyScripter::readBasalProfile);
*/
pump.basalProfile = readResult.basalProfile;
pump.basalProfile = requestedBasalProfile;
if(readResult.success && readResult.basalProfile.equals(requestedBasalProfile)){
//dismiss previously "FAILED" overview notifications
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
//issue success notification
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
MainApp.bus().post(new EventNewNotification(notification));
return PumpInterface.SUCCESS;
} else {
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return PumpInterface.FAILED;
}
//dismiss previously "FAILED" overview notifications
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
//issue success notification
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
MainApp.bus().post(new EventNewNotification(notification));
return PumpInterface.SUCCESS;
}
@Override
@ -322,7 +316,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
CommandResult stateResult = runCommand(pump.initialized ? MainApp.sResources.getString(R.string.combo_pump_action_refreshing) : MainApp.sResources.getString(R.string.combo_pump_action_initializing),
1, ruffyScripter::readReservoirLevelAndLastBolus);
1, ruffyScripter::readPumpState);
if (!stateResult.success) {
return;
}
@ -366,16 +360,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
private void updateLocalData(CommandResult result) {
if (result.reservoirLevel != PumpState.UNKNOWN) {
pump.reservoirLevel = result.reservoirLevel;
}
if (result.lastBolus != null) {
pump.lastBolus = result.lastBolus;
} else if (result.history != null && !result.history.bolusHistory.isEmpty()) {
pump.lastBolus = result.history.bolusHistory.get(0);
}
if (result.state.menu != null) {
pump.state = result.state;
}
@ -466,34 +450,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
Bolus lastKnownBolus = pump.lastBolus;
try {
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
MainApp.bus().post(new EventComboPumpUpdateGUI());
// refresh pump data
CommandResult reservoirBolusResult = runCommand(null, 3,
ruffyScripter::readReservoirLevelAndLastBolus);
if (!reservoirBolusResult.success) {
log.error("Bolus delivery failure at stage 1", new Exception());
return new PumpEnactResult().success(false).enacted(false);
}
// check enough insulin left for bolus
if (Math.round(detailedBolusInfo.insulin + 0.5) > reservoirBolusResult.reservoirLevel) {
log.error("Bolus delivery failure at stage 2", new Exception());
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.sResources.getString(R.string.combo_reservoir_level_insufficient_for_bolus));
}
// verify we're update to date and know the most recent bolus
if (!Objects.equals(lastKnownBolus, reservoirBolusResult.lastBolus)) {
log.error("Bolus delivery failure at stage 3", new Exception());
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_history_state_mismatch));
}
if (cancelBolus) {
return new PumpEnactResult().success(true).enacted(false);
}
@ -505,28 +465,29 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
bolusInProgress = false;
if (!bolusCmdResult.success) {
new Thread(this::checkPumpHistory).start();
log.error("Bolus delivery failure at stage 4", new Exception());
if (!cancelBolus && bolusCmdResult.success) {
detailedBolusInfo.date = bolusCmdResult.state.timestamp;
detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(detailedBolusInfo.insulin)
.carbsDelivered(detailedBolusInfo.carbs);
}
// in case of error check what was actually delivered
CommandResult historyResult = runCommand(null, 1,
() -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
if (!historyResult.success) {
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
}
// verify delivered bolus
reservoirBolusResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
if (!reservoirBolusResult.success) {
log.error("Bolus delivery failure at stage 5", new Exception());
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
}
Bolus lastPumpBolus = reservoirBolusResult.lastBolus;
Bolus lastPumpBolus = historyResult.lastBolus;
if (cancelBolus) {
// if cancellation was requested, the delivered bolus is allowed to differ from requested
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
log.error("Bolus delivery failure at stage 6", new Exception());
return new PumpEnactResult().success(false).enacted(false).
comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
}
// add treatment record to DB (if it wasn't cancelled)
@ -534,8 +495,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
detailedBolusInfo.date = lastPumpBolus.timestamp;
detailedBolusInfo.insulin = lastPumpBolus.amount;
detailedBolusInfo.date = lastPumpBolus.timestamp;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = lastPumpBolus.timestamp;
detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(lastPumpBolus.amount).carbsDelivered(detailedBolusInfo.carbs);
@ -556,13 +516,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override
public void stopBolusDelivering() {
// TODO if the pump is busy setting a TBR while a bolus was requested,
// cancelling here, when the TBR is still being set will fail to cancel the bolus.
// See if the queue might solve this, otherwise we could add a check in runCommand
// (but can't currently determine if the request is a basal request)
// or have the scripter skip the next bolus that comes in
if (bolusInProgress) {
ruffyScripter.cancelBolus();
}
cancelBolus = true;
}
// Note: AAPS calls this only to enact OpenAPS recommendations
// Note: AAPS calls this solely to enact OpenAPS suggestions
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {
// the force parameter isn't used currently since we always set the tbr - there might be room for optimization to
@ -579,7 +544,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return setTempBasalPercent(roundedPercentage, durationInMinutes);
}
// Note: AAPS calls this only for setting a temp basal issued by the user
// Note: AAPS calls this directly only for setting a temp basal issued by the user
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) {
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
@ -622,12 +587,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (state.tbrActive && state.tbrPercent == percent
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
TemporaryBasal tempStart = new TemporaryBasal();
tempStart.date = state.timestamp / (60 * 1000) * (60 * 1000);
tempStart.date = state.timestamp;
tempStart.durationInMinutes = durationInMinutes;
tempStart.percentRate = adjustedPercent;
tempStart.isAbsolute = false;
tempStart.source = Source.PUMP;
tempStart.pumpId = tempStart.date;
tempStart.source = Source.USER;
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
treatmentsInterface.addToHistoryTempBasal(tempStart);
@ -647,9 +611,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public PumpEnactResult cancelTempBasal(boolean userRequested) {
log.debug("cancelTempBasal called");
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp == null) {
return new PumpEnactResult().success(false).enacted(false);
}
if (userRequested) {
log.debug("cancelTempBasal: hard-cancelling TBR since user requested");
CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr);
@ -657,13 +618,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = commandResult.state.timestamp;
tempBasal.durationInMinutes = 0;
tempBasal.source = Source.PUMP;
tempBasal.pumpId = activeTemp.pumpId;
tempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult().isTempCancel(true).success(true).enacted(true);
} else {
return new PumpEnactResult().success(false).enacted(false);
}
} else if (activeTemp == null) {
return new PumpEnactResult().success(true).enacted(false);
} else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15) {
// Let fake neutral temp keep run (see below)
log.debug("cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins.");
@ -676,22 +638,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// on whether the TBR we're cancelling is above or below 100%.
final int percentage = (activeTemp.percentRate > 100) ? 110 : 90;
log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins.");
CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15));
if (commandResult.state.tbrActive && commandResult.state.tbrPercent == percentage
&& (commandResult.state.tbrRemainingDuration == 15 || commandResult.state.tbrRemainingDuration == 14)) {
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = System.currentTimeMillis() / (60 * 1000) * (60 * 1000);
tempBasal.durationInMinutes = 15;
tempBasal.source = Source.PUMP;
tempBasal.pumpId = tempBasal.date;
tempBasal.percentRate = percentage;
tempBasal.isAbsolute = false;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult().success(true).enacted(true);
} else {
return new PumpEnactResult().success(false).enacted(false);
}
return setTempBasalPercent(percentage, 15);
}
}
@ -715,8 +662,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (!ruffyScripter.isConnected()) {
CommandResult preCheckError = runOnConnectChecks();
if (preCheckError != null) {
updateLocalData(preCheckError);
return preCheckError;
updateLocalData(preCheckError);
return preCheckError;
}
}
@ -788,9 +735,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
}
// check if TBR was cancelled or set by user
boolean mismatch = checkForTbrMismatch(preCheckResult.state);
if (mismatch) checkPumpHistory();
checkAndResolveTbrMismatch(preCheckResult.state);
// raise notification if clock is off (setting clock is not supported by ruffy)
if (preCheckResult.state.pumpTimeMinutesOfDay != 0) {
@ -799,6 +744,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if ((Math.abs(preCheckResult.state.pumpTimeMinutesOfDay - minutesOfDayNow) > 3)) {
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_notification_check_time_date), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification));
// setting date time isn't supported by ruffy v1, a warning is issue during connect if clock is off
// runCommand("Updating pump clock", 2, ruffyScripter::setDateAndTime);
}
}
@ -849,39 +795,42 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
/**
* Checks the main screen to determine if TBR on pump matches app state.
*/
private boolean checkForTbrMismatch(PumpState state) {
private void checkAndResolveTbrMismatch(PumpState state) {
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
boolean sync = false;
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
log.debug("Pump runs TBR AAPS is unaware of, cancelling TBR so it can be read from history properly");
runCommand(null, 0, ruffyScripter::cancelTbr);
sync = true;
log.debug("Creating temp basal from pump TBR");
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = System.currentTimeMillis();
newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
newTempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
} else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) {
log.debug("AAPS shows a TBR but pump isn't running a TBR; deleting TBR in AAPS and reading pump history");
MainApp.getDbHelper().delete(aapsTbr);
sync = true;
} else if (aapsTbr != null && state.tbrActive) {
// both AAPS and pump have an active TBR ...
if (aapsTbr.percentRate != state.tbrPercent) {
// ... but they have different percentages
log.debug("TBR percentage differs between AAPS and pump; deleting TBR in AAPS and reading pump history");
MainApp.getDbHelper().delete(aapsTbr);
sync = true;
}
int durationDiff = Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration);
if (durationDiff > 2) {
// ... but they have different runtimes
log.debug("TBR duration differs between AAPS and pump; deleting TBR in AAPS and reading pump history");
MainApp.getDbHelper().delete(aapsTbr);
sync = true;
}
}
log.debug("Ending AAPS-TBR since pump has no TBR active");
TemporaryBasal tempStop = new TemporaryBasal();
tempStop.date = aapsTbr.date;
tempStop.durationInMinutes = 0;
tempStop.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
} else if (aapsTbr != null && state.tbrActive
&& (aapsTbr.percentRate != state.tbrPercent ||
Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration) > 2)) {
log.debug("AAPSs and pump-TBR differ; Ending AAPS-TBR and creating new TBR based on pump TBR");
TemporaryBasal tempStop = new TemporaryBasal();
tempStop.date = aapsTbr.date;
tempStop.durationInMinutes = 0;
tempStop.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
if (sync) {
log.debug("Sync requested from checkTbrMismatch");
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = System.currentTimeMillis();
newTempBasal.percentRate = state.tbrPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
newTempBasal.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
}
return sync;
}
/**
@ -889,6 +838,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* read to get the DB up to date.
*/
private synchronized boolean checkPumpHistory() {
return true;
/* reading history triggers pump bug
// set here, rather at the end so that if this runs into an error it's not tried
// over and over since it's called at the end of runCommand
pumpHistoryLastChecked = System.currentTimeMillis();
@ -956,10 +908,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
return true;
*/
}
/**
* Reads the pump's history and updates the DB accordingly.
*
* Only ever called by #readAllPumpData which is triggered by the user via the combo fragment
* which warns the user against doing this.
*/
private boolean readHistory(final PumpHistoryRequest request) {
CommandResult historyResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(request));
@ -967,15 +923,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return false;
}
// update local cache
PumpHistory history = historyResult.history;
if (!history.bolusHistory.isEmpty()) {
pump.lastHistoryBolusTime = history.bolusHistory.get(0).timestamp;
}
if (!history.tbrHistory.isEmpty()) {
pump.lastHistoryTbrTime = history.tbrHistory.get(0).timestamp;
}
updateDbFromPumpHistory(history);
// update local cache
if (!history.pumpAlertHistory.isEmpty()) {
pump.errorHistory = history.pumpAlertHistory;
}
@ -983,8 +934,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
pump.tddHistory = history.tddHistory;
}
updateDbFromPumpHistory(history);
return historyResult.success;
}
@ -1023,20 +972,26 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
void readAllPumpData() {
long lastCheckInitiated = System.currentTimeMillis();
boolean readHistorySuccess = readHistory(new PumpHistoryRequest()
.bolusHistory(pump.lastHistoryBolusTime)
.tbrHistory(pump.lastHistoryTbrTime)
.bolusHistory(pumpHistoryLastChecked)
.tbrHistory(pumpHistoryLastChecked)
.pumpErrorHistory(PumpHistoryRequest.FULL)
.tddHistory(PumpHistoryRequest.FULL));
if (!readHistorySuccess) {
return;
}
pumpHistoryLastChecked = lastCheckInitiated;
/* not displayed in the UI anymore due to pump bug
CommandResult reservoirResult = runCommand("Checking reservoir level", 2,
ruffyScripter::readReservoirLevelAndLastBolus);
if (!reservoirResult.success) {
return;
}
*/
CommandResult basalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
if (!basalResult.success) {
@ -1060,7 +1015,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
try {
JSONObject pumpJson = new JSONObject();
pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime));
pumpJson.put("reservoir", pump.reservoirLevel);
// TODO can we upload empty/low/normal or is a int expected? If so, use fake numbers like 0/50/200
// pumpJson.put("reservoir", pump.reservoirState);
JSONObject statusJson = new JSONObject();
statusJson.put("status", getStateSummary());
@ -1070,10 +1026,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
JSONObject extendedJson = new JSONObject();
extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
if (pump.lastBolus != null) {
extendedJson.put("LastBolus", new Date(pump.lastBolus.timestamp).toLocaleString());
extendedJson.put("LastBolusAmount", DecimalFormatter.to1Decimal(pump.lastBolus.amount));
}
PumpState ps = pump.state;
if (ps.tbrActive) {
extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate);

View file

@ -1,17 +1,13 @@
package info.nightscout.androidaps.plugins.PumpCombo;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import de.jotomo.ruffy.spi.BasalProfile;
import de.jotomo.ruffy.spi.CommandResult;
import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.history.Bolus;
import de.jotomo.ruffy.spi.history.PumpAlert;
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
import de.jotomo.ruffy.spi.history.Tdd;
class ComboPump {
@ -21,15 +17,9 @@ class ComboPump {
public volatile String activity;
@NonNull
volatile PumpState state = new PumpState();
volatile int reservoirLevel = -1;
volatile Bolus lastBolus = null;
@NonNull
volatile BasalProfile basalProfile = new BasalProfile();
// Last known history record times to skip over old ones when reading history
long lastHistoryBolusTime = PumpHistoryRequest.FULL;
long lastHistoryTbrTime = PumpHistoryRequest.FULL;
// Alert and TDD histories are not stored in DB, but are read on demand and just cached here
List<PumpAlert> errorHistory = new ArrayList<>(0);
List<Tdd> tddHistory = new ArrayList<>(0);

View file

@ -21,7 +21,7 @@ public class ComboTddHistoryDialog extends DialogFragment {
TextView text = (TextView) layout.findViewById(R.id.combo_tdd_history_text);
List<Tdd> tdds = ComboPlugin.getPlugin().getPump().tddHistory;
if (tdds.isEmpty()) {
text.setText(R.string.combo_empty_tdd_history_note);
text.setText(R.string.combo_empty_history_note);
} else {
StringBuilder sb = new StringBuilder();
DateFormat dateFormatter = DateFormat.getDateInstance();

View file

@ -236,6 +236,7 @@
</LinearLayout>
<!-- reading last bolus from pump triggers pump bug
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
@ -280,6 +281,7 @@
android:textSize="14sp" />
</LinearLayout>
-->
<View
android:layout_width="fill_parent"

View file

@ -811,11 +811,8 @@
<string name="key_raise_urgent_alarms_as_android_notification" translatable="false">raise_urgent_alarms_as_android_notification</string>
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
<string name="combo_pump_never_connected">Never</string>
<string name="combo_reservoir_level_insufficient_for_bolus">Not enough insulin left in reservoir for bolus</string>
<string name="combo_pump_bolus_history_state_mismatch">A bolus has been delivered directly on the pump recently, of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check the Combo page, verify the last bolus and IOB and bolus again if needed. No bolus has been delivered.</string>
<string name="combo_pump_bolus_verification_failed">Bolus delivery verification failed. The pump history will be read again on the next loop run or when refreshing from the Combo page. Please check and bolus again if needed.</string>
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed.</string>
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please the pump and treatments tabs and bolus again as needed.</string>
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
<string name="combo_notification_check_time_date">Check pump time and date</string>
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
@ -827,11 +824,13 @@
<string name="combo_pump_cartridge_low_warrning">Pump cartridge level is low</string>
<string name="combo_pump_battery_low_warrning">Pump battery is low</string>
<string name="combo_is_in_error_state">Pump is in an error state, please check the pump</string>
<string name="combo_empty_alert_history_note">To retrieve the alert history from the pump, long press the Refresh button.</string>
<string name="combo_empty_tdd_history_note">To retrieve the TDD history from the pump, long press the Refresh button.</string>
<string name="combo_empty_history_note">To read all data from the pump, long press the Stats button.\n\nWARNING: this can trigger a bug which causes the pump to reject all connection attempts and requires pressing a button on the pump to recover and should therefore be avoided.</string>
<string name="key_sync_profile_to_pump">sync_profile_to_pump</string>
<string name="combo_tdd_minimum">Minimum: %3.1f U</string>
<string name="combo_tdd_average">Average: %3.1f U</string>
<string name="combo_tdd_maximum">Maximum: %3.1f U</string>
<string name="combo_reservoir_low">Low</string>
<string name="combo_reservoir_empty">Empty</string>
<string name="combo_reservoir_normal">Normal</string>
</resources>

View file

@ -2,7 +2,7 @@ package de.jotomo.ruffy.spi;
/** State displayed on the main screen of the pump. */
public class PumpState {
/** Time the state was captured, rounded to a full second */
/** Time the state was captured. This is NOT the pump's time! */
public long timestamp;
/** The time displayed on the main menu */
public long pumpTimeMinutesOfDay;

View file

@ -499,8 +499,7 @@ public class RuffyScripter implements RuffyCommands {
*/
public PumpState readPumpStateInternal() {
PumpState state = new PumpState();
// round timestamp to full second
state.timestamp = System.currentTimeMillis() / (60 * 1000) * (60 * 1000);
state.timestamp = System.currentTimeMillis();
Menu menu = currentMenu;
if (menu == null) {
return state;