From b3a60eb5ab0075b2e718fcb8e7b61d103abe41ab Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 15:22:41 +0100 Subject: [PATCH 01/54] Initial work on basing boluses on pump history. --- .../androidaps/db/DatabaseHelper.java | 35 --- .../plugins/PumpCombo/ComboFragment.java | 10 +- .../plugins/PumpCombo/ComboPlugin.java | 227 ++++++++++++------ app/src/main/res/values/strings.xml | 2 + .../commands/ReadHistoryCommand.java | 74 +++--- 5 files changed, 194 insertions(+), 154 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 3986a8b98d..082f872d20 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -713,24 +713,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - @Nullable - public Treatment getTreatmentByDate(long mills) { - try { - Dao daoTreatments = getDaoTreatments(); - List treatments; - QueryBuilder queryBuilder = daoTreatments.queryBuilder(); - Where where = queryBuilder.where(); - where.eq("date", mills); - PreparedQuery preparedQuery = queryBuilder.prepare(); - treatments = daoTreatments.query(preparedQuery); - // date is unique - return treatments.isEmpty() ? null : treatments.get(0); - } catch (SQLException e) { - log.error("Unhandled exception", e); - return null; - } - } - public List getTreatmentDataFromTime(long mills, boolean ascending) { try { Dao daoTreatments = getDaoTreatments(); @@ -1086,23 +1068,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryBasalChange(); } - @Nullable - public TemporaryBasal getTemporaryBasalsDataByDate(long startTime) { - try { - List tempbasals; - QueryBuilder queryBuilder = getDaoTemporaryBasal().queryBuilder(); - Where where = queryBuilder.where(); - where.eq("date", startTime); - PreparedQuery preparedQuery = queryBuilder.prepare(); - tempbasals = getDaoTemporaryBasal().query(preparedQuery); - // date is unique - return tempbasals.isEmpty() ? null : tempbasals.get(0); - } catch (SQLException e) { - log.error("Unhandled exception", e); - } - return null; - } - public List getTemporaryBasalsDataFromTime(long mills, boolean ascending) { try { List tempbasals; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 4fb9dd250f..6abb40dcec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -85,7 +85,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis case R.id.combo_full_history_button: AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.combo_warning); - builder.setMessage(R.string.combo_read_full_history_warning); + builder.setMessage(R.string.combo_read_full_history_info); builder.show(); break; } @@ -101,13 +101,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis new Thread(() -> ComboPlugin.getPlugin().readTddData()).start(); return true; case R.id.combo_full_history_button: - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(R.string.combo_warning); - builder.setMessage(R.string.combo_read_full_history_confirmation); - builder.setPositiveButton(R.string.ok, (dialog, which) -> - new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start()); - builder.setNegativeButton(MainApp.gs(R.string.cancel), null); - builder.show(); + new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start(); return true; } return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 13e208774f..f960312235 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.PumpCombo; import android.os.SystemClock; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; @@ -10,6 +11,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -101,8 +103,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private volatile boolean bolusInProgress; private volatile boolean cancelBolus; + private Bolus lastRequestedBolus; - private long pumpHistoryLastChecked; +// private long pumpHistoryLastChecked; + private volatile long timestampOfLastKnownBolusRecord; + + /** this is set whenever a connection to the pump is made and indicates if new history + records on the pump have been found */ + private volatile boolean pumpHistoryChanged = false; public static ComboPlugin getPlugin() { if (plugin == null) @@ -347,6 +355,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf initializePump(); } else { runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState); + // note that since the history is checked upon every connect, the above already updated + // the DB with any changed history records } } @@ -368,6 +378,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return; } + // note that since the history is checked upon every connect, the above already updated + // the DB with any changed history records + if (pumpHistoryChanged) { + log.debug("Pump history has changed and was imported"); + pumpHistoryChanged = false; + } + if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) { Notification n = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_force_disabled_notification), @@ -384,6 +401,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } pump.basalProfile = readBasalResult.basalProfile; validBasalRateProfileSelectedOnPump = true; + pump.initialized = true; MainApp.bus().post(new EventInitializationChanged()); @@ -474,15 +492,31 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.bolus_frequency_exceeded)); } + // TODO only check this after a bolus was successfully applied? NO, because in error condition + // we can't say with certainty if a bolus was delivered (we find out when refreshing history next) + // so, be on the annoying but safe side lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true); - CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState); + CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus); long pumpTimeWhenBolusWasRequested = stateResult .state.pumpTime; if (!stateResult.success || pumpTimeWhenBolusWasRequested == 0) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); } + if (stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) { + return new PumpEnactResult().success(false).enacted(false) + .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus)); + } + + // the commands above ensured a connection was made, which updated this field + if (pumpHistoryChanged) { + return new PumpEnactResult().success(false).enacted(false) + .comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change)); + } + + Bolus previousBolus = stateResult.lastBolus != null ? stateResult.lastBolus : new Bolus(0, 0, false); + try { pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin); MainApp.bus().post(new EventComboPumpUpdateGUI()); @@ -499,21 +533,54 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter)); bolusInProgress = false; - if (bolusCmdResult.success) { - if (bolusCmdResult.delivered > 0) { - detailedBolusInfo.insulin = bolusCmdResult.delivered; - detailedBolusInfo.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); - } - return new PumpEnactResult() - .success(true) - .enacted(bolusCmdResult.delivered > 0) - .bolusDelivered(bolusCmdResult.delivered) - .carbsDelivered(detailedBolusInfo.carbs); - } else { - progressReporter.report(BolusProgressReporter.State.RECOVERING, 0, 0); - return recoverFromErrorDuringBolusDelivery(detailedBolusInfo, pumpTimeWhenBolusWasRequested); + // Note that the result of the issues the bolus command is not checked. If there was + // a connection problem, ruffyscripter tried to recover and we can just check the + // history below + + // TODO test and check error messages, they're not as fine-grained as they used to be. + // maybe they shouldn't even be, if there was an error, the user should check anyways + CommandResult postBolusStateResult = runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus); + if (!postBolusStateResult.success) { + return new PumpEnactResult().success(false).enacted(false) + .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); } + + Bolus lastBolus = postBolusStateResult.lastBolus; + if (lastBolus == null || lastBolus.equals(previousBolus)) { + return new PumpEnactResult().success(false).enacted(false) + .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); + } + + List bolusList = new ArrayList<>(1); + bolusList.add(lastBolus); + boolean pumpRecordedAdded = updateDbFromPumpHistory(new PumpHistory().bolusHistory(bolusList)); + if (!pumpRecordedAdded) { + return new PumpEnactResult().success(false).enacted(false) + .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); + + } + + return new PumpEnactResult() + .success(true) + .enacted(bolusCmdResult.delivered > 0) + .bolusDelivered(bolusCmdResult.delivered) + .carbsDelivered(detailedBolusInfo.carbs); + +// if (bolusCmdResult.success) { +// if (bolusCmdResult.delivered > 0) { +// detailedBolusInfo.insulin = bolusCmdResult.delivered; +// detailedBolusInfo.source = Source.USER; +// MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); +// } +// return new PumpEnactResult() +// .success(true) +// .enacted(bolusCmdResult.delivered > 0) +// .bolusDelivered(bolusCmdResult.delivered) +// .carbsDelivered(detailedBolusInfo.carbs); +// } else { +// progressReporter.report(BolusProgressReporter.State.RECOVERING, 0, 0); +// return recoverFromErrorDuringBolusDelivery(detailedBolusInfo, pumpTimeWhenBolusWasRequested); +// } } finally { pump.activity = null; MainApp.bus().post(new EventComboPumpUpdateGUI()); @@ -522,7 +589,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } - /** * If there was an error during BolusCommand the scripter reconnects and cleans up. The pump * refuses connections while a bolus delivery is still in progress (once bolus delivery started @@ -589,13 +655,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf cancelBolus = true; } - // Note: AAPS calls this solely to enact OpenAPS suggestions + /** Note: AAPS calls this solely to enact OpenAPS suggestions + * + * @param force the force parameter isn't used currently since we always set the tbr - + * there might be room for optimization to first test the currently running tbr + * and only change it if it differs (as the DanaR plugin does). This approach + * might have other issues though (what happens if the tbr which wasn't re-set to + * the new value (and thus still has the old duration of e.g. 1 min) expires?) + */ @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 - // first test the currently running tbr and only change it if it differs (as the DanaR plugin does). - // This approach might have other issues though (what happens if the tbr which wasn't re-set to the new value - // (and thus still has the old duration of e.g. 1 min) expires?) log.debug("setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min."); int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int roundedPercentage = (int) (Math.round(absoluteRate / getBaseBasalRate() * 10) * 10); @@ -620,6 +689,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) { log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min"); + if (pumpHistoryChanged && percent > 110) { + return new PumpEnactResult().success(false).enacted(false) + .comment("Rejecting high temp since calculation didn't consider recently changed pump history"); + } + int adjustedPercent = percent; if (adjustedPercent > pumpDescription.maxTempPercent) { @@ -763,8 +837,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } - checkForUnsafeUsage(commandResult); - return commandResult; } @@ -801,8 +873,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } + checkForUnsafeUsage(preCheckResult); checkAndResolveTbrMismatch(preCheckResult.state); checkPumpTime(preCheckResult.state); + checkHistory(); return null; } @@ -922,7 +996,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf * 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) { + private boolean readHistory(@Nullable PumpHistoryRequest request) { CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(request)); if (!historyResult.success) { return false; @@ -942,38 +1016,36 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return historyResult.success; } - private synchronized void updateDbFromPumpHistory(@NonNull PumpHistory history) { - DatabaseHelper dbHelper = MainApp.getDbHelper(); - // boluses + private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) { + boolean updated = false; + // Bolus for (Bolus pumpBolus : history.bolusHistory) { - Treatment aapsBolus = dbHelper.getTreatmentByDate(pumpBolus.timestamp); - if (aapsBolus == null) { - log.debug("Creating bolus record from pump bolus: " + pumpBolus); - DetailedBolusInfo dbi = new DetailedBolusInfo(); - dbi.date = pumpBolus.timestamp; - dbi.pumpId = pumpBolus.timestamp; - dbi.source = Source.PUMP; - dbi.insulin = pumpBolus.amount; - dbi.eventType = CareportalEvent.CORRECTIONBOLUS; - MainApp.getConfigBuilder().addToHistoryTreatment(dbi); + DetailedBolusInfo dbi = new DetailedBolusInfo(); + dbi.date = pumpBolus.timestamp; + dbi.pumpId = pumpBolus.timestamp + ((int) pumpBolus.amount * 10); + dbi.source = Source.PUMP; + dbi.insulin = pumpBolus.amount; + dbi.eventType = CareportalEvent.CORRECTIONBOLUS; + if (MainApp.getConfigBuilder().addToHistoryTreatment(dbi)) { + updated = true; } } // TBRs for (Tbr pumpTbr : history.tbrHistory) { - TemporaryBasal aapsTbr = dbHelper.getTemporaryBasalsDataByDate(pumpTbr.timestamp); - if (aapsTbr == null) { - log.debug("Creating TBR from pump TBR: " + pumpTbr); - TemporaryBasal temporaryBasal = new TemporaryBasal(); - temporaryBasal.date = pumpTbr.timestamp; - temporaryBasal.pumpId = pumpTbr.timestamp; - temporaryBasal.source = Source.PUMP; - temporaryBasal.percentRate = pumpTbr.percent; - temporaryBasal.durationInMinutes = pumpTbr.duration; - temporaryBasal.isAbsolute = false; - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TemporaryBasal temporaryBasal = new TemporaryBasal(); + temporaryBasal.date = pumpTbr.timestamp; + temporaryBasal.pumpId = pumpTbr.timestamp + pumpTbr.percent; + temporaryBasal.source = Source.PUMP; + temporaryBasal.percentRate = pumpTbr.percent; + temporaryBasal.durationInMinutes = pumpTbr.duration; + temporaryBasal.isAbsolute = false; + if (MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal)) { + updated = true; } } + + return updated; } // TODO queue @@ -990,37 +1062,40 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // TODO queue void readAllPumpData() { - long lastCheckInitiated = System.currentTimeMillis(); - - boolean readHistorySuccess = readHistory(new PumpHistoryRequest() - .bolusHistory(pumpHistoryLastChecked) - .tbrHistory(pumpHistoryLastChecked) + readHistory(new PumpHistoryRequest() + .bolusHistory(PumpHistoryRequest.FULL) + .tbrHistory(PumpHistoryRequest.FULL) .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(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); - if (!basalResult.success) { - return; - } - - pump.basalProfile = basalResult.basalProfile; - + .tddHistory(PumpHistoryRequest.FULL) + ); + runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); ruffyScripter.disconnect(); } + private void checkHistory() { + long start = System.currentTimeMillis(); +// long lastCheckInitiated = System.currentTimeMillis(); + + CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> + ruffyScripter.readHistory(new PumpHistoryRequest() + .bolusHistory(timestampOfLastKnownBolusRecord) + // TODO TBR history will almost always produce changes +// .tbrHistory(pumpHistoryLastChecked)) + )); + if (!historyResult.success) { + return; + } + + pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history); + + if (!historyResult.history.bolusHistory.isEmpty()) { + timestampOfLastKnownBolusRecord = historyResult.history.bolusHistory.get(0).timestamp; + } +// pumpHistoryLastChecked = lastCheckInitiated; + long end = System.currentTimeMillis(); + log.debug("History check took: " + ((end - start) / 1000) + "s"); + } + @Override public PumpEnactResult cancelExtendedBolus() { return OPERATION_NOT_SUPPORTED; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 45d34c5172..83aa616621 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -854,6 +854,7 @@ Pump clock update needed History Warning + Long press this button to (re)read all history data and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time was significantly off or the basal profile was changed on the pump (which should never be done under normal circumstances). This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed @@ -865,5 +866,6 @@ Extended bolus delivery error %.2f U/h Reading basal profile + The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested within the same minute for saftery (regardless of whether they were administered or not). diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java index cb2bec0891..8ba6c18d81 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java @@ -60,47 +60,51 @@ public class ReadHistoryCommand extends BaseCommand { } } - // error history - scripter.pressMenuKey(); - scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA); - if (request.pumpErrorHistory != PumpHistoryRequest.SKIP) { - int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); - if (totalRecords > 0) { - if (request.pumpErrorHistory == PumpHistoryRequest.LAST) { - PumpAlert error = readAlertRecord(); - history.pumpAlertHistory.add(error); - } else { - readAlertRecords(request.pumpErrorHistory); + if (request.pumpErrorHistory == PumpHistoryRequest.SKIP + && request.tddHistory == PumpHistoryRequest.SKIP + && request.tbrHistory == PumpHistoryRequest.SKIP) { + // error history + scripter.pressMenuKey(); + scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA); + if (request.pumpErrorHistory != PumpHistoryRequest.SKIP) { + int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); + if (totalRecords > 0) { + if (request.pumpErrorHistory == PumpHistoryRequest.LAST) { + PumpAlert error = readAlertRecord(); + history.pumpAlertHistory.add(error); + } else { + readAlertRecords(request.pumpErrorHistory); + } } } - } - // tdd history - scripter.pressMenuKey(); - scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA); - if (request.tddHistory != PumpHistoryRequest.SKIP) { - int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); - if (totalRecords > 0) { - if (request.tddHistory == PumpHistoryRequest.LAST) { - Tdd tdd = readTddRecord(); - history.tddHistory.add(tdd); - } else { - readTddRecords(request.tbrHistory); + // tdd history + scripter.pressMenuKey(); + scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA); + if (request.tddHistory != PumpHistoryRequest.SKIP) { + int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); + if (totalRecords > 0) { + if (request.tddHistory == PumpHistoryRequest.LAST) { + Tdd tdd = readTddRecord(); + history.tddHistory.add(tdd); + } else { + readTddRecords(request.tbrHistory); + } } } - } - // tbr history - scripter.pressMenuKey(); - scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA); - if (request.tbrHistory != PumpHistoryRequest.SKIP) { - int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); - if (totalRecords > 0) { - if (request.tbrHistory == PumpHistoryRequest.LAST) { - Tbr tbr = readTbrRecord(); - history.tbrHistory.add(tbr); - } else { - readTbrRecords(request.tbrHistory); + // tbr history + scripter.pressMenuKey(); + scripter.verifyMenuIsDisplayed(MenuType.TBR_DATA); + if (request.tbrHistory != PumpHistoryRequest.SKIP) { + int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); + if (totalRecords > 0) { + if (request.tbrHistory == PumpHistoryRequest.LAST) { + Tbr tbr = readTbrRecord(); + history.tbrHistory.add(tbr); + } else { + readTbrRecords(request.tbrHistory); + } } } } From 5de588b540a5accb2f7edbcd64aad9025b196cdc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 20 Jan 2018 15:25:06 +0100 Subject: [PATCH 02/54] Enable reading reservoir level units. This partially reverts commit b4998feee11d63418ed1ce288eed7a820529e723. --- .../androidaps/plugins/PumpCombo/ComboFragment.java | 6 +++--- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 13 +++++++++---- .../androidaps/plugins/PumpCombo/ComboPump.java | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 6abb40dcec..ee023e23cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -164,17 +164,17 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis } // reservoir + int reservoirLevel = plugin.getPump().reservoirLevel; + reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " " + + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); if (ps.insulinState == PumpState.LOW) { reservoirView.setTextColor(Color.YELLOW); - reservoirView.setText(R.string.combo_reservoir_low); reservoirView.setTypeface(null, Typeface.BOLD); } else if (ps.insulinState == PumpState.EMPTY) { reservoirView.setTextColor(Color.RED); - reservoirView.setText(R.string.combo_reservoir_empty); reservoirView.setTypeface(null, Typeface.BOLD); } else { reservoirView.setTextColor(Color.WHITE); - reservoirView.setText(R.string.combo_reservoir_normal); reservoirView.setTypeface(null, Typeface.NORMAL); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index f960312235..3f5075b007 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -354,7 +354,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!pump.initialized) { initializePump(); } else { - runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState); + runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readReservoirLevelAndLastBolus); // note that since the history is checked upon every connect, the above already updated // the DB with any changed history records } @@ -406,10 +406,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf MainApp.bus().post(new EventInitializationChanged()); // ComboFragment updates state fully only after the pump has initialized, so read full state here - updateLocalData(readBasalResult); + updateLocalData(runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus)); } private void updateLocalData(CommandResult result) { + if (result.reservoirLevel != PumpState.UNKNOWN) { + pump.reservoirLevel = result.reservoirLevel; + } if (result.state.menu != null) { pump.state = result.state; } @@ -1111,9 +1114,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf JSONObject pumpJson = new JSONObject(); pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime)); - int level = 150; - if (pump.state.insulinState == PumpState.LOW) level = 8; + int level; + if (pump.reservoirLevel != -1) level = pump.reservoirLevel; + else if (pump.state.insulinState == PumpState.LOW) level = 8; else if (pump.state.insulinState == PumpState.EMPTY) level = 0; + else level = 150; pumpJson.put("reservoir", level); JSONObject statusJson = new JSONObject(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 5980cf11eb..0455fa3ada 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -17,6 +17,7 @@ class ComboPump { public volatile String activity; @NonNull volatile PumpState state = new PumpState(); + volatile int reservoirLevel = -1; @NonNull volatile BasalProfile basalProfile = new BasalProfile(); From e3abe0454533aee97f6c24833eb252d01dd74a5f Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 20 Jan 2018 20:13:08 +0100 Subject: [PATCH 03/54] Bring back last bolus to combo fragment. (cherry picked from commit 108349e) --- .../plugins/PumpCombo/ComboFragment.java | 25 +++++++++++++++++++ .../plugins/PumpCombo/ComboPlugin.java | 5 ++++ .../plugins/PumpCombo/ComboPump.java | 4 +++ .../main/res/layout/combopump_fragment.xml | 2 -- .../jotomo/ruffyscripter/RuffyScripter.java | 2 +- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index ee023e23cc..e1b5bdd92f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -15,6 +15,7 @@ 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.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; @@ -29,6 +30,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis private TextView batteryView; private TextView reservoirView; private TextView lastConnectionView; + private TextView lastBolusView; private TextView baseBasalRate; private TextView tempBasalText; private Button refreshButton; @@ -45,6 +47,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis activityView = (TextView) view.findViewById(R.id.combo_activity); batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery); reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate); + lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus); lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection); baseBasalRate = (TextView) view.findViewById(R.id.combo_base_basal_rate); tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal); @@ -192,6 +195,28 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis lastConnectionView.setTextColor(Color.WHITE); } + // last bolus + Bolus bolus = plugin.getPump().lastBolus; + if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { + long agoMsc = System.currentTimeMillis() - bolus.timestamp; + double bolusMinAgo = agoMsc / 60d / 1000d; + double bolusHoursAgo = agoMsc / 60d / 60d / 1000d; + // TODO i18n + if ((agoMsc < 60 * 1000)) { + lastBolusView.setText(String.format("%.1f U (now)", bolus.amount)); + } else if (bolusMinAgo < 60) { + lastBolusView.setText(String.format("%.1f U (%d min ago)", bolus.amount, (int) bolusMinAgo)); +// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, +// getString(R.string.minago, bolusMinAgo), DateUtil.timeString(bolus.timestamp))); + } else { + lastBolusView.setText(String.format("%.1f U (%.1f h ago)", bolus.amount, bolusHoursAgo)); +// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, +// String.format("%.1f", bolusHoursAgo) + getString(R.string.hoursago), DateUtil.timeString(bolus.timestamp))); + } + } else { + lastBolusView.setText(""); + } + // base basal rate baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 3f5075b007..812aa1d753 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -413,6 +413,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf 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; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 0455fa3ada..3aa4137b8b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -1,12 +1,14 @@ 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.PumpState; +import de.jotomo.ruffy.spi.history.Bolus; import de.jotomo.ruffy.spi.history.PumpAlert; import de.jotomo.ruffy.spi.history.Tdd; @@ -20,6 +22,8 @@ class ComboPump { volatile int reservoirLevel = -1; @NonNull volatile BasalProfile basalProfile = new BasalProfile(); + @Nullable + volatile Bolus lastBolus; // Alert and TDD histories are not stored in DB, but are read on demand and just cached here List errorHistory = new ArrayList<>(0); diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index 54e3e2f3d1..29d8659d53 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -236,7 +236,6 @@ - Date: Sun, 28 Jan 2018 15:38:54 +0100 Subject: [PATCH 04/54] ComboFragment: deal with resevoir levels being available or not. --- .../plugins/PumpCombo/ComboFragment.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index e1b5bdd92f..e5989e4ecd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -168,9 +168,20 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis // reservoir int reservoirLevel = plugin.getPump().reservoirLevel; - reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " " - + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); - if (ps.insulinState == PumpState.LOW) { + if (reservoirLevel != -1) { + reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); + } else if (ps.insulinState == PumpState.LOW) { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low)); + } else if (ps.insulinState == PumpState.EMPTY) { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty)); + } else { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal)); + } + + if (ps.insulinState == PumpState.UNKNOWN) { + reservoirView.setTextColor(Color.WHITE); + reservoirView.setTypeface(null, Typeface.NORMAL); + } else if (ps.insulinState == PumpState.LOW) { reservoirView.setTextColor(Color.YELLOW); reservoirView.setTypeface(null, Typeface.BOLD); } else if (ps.insulinState == PumpState.EMPTY) { From 1bbc6d24c7978fcb7d592e50fb279e8f913d634b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 15:45:57 +0100 Subject: [PATCH 05/54] RuffyScripter: add toggle to avoid reading the quick info menu. --- .../main/java/de/jotomo/ruffyscripter/RuffyScripter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index c8b817aaae..aa748e031c 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -51,6 +51,8 @@ import de.jotomo.ruffyscripter.commands.SetTbrCommand; * operations and are cleanly separated from the thread management, connection management etc */ public class RuffyScripter implements RuffyCommands { + private final boolean readQuickInfoMenu = true; + private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class); private IRuffyService ruffyService; @@ -215,7 +217,10 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult readReservoirLevelAndLastBolus() { - return runCommand(new ReadReservoirLevelAndLastBolus()); + if (readQuickInfoMenu) { + return runCommand(new ReadReservoirLevelAndLastBolus()); + } + return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); } public void returnToRootMenu() { From 8c27b32d078db87c7e5e7ee044d811cba31aee95 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 15:46:12 +0100 Subject: [PATCH 06/54] Let "Initializing" be a pump state, not an action. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 6 ++---- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 812aa1d753..55198e4599 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -36,10 +36,8 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.ConstraintsInterface; @@ -159,7 +157,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf ? "E" + ps.activeAlert.errorCode + ": " + ps.activeAlert.message : "W" + ps.activeAlert.warningCode + ": " + ps.activeAlert.message; } else if (ps.menu == null) - return MainApp.gs(R.string.combo_pump_state_disconnected); + return MainApp.gs(R.string.combo_pump_state_initializing); else if (ps.suspended && (ps.batteryState == PumpState.EMPTY || ps.insulinState == PumpState.EMPTY)) return MainApp.gs(R.string.combo_pump_state_suspended_due_to_error); else if (ps.suspended) @@ -373,7 +371,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } - CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_initializing),1, ruffyScripter::readPumpState); + CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing),1, ruffyScripter::readPumpState); if (!stateResult.success) { return; } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7c033bc908..794675c887 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -736,7 +736,7 @@ Wegen eines Fehlers wurden nur %.2f IE von den angeforderten %.2f IE abgegeben. Bitte prüfe den abgegebenen Bolus auf der Pumpe. Historie Status wird aktualisiert - Die Pumpe wird initialisiert + Die Pumpe wird initialisiert Jetzt Nie Der Alarm \"TBR ABBRUCH\" wurde bestätigt diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 39af5b8c6c..ca434cc35a 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -743,7 +743,7 @@ Geen verbinding gedurende %d minuten %d%% (%d min resterend) %.1f E (%s, %s) - Initialiseren + Initialiseren Verbinding verbroken Herstel van verbroken verbindng Waarschuwing diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83aa616621..14005716f8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -821,7 +821,7 @@ No connection for %d min %d%% (%d min remaining) %.1f U (%s, %s) - Initializing + Initializing Disconnected Suspended due to error Suspended by user From 3a95c3c4d932bb0fa2bf85c6ebe86659644a7a0b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 17:06:01 +0100 Subject: [PATCH 07/54] More work for bolusing with pump history records. (cherry picked from commit 4bc3e42) --- .../plugins/PumpCombo/ComboPlugin.java | 112 ++++-------------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 22 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 55198e4599..94f9cebda7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -498,9 +498,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.bolus_frequency_exceeded)); } - // TODO only check this after a bolus was successfully applied? NO, because in error condition - // we can't say with certainty if a bolus was delivered (we find out when refreshing history next) - // so, be on the annoying but safe side lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true); CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus); @@ -535,7 +532,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // start bolus delivery bolusInProgress = true; - CommandResult bolusCmdResult = runCommand(null, 0, + runCommand(null, 0, () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter)); bolusInProgress = false; @@ -543,9 +540,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // a connection problem, ruffyscripter tried to recover and we can just check the // history below - // TODO test and check error messages, they're not as fine-grained as they used to be. - // maybe they shouldn't even be, if there was an error, the user should check anyways - CommandResult postBolusStateResult = runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus); + CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); @@ -554,105 +549,38 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf Bolus lastBolus = postBolusStateResult.lastBolus; if (lastBolus == null || lastBolus.equals(previousBolus)) { return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); + .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); } - List bolusList = new ArrayList<>(1); - bolusList.add(lastBolus); - boolean pumpRecordedAdded = updateDbFromPumpHistory(new PumpHistory().bolusHistory(bolusList)); - if (!pumpRecordedAdded) { - return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); + if (Math.abs(lastBolus.amount - detailedBolusInfo.insulin) > 0.01) { + return new PumpEnactResult().success(false).enacted(true) + .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered)); + } + // seems we actually made it ... + detailedBolusInfo.date = lastBolus.timestamp; + detailedBolusInfo.pumpId = lastBolus.timestamp + ((int) lastBolus.amount * 10); + detailedBolusInfo.source = Source.PUMP; + detailedBolusInfo.insulin = lastBolus.amount; + boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + if (!treatmentCreated) { + return new PumpEnactResult().success(false).enacted(true) + .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); } return new PumpEnactResult() .success(true) - .enacted(bolusCmdResult.delivered > 0) - .bolusDelivered(bolusCmdResult.delivered) + .enacted(lastBolus.amount > 0) + .bolusDelivered(lastBolus.amount) .carbsDelivered(detailedBolusInfo.carbs); - -// if (bolusCmdResult.success) { -// if (bolusCmdResult.delivered > 0) { -// detailedBolusInfo.insulin = bolusCmdResult.delivered; -// detailedBolusInfo.source = Source.USER; -// MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); -// } -// return new PumpEnactResult() -// .success(true) -// .enacted(bolusCmdResult.delivered > 0) -// .bolusDelivered(bolusCmdResult.delivered) -// .carbsDelivered(detailedBolusInfo.carbs); -// } else { -// progressReporter.report(BolusProgressReporter.State.RECOVERING, 0, 0); -// return recoverFromErrorDuringBolusDelivery(detailedBolusInfo, pumpTimeWhenBolusWasRequested); -// } } finally { pump.activity = null; MainApp.bus().post(new EventComboPumpUpdateGUI()); - MainApp.bus().post(new EventRefreshOverview("Combo Bolus")); + MainApp.bus().post(new EventRefreshOverview("Bolus")); cancelBolus = false; } } - /** - * If there was an error during BolusCommand the scripter reconnects and cleans up. The pump - * refuses connections while a bolus delivery is still in progress (once bolus delivery started - * it continues regardless of a connection loss). - * Then verify the bolus record we read has a date which is >= the time the bolus was requested - * (using the pump's time!). If there is such a bolus with <= the requested amount, then it's - * from this command and shall be added to treatments. If the bolus wasn't delivered in full, - * add it to treatments but raise a warning. Raise a warning as well if no bolus was delivered - * at all. - * This all still might fail for very large boluses and earthquakes in which case an error - * is raised asking to user to deal with it. - */ - private PumpEnactResult recoverFromErrorDuringBolusDelivery(DetailedBolusInfo detailedBolusInfo, long pumpTimeWhenBolusWasRequested) { - log.debug("Trying to determine from pump history what was actually delivered"); - CommandResult readLastBolusResult = runCommand(null , 2, - () -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); - if (!readLastBolusResult.success || readLastBolusResult.history == null) { - // this happens when the cartridge runs empty during delivery, the pump will be in an error - // state with multiple alarms ringing and no chance of reading history - return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); - } - - List bolusHistory = readLastBolusResult.history.bolusHistory; - Bolus lastBolus = !bolusHistory.isEmpty() ? bolusHistory.get(0) : null; - log.debug("Last bolus read from history: " + lastBolus + ", request time: " + - pumpTimeWhenBolusWasRequested + " (" + new Date(pumpTimeWhenBolusWasRequested) + ")"); - - if (lastBolus == null // no bolus ever given - || lastBolus.timestamp < pumpTimeWhenBolusWasRequested // this is not the bolus you're looking for - || lastBolus.amount - detailedBolusInfo.insulin > 0.01 // this one neither, big than requested bolus - || !lastBolus.isValid) { // ext/multiwave bolus - log.debug("No bolus was delivered"); - return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); - } else if (Math.abs(lastBolus.amount - detailedBolusInfo.insulin) > 0.01) { // bolus only partially delivered - double requestedBolus = detailedBolusInfo.insulin; - - detailedBolusInfo.insulin = lastBolus.amount; - detailedBolusInfo.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); - log.debug(String.format(Locale.getDefault(), "Added partial bolus of %.2f to treatments (requested: %.2f)", lastBolus.amount, requestedBolus)); - - return new PumpEnactResult().success(false).enacted(true) - .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered, - lastBolus.amount, requestedBolus)); - } else { - // bolus was correctly and fully delivered - detailedBolusInfo.insulin = lastBolus.amount; - detailedBolusInfo.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); - log.debug("Added correctly delivered bolus to treatments"); - return new PumpEnactResult().success(true).enacted(true) - .bolusDelivered(lastBolus.amount) - .carbsDelivered(detailedBolusInfo.carbs); - } - } - @Override public void stopBolusDelivering() { if (bolusInProgress) { @@ -1080,6 +1008,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private void checkHistory() { long start = System.currentTimeMillis(); + // TODO optimize for the default case where no new records exists by checking quick info; + // and only read My Data history when quick info shows a new record // long lastCheckInitiated = System.currentTimeMillis(); CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14005716f8..647b3aed13 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -867,5 +867,6 @@ %.2f U/h Reading basal profile The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested within the same minute for saftery (regardless of whether they were administered or not). + Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the same minute. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute. From bd87a893c24e252253322c31f9a0755fb6135611 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 18:58:06 +0100 Subject: [PATCH 08/54] Best effort to handle multiple boluses within the same minute. (cherry picked from commit cc9094f) --- .../plugins/PumpCombo/ComboPlugin.java | 16 +++++++++------- app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 94f9cebda7..480d29602c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -490,10 +490,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf @NonNull private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) { - // guard against boluses issued multiple times within a minute + // Guard against boluses issued multiple times within two minutes. + // Two minutes, so that the resulting timestamp and bolus are different with the Combo + // history records which only store with minute-precision if (lastRequestedBolus != null && Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01 - && lastRequestedBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) { + && lastRequestedBolus.timestamp + 120 * 1000 > System.currentTimeMillis()) { log.error("Bolus delivery failure at stage 0", new Exception()); return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.bolus_frequency_exceeded)); @@ -557,9 +559,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered)); } - // seems we actually made it ... - detailedBolusInfo.date = lastBolus.timestamp; - detailedBolusInfo.pumpId = lastBolus.timestamp + ((int) lastBolus.amount * 10); + // seems we actually made it this far, let's add a treatment record + detailedBolusInfo.date = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000)); + detailedBolusInfo.pumpId = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000)); detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.insulin = lastBolus.amount; boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); @@ -955,8 +957,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // Bolus for (Bolus pumpBolus : history.bolusHistory) { DetailedBolusInfo dbi = new DetailedBolusInfo(); - dbi.date = pumpBolus.timestamp; - dbi.pumpId = pumpBolus.timestamp + ((int) pumpBolus.amount * 10); + dbi.date = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000)); + dbi.pumpId = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000)); dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; dbi.eventType = CareportalEvent.CORRECTIONBOLUS; diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 794675c887..3ff98e2520 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -780,4 +780,6 @@ Achtung! Normalerweise musst Du diese Werte nicht ändern. Bitte KLICKE HIER und LESE den Text. Verändere Werte erst, wenn Du den Inhalt des Textes verstanden hast. %.2f IE/h Basalratenprofil wird gelesen + %.2f IE/h + Dringender Alarm diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 988a92928d..aa59862b20 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -229,7 +229,7 @@ Esperando resultado Números de teléfono permitidos XXXXXXXXXX +; + YYYYYYYYYY - Para entregar bolo% .2fU responder con código% s + Para entregar bolo %.2fU responder con código% s Bolo falló Bolo %.2fU entregado con éxito Entregando %.2fU diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 647b3aed13..ca7dce0430 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -866,7 +866,7 @@ Extended bolus delivery error %.2f U/h Reading basal profile - The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested within the same minute for saftery (regardless of whether they were administered or not). - Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the same minute. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute. + The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested with less than tow minutes between them for safety (regardless of whether they were administered or not). + Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the last two minutes. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute and same amount. From 3b7045227e56548f188637780a490f2e5c62b8c5 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 19:04:46 +0100 Subject: [PATCH 09/54] Only check reservoir level before bolus if data is available. --- .../nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 480d29602c..68056d5d55 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -509,7 +509,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); } - if (stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) { + if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus)); } From 9ba6f2144bd47ec5630a0a02792c87327984dd0e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 19:30:59 +0100 Subject: [PATCH 10/54] Strings fix-up. --- app/src/main/res/values-de/strings.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 3ff98e2520..13e2c34d65 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -778,8 +778,6 @@ Standarwert: 2\nBolus snooze (\"Bolus-Schlummer\") bremst den Loop nach einem Mahleiten-Bolus, damit dieser nicht mit niedrigen TBR reagiert, wenn Du gerade gegessen hast. Beispiel: Der Standardwert 2 bewirkt, dass bei einem 3 Stunden DIA der Bolus snooze während 1.5 Stunden nach dem Bolus linear ausläuft (3 h Dia / 2 = 1.5 h Bolus snooze). Standardwert: 3.0\nDies ist eine Einstellung für die Standard-Kohlenhydrat-Absorptionswirkung pro 5 Minuten. Der Standardwert ist 3mg/dl/5min. Dies wirkt sich darauf aus, wie schnell der COB-Wert fällt und wieviel KH-Absorption bei der Berechnung des vorhergesagten BZ angenommen wird, wenn der BZ stärker als erwartet fällt oder nicht so stark wie erwartet steigt. Achtung! Normalerweise musst Du diese Werte nicht ändern. Bitte KLICKE HIER und LESE den Text. Verändere Werte erst, wenn Du den Inhalt des Textes verstanden hast. - %.2f IE/h Basalratenprofil wird gelesen %.2f IE/h - Dringender Alarm From 302d3494d277f509524ce9c432d5a481657f31f5 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 19:49:40 +0100 Subject: [PATCH 11/54] Covering 105% of all failure cases. --- .../plugins/PumpCombo/ComboPlugin.java | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 68056d5d55..897c51a0cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -560,12 +560,28 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } // seems we actually made it this far, let's add a treatment record - detailedBolusInfo.date = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000)); - detailedBolusInfo.pumpId = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000)); + detailedBolusInfo.date = calculateFakeBolusDate(lastBolus); + detailedBolusInfo.pumpId = calculateFakeBolusDate(lastBolus); detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.insulin = lastBolus.amount; - boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); - if (!treatmentCreated) { + try { + boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + if (!treatmentCreated) { + if (detailedBolusInfo.isSMB) { + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + return new PumpEnactResult().success(false).enacted(true) + .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); + } + return new PumpEnactResult().success(false).enacted(true) + .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); + } + } catch (Exception e) { + log.error("Adding treatment record failed", e); + if (detailedBolusInfo.isSMB) { + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } return new PumpEnactResult().success(false).enacted(true) .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); } @@ -957,8 +973,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // Bolus for (Bolus pumpBolus : history.bolusHistory) { DetailedBolusInfo dbi = new DetailedBolusInfo(); - dbi.date = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000)); - dbi.pumpId = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000)); + dbi.date = calculateFakeBolusDate(pumpBolus); + dbi.pumpId = calculateFakeBolusDate(pumpBolus); dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; dbi.eventType = CareportalEvent.CORRECTIONBOLUS; @@ -984,6 +1000,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return updated; } + /** Adds the bolus to the timestamp to be able to differentiate multiple boluses in the same + * minute. Best effort, since this covers only boluses up to 5.9 U and relies on other code + * to prevent a boluses with the same amount to be delivered within the same minute. + * Should be good enough, even with command mode, it's a challenge to create that situation + * and most time clashes will be around SMBs which are covered. + */ + private long calculateFakeBolusDate(Bolus pumpBolus) { + return pumpBolus.timestamp + (Math.min((int) (pumpBolus.amount - 0.1) * 10 * 1000, 59 * 1000)); + } + // TODO queue void readTddData() { readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)); @@ -1010,16 +1036,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private void checkHistory() { long start = System.currentTimeMillis(); - // TODO optimize for the default case where no new records exists by checking quick info; - // and only read My Data history when quick info shows a new record -// long lastCheckInitiated = System.currentTimeMillis(); + // TODO maybe optimize for the default case where no new records exists by checking quick info; + // and only read My Data history when quick info shows a new record CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(new PumpHistoryRequest() - .bolusHistory(timestampOfLastKnownBolusRecord) - // TODO TBR history will almost always produce changes -// .tbrHistory(pumpHistoryLastChecked)) - )); + .bolusHistory(timestampOfLastKnownBolusRecord))); if (!historyResult.success) { return; } @@ -1029,7 +1051,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!historyResult.history.bolusHistory.isEmpty()) { timestampOfLastKnownBolusRecord = historyResult.history.bolusHistory.get(0).timestamp; } -// pumpHistoryLastChecked = lastCheckInitiated; + long end = System.currentTimeMillis(); log.debug("History check took: " + ((end - start) / 1000) + "s"); } From 6609eb6be580f8f679fe244a0f598e5a07efc748 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 21:56:56 +0100 Subject: [PATCH 12/54] Cleanup. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 897c51a0cc..7128236d95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -4,18 +4,12 @@ import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.crashlytics.android.answers.Answers; -import com.crashlytics.android.answers.CustomEvent; - import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; -import java.util.Locale; import de.jotomo.ruffy.spi.BasalProfile; import de.jotomo.ruffy.spi.BolusProgressReporter; @@ -103,12 +97,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private volatile boolean cancelBolus; private Bolus lastRequestedBolus; -// private long pumpHistoryLastChecked; - private volatile long timestampOfLastKnownBolusRecord; /** this is set whenever a connection to the pump is made and indicates if new history records on the pump have been found */ private volatile boolean pumpHistoryChanged = false; + private volatile long timestampOfLastKnownPumpBolusRecord; public static ComboPlugin getPlugin() { if (plugin == null) @@ -1041,7 +1034,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // and only read My Data history when quick info shows a new record CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(new PumpHistoryRequest() - .bolusHistory(timestampOfLastKnownBolusRecord))); + .bolusHistory(timestampOfLastKnownPumpBolusRecord))); if (!historyResult.success) { return; } @@ -1049,7 +1042,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history); if (!historyResult.history.bolusHistory.isEmpty()) { - timestampOfLastKnownBolusRecord = historyResult.history.bolusHistory.get(0).timestamp; + timestampOfLastKnownPumpBolusRecord = historyResult.history.bolusHistory.get(0).timestamp; } long end = System.currentTimeMillis(); From 34af5bc20bb1444d807c81a539131ea3bde0c630 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:03:32 +0100 Subject: [PATCH 13/54] Source code from ruffyscripter, ruffy-spi modules. --- app/build.gradle | 1 - .../d/ruffy/ruffy/driver/IRTHandler.aidl | 0 .../d/ruffy/ruffy/driver/IRuffyService.aidl | 0 .../d/ruffy/ruffy/driver/display/Menu.aidl | 0 .../d/ruffy/ruffy/driver/package-info.java | 0 .../de/jotomo/ruffy/spi/BasalProfile.java | 0 .../ruffy/spi/BolusProgressReporter.java | 0 .../de/jotomo/ruffy/spi/CommandResult.java | 0 .../de/jotomo/ruffy/spi/PumpErrorCodes.java | 0 .../java/de/jotomo/ruffy/spi/PumpState.java | 0 .../de/jotomo/ruffy/spi/PumpWarningCodes.java | 0 .../de/jotomo/ruffy/spi/RuffyCommands.java | 0 .../jotomo/ruffy/spi/WarningOrErrorCode.java | 0 .../de/jotomo/ruffy/spi/history/Bolus.java | 0 .../ruffy/spi/history/HistoryRecord.java | 0 .../jotomo/ruffy/spi/history/PumpAlert.java | 0 .../jotomo/ruffy/spi/history/PumpHistory.java | 0 .../ruffy/spi/history/PumpHistoryRequest.java | 0 .../java/de/jotomo/ruffy/spi/history/Tbr.java | 0 .../java/de/jotomo/ruffy/spi/history/Tdd.java | 0 .../ruffyscripter/RuffyCommandsV1Impl.java | 0 .../jotomo/ruffyscripter/RuffyScripter.java | 0 .../ruffyscripter/commands/BaseCommand.java | 0 .../ruffyscripter/commands/BolusCommand.java | 0 .../commands/CancelTbrCommand.java | 0 .../ruffyscripter/commands/Command.java | 0 .../commands/CommandException.java | 0 .../commands/ConfirmAlertCommand.java | 0 .../commands/ReadBasalProfileCommand.java | 0 .../commands/ReadHistoryCommand.java | 0 .../commands/ReadPumpStateCommand.java | 0 .../ReadReservoirLevelAndLastBolus.java | 0 .../commands/SetBasalProfileCommand.java | 0 .../ruffyscripter/commands/SetTbrCommand.java | 0 .../d/ruffy/ruffy/driver/display/Menu.java | 0 .../ruffy/driver/display/MenuAttribute.java | 0 .../ruffy/ruffy/driver/display/MenuType.java | 0 .../ruffy/driver/display/menu/BolusType.java | 0 .../ruffy/driver/display/menu/MenuBlink.java | 0 .../ruffy/driver/display/menu/MenuDate.java | 0 .../ruffy/driver/display/menu/MenuTime.java | 0 ruffy-spi/.gitignore | 1 - ruffy-spi/build.gradle | 32 ----------------- ruffy-spi/proguard-rules.pro | 25 ------------- ruffy-spi/src/main/AndroidManifest.xml | 3 -- ruffyscripter/.gitignore | 1 - ruffyscripter/build.gradle | 35 ------------------- ruffyscripter/proguard-rules.pro | 25 ------------- ruffyscripter/src/main/AndroidManifest.xml | 7 ---- settings.gradle | 2 +- 50 files changed, 1 insertion(+), 131 deletions(-) rename {ruffyscripter => app}/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRTHandler.aidl (100%) rename {ruffyscripter => app}/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRuffyService.aidl (100%) rename {ruffyscripter => app}/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/display/Menu.aidl (100%) rename {ruffyscripter => app}/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/package-info.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/CommandResult.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/PumpState.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java (100%) rename {ruffy-spi => app}/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/Command.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java (100%) rename {ruffyscripter => app}/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/Menu.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuAttribute.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuType.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/BolusType.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuBlink.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuDate.java (100%) rename {ruffyscripter => app}/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuTime.java (100%) delete mode 100644 ruffy-spi/.gitignore delete mode 100644 ruffy-spi/build.gradle delete mode 100644 ruffy-spi/proguard-rules.pro delete mode 100644 ruffy-spi/src/main/AndroidManifest.xml delete mode 100644 ruffyscripter/.gitignore delete mode 100644 ruffyscripter/build.gradle delete mode 100644 ruffyscripter/proguard-rules.pro delete mode 100644 ruffyscripter/src/main/AndroidManifest.xml diff --git a/app/build.gradle b/app/build.gradle index 67bac2b736..e1a030130c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -175,7 +175,6 @@ allprojects { dependencies { wearApp project(':wear') - compile project(path: ':ruffyscripter') compile fileTree(include: ['*.jar'], dir: 'libs') compile("com.crashlytics.sdk.android:crashlytics:2.6.7@aar") { diff --git a/ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRTHandler.aidl b/app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRTHandler.aidl similarity index 100% rename from ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRTHandler.aidl rename to app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRTHandler.aidl diff --git a/ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRuffyService.aidl b/app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRuffyService.aidl similarity index 100% rename from ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRuffyService.aidl rename to app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/IRuffyService.aidl diff --git a/ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/display/Menu.aidl b/app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/display/Menu.aidl similarity index 100% rename from ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/display/Menu.aidl rename to app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/display/Menu.aidl diff --git a/ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/package-info.java b/app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/package-info.java similarity index 100% rename from ruffyscripter/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/package-info.java rename to app/src/main/aidl/org/monkey/d/ruffy/ruffy/driver/package-info.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java b/app/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java rename to app/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java b/app/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java rename to app/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java b/app/src/main/java/de/jotomo/ruffy/spi/CommandResult.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java rename to app/src/main/java/de/jotomo/ruffy/spi/CommandResult.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java b/app/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java rename to app/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java b/app/src/main/java/de/jotomo/ruffy/spi/PumpState.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java rename to app/src/main/java/de/jotomo/ruffy/spi/PumpState.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java b/app/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java rename to app/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java b/app/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java rename to app/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java b/app/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java rename to app/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java b/app/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java b/app/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java b/app/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java b/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java b/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java b/app/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java b/app/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java similarity index 100% rename from ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java rename to app/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java rename to app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java rename to app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java similarity index 100% rename from ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java rename to app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/Menu.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/Menu.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/Menu.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/Menu.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuAttribute.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuAttribute.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuAttribute.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuAttribute.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuType.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuType.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuType.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/MenuType.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/BolusType.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/BolusType.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/BolusType.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/BolusType.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuBlink.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuBlink.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuBlink.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuBlink.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuDate.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuDate.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuDate.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuDate.java diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuTime.java b/app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuTime.java similarity index 100% rename from ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuTime.java rename to app/src/main/java/org/monkey/d/ruffy/ruffy/driver/display/menu/MenuTime.java diff --git a/ruffy-spi/.gitignore b/ruffy-spi/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/ruffy-spi/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/ruffy-spi/build.gradle b/ruffy-spi/build.gradle deleted file mode 100644 index 94a3ddf90c..0000000000 --- a/ruffy-spi/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 23 - buildToolsVersion "26.0.2" - - defaultConfig { - minSdkVersion 21 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.4.0' - testCompile 'junit:junit:4.12' -} diff --git a/ruffy-spi/proguard-rules.pro b/ruffy-spi/proguard-rules.pro deleted file mode 100644 index ae0b3241cc..0000000000 --- a/ruffy-spi/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /home/joe/opt/android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/ruffy-spi/src/main/AndroidManifest.xml b/ruffy-spi/src/main/AndroidManifest.xml deleted file mode 100644 index 6ad261f527..0000000000 --- a/ruffy-spi/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - diff --git a/ruffyscripter/.gitignore b/ruffyscripter/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/ruffyscripter/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/ruffyscripter/build.gradle b/ruffyscripter/build.gradle deleted file mode 100644 index 6f3ecbc070..0000000000 --- a/ruffyscripter/build.gradle +++ /dev/null @@ -1,35 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 23 - buildToolsVersion "26.0.2" - - defaultConfig { - minSdkVersion 21 - targetSdkVersion 23 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:23.4.0' - testCompile 'junit:junit:4.12' - compile project(':ruffy-spi') - compile 'org.slf4j:slf4j-api:1.7.12' - compile 'com.google.guava:guava:20.0' -} diff --git a/ruffyscripter/proguard-rules.pro b/ruffyscripter/proguard-rules.pro deleted file mode 100644 index ae0b3241cc..0000000000 --- a/ruffyscripter/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /home/joe/opt/android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/ruffyscripter/src/main/AndroidManifest.xml b/ruffyscripter/src/main/AndroidManifest.xml deleted file mode 100644 index 2c730e84e5..0000000000 --- a/ruffyscripter/src/main/AndroidManifest.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/settings.gradle b/settings.gradle index a55c0c137c..9ccfb61915 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':wear', ':ruffyscripter', ':ruffy-spi' +include ':app', ':wear' From 10d2b8739f0cab0abb057e3ca904aeb4158e46df Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:10:11 +0100 Subject: [PATCH 14/54] Log commands to Fabric. --- .../jotomo/ruffyscripter/RuffyScripter.java | 20 ++++++++++++++++++- .../plugins/PumpCombo/ComboPlugin.java | 2 -- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index aa748e031c..d0034768d1 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -10,6 +10,8 @@ import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.crashlytics.android.answers.Answers; +import com.crashlytics.android.answers.CustomEvent; import com.google.common.base.Joiner; import org.monkey.d.ruffy.ruffy.driver.IRTHandler; @@ -44,6 +46,7 @@ import de.jotomo.ruffyscripter.commands.ReadPumpStateCommand; import de.jotomo.ruffyscripter.commands.ReadReservoirLevelAndLastBolus; import de.jotomo.ruffyscripter.commands.SetBasalProfileCommand; import de.jotomo.ruffyscripter.commands.SetTbrCommand; +import info.nightscout.androidaps.BuildConfig; /** * Provides scripting 'runtime' and operations. consider moving operations into a separate @@ -167,6 +170,9 @@ public class RuffyScripter implements RuffyCommands { if (!boundSucceeded) { log.error("No connection to ruffy. Pump control unavailable."); + } else { + Answers.getInstance().logCustom(new CustomEvent("RuffyScripterInit") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)); } } @@ -417,6 +423,8 @@ public class RuffyScripter implements RuffyCommands { } } log.debug("Recovery from connection loss " + (connected ? "succeeded" : "failed")); + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromConnectionLoss") + .putCustomAttribute("success", connected ? "true" : "else")); return connected; } @@ -439,7 +447,9 @@ public class RuffyScripter implements RuffyCommands { } } try { - return readPumpStateInternal(); + PumpState pumpState = readPumpStateInternal(); + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailureSucceded")); + return pumpState; } catch (Exception e) { log.debug("Reading pump state during recovery failed", e); return new PumpState(); @@ -462,6 +472,7 @@ public class RuffyScripter implements RuffyCommands { long initialUpdateTime = menuLastUpdated; while (initialUpdateTime == menuLastUpdated) { if (System.currentTimeMillis() > timeoutExpired) { + Answers.getInstance().logCustom(new CustomEvent("ComboConnectTimeout")); throw new CommandException("Timeout connecting to pump"); } SystemClock.sleep(50); @@ -768,12 +779,14 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter) { + Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmd")); return runCommand(new BolusCommand(amount, bolusProgressReporter)); } @Override public void cancelBolus() { if (activeCmd instanceof BolusCommand) { + Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmdCancel")); ((BolusCommand) activeCmd).requestCancellation(); } else { log.error("cancelBolus called, but active command is not a bolus:" + activeCmd); @@ -782,16 +795,19 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult setTbr(int percent, int duration) { + Answers.getInstance().logCustom(new CustomEvent("ComboSetTbrCmd")); return runCommand(new SetTbrCommand(percent, duration)); } @Override public CommandResult cancelTbr() { + Answers.getInstance().logCustom(new CustomEvent("ComboCancelTbrCmd")); return runCommand(new CancelTbrCommand()); } @Override public CommandResult confirmAlert(int warningCode) { + Answers.getInstance().logCustom(new CustomEvent("ComboConfirmAlertCmd")); return runCommand(new ConfirmAlertCommand(warningCode)); } @@ -802,11 +818,13 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult readBasalProfile() { + Answers.getInstance().logCustom(new CustomEvent("ComboReadBasalProfileCmd")); return runCommand(new ReadBasalProfileCommand()); } @Override public CommandResult setBasalProfile(BasalProfile basalProfile) { + Answers.getInstance().logCustom(new CustomEvent("ComboSetBasalProfileCmd")); return runCommand(new SetBasalProfileCommand(basalProfile)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 7128236d95..106264cc32 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -352,8 +352,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } private synchronized void initializePump() { - Answers.getInstance().logCustom(new CustomEvent("ComboInit") - .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)); long maxWait = System.currentTimeMillis() + 15 * 1000; while (!ruffyScripter.isPumpAvailable()) { log.debug("Waiting for ruffy service to come up ..."); From 6c4c662c3165e6decd2812f6cd3d27204346b100 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:14:26 +0100 Subject: [PATCH 15/54] Remove RuffyCommandsV1Impl. --- .../spi => ruffyscripter}/BasalProfile.java | 2 +- .../BolusProgressReporter.java | 2 +- .../spi => ruffyscripter}/CommandResult.java | 6 +- .../spi => ruffyscripter}/PumpErrorCodes.java | 2 +- .../spi => ruffyscripter}/PumpState.java | 2 +- .../PumpWarningCodes.java | 2 +- .../spi => ruffyscripter}/RuffyCommands.java | 4 +- .../ruffyscripter/RuffyCommandsV1Impl.java | 127 ------------------ .../jotomo/ruffyscripter/RuffyScripter.java | 10 +- .../WarningOrErrorCode.java | 2 +- .../ruffyscripter/commands/BaseCommand.java | 5 +- .../ruffyscripter/commands/BolusCommand.java | 18 +-- .../commands/CancelTbrCommand.java | 4 +- .../ruffyscripter/commands/Command.java | 2 +- .../commands/ReadBasalProfileCommand.java | 4 +- .../commands/ReadHistoryCommand.java | 12 +- .../ReadReservoirLevelAndLastBolus.java | 2 +- .../commands/SetBasalProfileCommand.java | 4 +- .../ruffyscripter/commands/SetTbrCommand.java | 6 +- .../spi => ruffyscripter}/history/Bolus.java | 2 +- .../history/HistoryRecord.java | 2 +- .../history/PumpAlert.java | 2 +- .../history/PumpHistory.java | 2 +- .../history/PumpHistoryRequest.java | 2 +- .../spi => ruffyscripter}/history/Tbr.java | 2 +- .../spi => ruffyscripter}/history/Tdd.java | 2 +- .../PumpCombo/ComboAlertHistoryDialog.java | 2 +- .../plugins/PumpCombo/ComboFragment.java | 4 +- .../plugins/PumpCombo/ComboPlugin.java | 26 ++-- .../plugins/PumpCombo/ComboPump.java | 10 +- .../PumpCombo/ComboTddHistoryDialog.java | 2 +- 31 files changed, 71 insertions(+), 203 deletions(-) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/BasalProfile.java (96%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/BolusProgressReporter.java (88%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/CommandResult.java (93%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/PumpErrorCodes.java (95%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/PumpState.java (99%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/PumpWarningCodes.java (93%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/RuffyCommands.java (94%) delete mode 100644 app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/WarningOrErrorCode.java (95%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/Bolus.java (96%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/HistoryRecord.java (79%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/PumpAlert.java (97%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/PumpHistory.java (97%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/PumpHistoryRequest.java (97%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/Tbr.java (96%) rename app/src/main/java/de/jotomo/{ruffy/spi => ruffyscripter}/history/Tdd.java (96%) diff --git a/app/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java b/app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java rename to app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java index 1765ff78f4..5496357eae 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/BasalProfile.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; import java.util.Arrays; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java b/app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java similarity index 88% rename from app/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java rename to app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java index 274342010a..4422bd0ed0 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/BolusProgressReporter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; public interface BolusProgressReporter { enum State { diff --git a/app/src/main/java/de/jotomo/ruffy/spi/CommandResult.java b/app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffy/spi/CommandResult.java rename to app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java index 2ab5695002..5b1dd6c817 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/CommandResult.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java @@ -1,12 +1,12 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; import android.support.annotation.Nullable; import java.util.LinkedList; import java.util.List; -import de.jotomo.ruffy.spi.history.Bolus; -import de.jotomo.ruffy.spi.history.PumpHistory; +import de.jotomo.ruffyscripter.history.Bolus; +import de.jotomo.ruffyscripter.history.PumpHistory; public class CommandResult { /** Whether the command was executed successfully. */ diff --git a/app/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java rename to app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java index 28bfe0bd74..28b7ff5f08 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/PumpErrorCodes.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; public class PumpErrorCodes { public static final int CARTRIDGE_EMPTY = 1; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/PumpState.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java similarity index 99% rename from app/src/main/java/de/jotomo/ruffy/spi/PumpState.java rename to app/src/main/java/de/jotomo/ruffyscripter/PumpState.java index 917c563e77..f1cb848e67 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/PumpState.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; /** State displayed on the main screen of the pump. */ public class PumpState { diff --git a/app/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java b/app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java rename to app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java index c081d8ad9f..c846fc3cfc 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/PumpWarningCodes.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; public class PumpWarningCodes { public static final int CARTRIDGE_LOW = 1; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java similarity index 94% rename from app/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java rename to app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java index 8e43771ac1..7e239f1c0c 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java @@ -1,6 +1,6 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; -import de.jotomo.ruffy.spi.history.PumpHistoryRequest; +import de.jotomo.ruffyscripter.history.PumpHistoryRequest; public interface RuffyCommands { /** Issues a bolus issues updates on progress through via {@link BolusProgressReporter}. */ diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java deleted file mode 100644 index bd95aef8da..0000000000 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java +++ /dev/null @@ -1,127 +0,0 @@ -package de.jotomo.ruffyscripter; - -import android.content.Context; -import android.support.annotation.NonNull; - -import java.util.Date; - -import de.jotomo.ruffy.spi.BasalProfile; -import de.jotomo.ruffy.spi.BolusProgressReporter; -import de.jotomo.ruffy.spi.CommandResult; -import de.jotomo.ruffy.spi.RuffyCommands; -import de.jotomo.ruffy.spi.history.PumpHistory; -import de.jotomo.ruffy.spi.history.PumpHistoryRequest; - - -public class RuffyCommandsV1Impl implements RuffyCommands { - private static RuffyCommandsV1Impl instance; - private static RuffyCommands delegate; - - @NonNull - public static RuffyCommands getInstance(Context context) { - if (instance == null) { - instance = new RuffyCommandsV1Impl(); - delegate = new RuffyScripter(context); - } - return instance; - } - - private RuffyCommandsV1Impl() {} - - /** Not supported by RuffyScripter */ - @Override - public CommandResult getDateAndTime() { - return new CommandResult().success(false); - } - - @Override - public CommandResult readReservoirLevelAndLastBolus() { - return delegate.readReservoirLevelAndLastBolus(); - } - - @Override - public CommandResult confirmAlert(int warningCode) { - return delegate.confirmAlert(warningCode); - } - - @Override - public CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter) { - return delegate.deliverBolus(amount, bolusProgressReporter); - } - - @Override - public void cancelBolus() { - delegate.cancelBolus(); - } - - @Override - public CommandResult setTbr(int percent, int duration) { - return delegate.setTbr(percent, duration); - } - - @Override - public CommandResult cancelTbr() { - return delegate.cancelTbr(); - } - - @Override - public boolean isPumpAvailable() { - return delegate.isPumpAvailable(); - } - - @Override - public boolean isPumpBusy() { - return delegate.isPumpBusy(); - } - - @Override - public boolean isConnected() { - return delegate.isConnected(); - } - - @Override - public void disconnect() { - delegate.disconnect(); - } - - @Override - public CommandResult readPumpState() { - return delegate.readPumpState(); - } - - @Override - public CommandResult readHistory(PumpHistoryRequest request) { - return delegate.readHistory(request); - } - - @Override - public CommandResult readBasalProfile() { - return delegate.readBasalProfile(); - } - - @Override - public CommandResult setBasalProfile(BasalProfile basalProfile) { - return delegate.setBasalProfile(basalProfile); - } - - /** Not supported by RuffyScripter */ - @Override - public CommandResult setDateAndTime() { - return new CommandResult().success(false); - } - - @Override - public void requestPairing() { - delegate.requestPairing(); - } - - @Override - public void sendAuthKey(String key) { - delegate.sendAuthKey(key); - } - - @Override - public void unpair() { - delegate.unpair(); - } -} diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index d0034768d1..e2a88481a1 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -28,13 +28,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; -import de.jotomo.ruffy.spi.BasalProfile; -import de.jotomo.ruffy.spi.BolusProgressReporter; -import de.jotomo.ruffy.spi.CommandResult; -import de.jotomo.ruffy.spi.PumpState; -import de.jotomo.ruffy.spi.RuffyCommands; -import de.jotomo.ruffy.spi.WarningOrErrorCode; -import de.jotomo.ruffy.spi.history.PumpHistoryRequest; +import de.jotomo.ruffyscripter.history.PumpHistoryRequest; import de.jotomo.ruffyscripter.commands.BolusCommand; import de.jotomo.ruffyscripter.commands.CancelTbrCommand; import de.jotomo.ruffyscripter.commands.Command; @@ -127,7 +121,7 @@ public class RuffyScripter implements RuffyCommands { } }; - RuffyScripter(Context context) { + public RuffyScripter(Context context) { boolean boundSucceeded = false; try { diff --git a/app/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java b/app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java rename to app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java index 9bc1754e9f..0961d79a29 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/WarningOrErrorCode.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi; +package de.jotomo.ruffyscripter; import android.support.annotation.Nullable; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java index 6d2a887cc5..0ef54cd955 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java @@ -3,7 +3,8 @@ package de.jotomo.ruffyscripter.commands; import java.util.Collections; import java.util.List; -import de.jotomo.ruffy.spi.CommandResult; +import de.jotomo.ruffyscripter.CommandResult; +import de.jotomo.ruffyscripter.PumpWarningCodes; import de.jotomo.ruffyscripter.RuffyScripter; public abstract class BaseCommand implements Command { @@ -29,7 +30,7 @@ public abstract class BaseCommand implements Command { /** * A warning id (or null) caused by a disconnect we can safely confirm on reconnect, * knowing it's not severe as it was caused by this command. - * @see de.jotomo.ruffy.spi.PumpWarningCodes + * @see PumpWarningCodes */ @Override public Integer getReconnectWarningId() { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java index 379e977bf8..7a07b3e474 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -11,17 +11,17 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import de.jotomo.ruffy.spi.BolusProgressReporter; -import de.jotomo.ruffy.spi.PumpWarningCodes; -import de.jotomo.ruffy.spi.WarningOrErrorCode; -import de.jotomo.ruffy.spi.history.Bolus; +import de.jotomo.ruffyscripter.BolusProgressReporter; +import de.jotomo.ruffyscripter.PumpWarningCodes; +import de.jotomo.ruffyscripter.WarningOrErrorCode; +import de.jotomo.ruffyscripter.history.Bolus; import de.jotomo.ruffyscripter.RuffyScripter; -import static de.jotomo.ruffy.spi.BolusProgressReporter.State.DELIVERED; -import static de.jotomo.ruffy.spi.BolusProgressReporter.State.DELIVERING; -import static de.jotomo.ruffy.spi.BolusProgressReporter.State.PROGRAMMING; -import static de.jotomo.ruffy.spi.BolusProgressReporter.State.STOPPED; -import static de.jotomo.ruffy.spi.BolusProgressReporter.State.STOPPING; +import static de.jotomo.ruffyscripter.BolusProgressReporter.State.DELIVERED; +import static de.jotomo.ruffyscripter.BolusProgressReporter.State.DELIVERING; +import static de.jotomo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING; +import static de.jotomo.ruffyscripter.BolusProgressReporter.State.STOPPED; +import static de.jotomo.ruffyscripter.BolusProgressReporter.State.STOPPING; public class BolusCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(BolusCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java index 4c4f9f5a02..15808461ec 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -4,8 +4,8 @@ import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import de.jotomo.ruffy.spi.PumpState; -import de.jotomo.ruffy.spi.PumpWarningCodes; +import de.jotomo.ruffyscripter.PumpState; +import de.jotomo.ruffyscripter.PumpWarningCodes; public class CancelTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(CancelTbrCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java index 9e95bee481..d89a9734ac 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java @@ -3,7 +3,7 @@ package de.jotomo.ruffyscripter.commands; import java.util.List; import de.jotomo.ruffyscripter.RuffyScripter; -import de.jotomo.ruffy.spi.CommandResult; +import de.jotomo.ruffyscripter.CommandResult; /** * Interface for all commands to be executed by the pump. diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java index 1cd3f1df32..87cb631694 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java @@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; -import de.jotomo.ruffy.spi.BasalProfile; -import de.jotomo.ruffy.spi.PumpState; +import de.jotomo.ruffyscripter.BasalProfile; +import de.jotomo.ruffyscripter.PumpState; public class ReadBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(ReadBasalProfileCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java index 8ba6c18d81..9b8aec8391 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java @@ -13,12 +13,12 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; -import de.jotomo.ruffy.spi.history.Bolus; -import de.jotomo.ruffy.spi.history.PumpAlert; -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.history.Tdd; +import de.jotomo.ruffyscripter.history.Bolus; +import de.jotomo.ruffyscripter.history.PumpAlert; +import de.jotomo.ruffyscripter.history.PumpHistory; +import de.jotomo.ruffyscripter.history.PumpHistoryRequest; +import de.jotomo.ruffyscripter.history.Tbr; +import de.jotomo.ruffyscripter.history.Tdd; // Note: TBRs are added to history only after they've completed running // TODO remove duplication diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java index 1aefd38fab..00246f3809 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java @@ -10,7 +10,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import java.util.Date; -import de.jotomo.ruffy.spi.history.Bolus; +import de.jotomo.ruffyscripter.history.Bolus; public class ReadReservoirLevelAndLastBolus extends BaseCommand { @Override diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java index f6ffd2216d..ae1cb4e4e3 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java @@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; -import de.jotomo.ruffy.spi.BasalProfile; -import de.jotomo.ruffy.spi.PumpState; +import de.jotomo.ruffyscripter.BasalProfile; +import de.jotomo.ruffyscripter.PumpState; public class SetBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetBasalProfileCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index f3bfb87313..4a47679ac4 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -12,9 +12,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import de.jotomo.ruffy.spi.PumpState; -import de.jotomo.ruffy.spi.PumpWarningCodes; -import de.jotomo.ruffy.spi.WarningOrErrorCode; +import de.jotomo.ruffyscripter.PumpState; +import de.jotomo.ruffyscripter.PumpWarningCodes; +import de.jotomo.ruffyscripter.WarningOrErrorCode; public class SetTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java b/app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java index 450cc2390e..1e2eebf040 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java b/app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java similarity index 79% rename from app/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java index 32f3d330c4..64ddb21f24 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/HistoryRecord.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; public abstract class HistoryRecord { public final long timestamp; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java similarity index 97% rename from app/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java index 39ff2df69c..d770579209 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpAlert.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java similarity index 97% rename from app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java index 4c7a7a5d47..b5c8284f74 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import android.support.annotation.NonNull; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java similarity index 97% rename from app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java index 9d89241399..2719059e32 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java b/app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java index 97936dcaef..2d7c7c3f65 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java b/app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java rename to app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java index 58c3ac4c4d..0e20de59f4 100644 --- a/app/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffy.spi.history; +package de.jotomo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java index 9b4b2f98d8..8873804bbc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java @@ -10,7 +10,7 @@ import android.widget.TextView; import java.text.DateFormat; import java.util.List; -import de.jotomo.ruffy.spi.history.PumpAlert; +import de.jotomo.ruffyscripter.history.PumpAlert; import info.nightscout.androidaps.R; public class ComboAlertHistoryDialog extends DialogFragment { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index e5989e4ecd..3e09d76fd9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -14,8 +14,8 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import de.jotomo.ruffy.spi.PumpState; -import de.jotomo.ruffy.spi.history.Bolus; +import de.jotomo.ruffyscripter.PumpState; +import de.jotomo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 106264cc32..65a38b42e4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -11,18 +11,18 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; -import de.jotomo.ruffy.spi.BasalProfile; -import de.jotomo.ruffy.spi.BolusProgressReporter; -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.ruffyscripter.RuffyCommandsV1Impl; +import de.jotomo.ruffyscripter.BasalProfile; +import de.jotomo.ruffyscripter.BolusProgressReporter; +import de.jotomo.ruffyscripter.CommandResult; +import de.jotomo.ruffyscripter.PumpState; +import de.jotomo.ruffyscripter.PumpWarningCodes; +import de.jotomo.ruffyscripter.RuffyCommands; +import de.jotomo.ruffyscripter.RuffyScripter; +import de.jotomo.ruffyscripter.WarningOrErrorCode; +import de.jotomo.ruffyscripter.history.Bolus; +import de.jotomo.ruffyscripter.history.PumpHistory; +import de.jotomo.ruffyscripter.history.PumpHistoryRequest; +import de.jotomo.ruffyscripter.history.Tbr; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -113,7 +113,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf .success(false).enacted(false).comment(MainApp.sResources.getString(R.string.combo_pump_unsupported_operation)); private ComboPlugin() { - ruffyScripter = RuffyCommandsV1Impl.getInstance(MainApp.instance()); + ruffyScripter = new RuffyScripter(MainApp.instance().getApplicationContext()); } public ComboPump getPump() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 3aa4137b8b..7c903533b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -6,11 +6,11 @@ import android.support.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import de.jotomo.ruffy.spi.BasalProfile; -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.Tdd; +import de.jotomo.ruffyscripter.BasalProfile; +import de.jotomo.ruffyscripter.PumpState; +import de.jotomo.ruffyscripter.history.Bolus; +import de.jotomo.ruffyscripter.history.PumpAlert; +import de.jotomo.ruffyscripter.history.Tdd; class ComboPump { boolean initialized = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java index 71ab8f2515..741691f4e4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java @@ -11,7 +11,7 @@ import java.text.DateFormat; import java.util.List; import java.util.Locale; -import de.jotomo.ruffy.spi.history.Tdd; +import de.jotomo.ruffyscripter.history.Tdd; import info.nightscout.androidaps.R; public class ComboTddHistoryDialog extends DialogFragment { From 3fde47d283803ae33a6fff18354bc84ec98db951 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:16:58 +0100 Subject: [PATCH 16/54] Move ruffyscripter to combo plugin package. --- .../PumpCombo/ComboAlertHistoryDialog.java | 2 +- .../plugins/PumpCombo/ComboFragment.java | 4 +-- .../plugins/PumpCombo/ComboPlugin.java | 24 ++++++++-------- .../plugins/PumpCombo/ComboPump.java | 10 +++---- .../PumpCombo/ComboTddHistoryDialog.java | 2 +- .../ruffyscripter/BasalProfile.java | 2 +- .../ruffyscripter/BolusProgressReporter.java | 2 +- .../ruffyscripter/CommandResult.java | 6 ++-- .../ruffyscripter/PumpErrorCodes.java | 2 +- .../PumpCombo}/ruffyscripter/PumpState.java | 2 +- .../ruffyscripter/PumpWarningCodes.java | 2 +- .../ruffyscripter/RuffyCommands.java | 4 +-- .../ruffyscripter/RuffyScripter.java | 28 +++++++++---------- .../ruffyscripter/WarningOrErrorCode.java | 2 +- .../ruffyscripter/commands/BaseCommand.java | 8 +++--- .../ruffyscripter/commands/BolusCommand.java | 22 +++++++-------- .../commands/CancelTbrCommand.java | 6 ++-- .../ruffyscripter/commands/Command.java | 6 ++-- .../commands/CommandException.java | 2 +- .../commands/ConfirmAlertCommand.java | 2 +- .../commands/ReadBasalProfileCommand.java | 6 ++-- .../commands/ReadHistoryCommand.java | 14 +++++----- .../commands/ReadPumpStateCommand.java | 2 +- .../ReadReservoirLevelAndLastBolus.java | 4 +-- .../commands/SetBasalProfileCommand.java | 6 ++-- .../ruffyscripter/commands/SetTbrCommand.java | 8 +++--- .../ruffyscripter/history/Bolus.java | 2 +- .../ruffyscripter/history/HistoryRecord.java | 2 +- .../ruffyscripter/history/PumpAlert.java | 2 +- .../ruffyscripter/history/PumpHistory.java | 2 +- .../history/PumpHistoryRequest.java | 2 +- .../PumpCombo}/ruffyscripter/history/Tbr.java | 2 +- .../PumpCombo}/ruffyscripter/history/Tdd.java | 2 +- 33 files changed, 96 insertions(+), 96 deletions(-) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/BasalProfile.java (93%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/BolusProgressReporter.java (78%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/CommandResult.java (88%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/PumpErrorCodes.java (91%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/PumpState.java (98%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/PumpWarningCodes.java (88%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/RuffyCommands.java (91%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/RuffyScripter.java (96%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/WarningOrErrorCode.java (91%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/BaseCommand.java (74%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/BolusCommand.java (92%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/CancelTbrCommand.java (84%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/Command.java (69%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/CommandException.java (76%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/ConfirmAlertCommand.java (87%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/ReadBasalProfileCommand.java (91%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/ReadHistoryCommand.java (95%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/ReadPumpStateCommand.java (83%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java (93%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/SetBasalProfileCommand.java (96%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/commands/SetTbrCommand.java (97%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/Bolus.java (94%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/HistoryRecord.java (68%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/PumpAlert.java (95%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/PumpHistory.java (95%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/PumpHistoryRequest.java (95%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/Tbr.java (93%) rename app/src/main/java/{de/jotomo => info/nightscout/androidaps/plugins/PumpCombo}/ruffyscripter/history/Tdd.java (93%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java index 8873804bbc..6f30b3aed9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboAlertHistoryDialog.java @@ -10,7 +10,7 @@ import android.widget.TextView; import java.text.DateFormat; import java.util.List; -import de.jotomo.ruffyscripter.history.PumpAlert; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert; import info.nightscout.androidaps.R; public class ComboAlertHistoryDialog extends DialogFragment { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 3e09d76fd9..4f4aa58460 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -14,8 +14,8 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 65a38b42e4..bcd58edff5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -11,18 +11,18 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; -import de.jotomo.ruffyscripter.BasalProfile; -import de.jotomo.ruffyscripter.BolusProgressReporter; -import de.jotomo.ruffyscripter.CommandResult; -import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.PumpWarningCodes; -import de.jotomo.ruffyscripter.RuffyCommands; -import de.jotomo.ruffyscripter.RuffyScripter; -import de.jotomo.ruffyscripter.WarningOrErrorCode; -import de.jotomo.ruffyscripter.history.Bolus; -import de.jotomo.ruffyscripter.history.PumpHistory; -import de.jotomo.ruffyscripter.history.PumpHistoryRequest; -import de.jotomo.ruffyscripter.history.Tbr; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 7c903533b6..aef0f2abd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -6,11 +6,11 @@ import android.support.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import de.jotomo.ruffyscripter.BasalProfile; -import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.history.Bolus; -import de.jotomo.ruffyscripter.history.PumpAlert; -import de.jotomo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; class ComboPump { boolean initialized = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java index 741691f4e4..7da1c8ba30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboTddHistoryDialog.java @@ -11,7 +11,7 @@ import java.text.DateFormat; import java.util.List; import java.util.Locale; -import de.jotomo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; import info.nightscout.androidaps.R; public class ComboTddHistoryDialog extends DialogFragment { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java index 5496357eae..fa9c2dceb0 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/BasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BasalProfile.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; import java.util.Arrays; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java similarity index 78% rename from app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java index 4422bd0ed0..59d334fe6f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/BolusProgressReporter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/BolusProgressReporter.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; public interface BolusProgressReporter { enum State { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java similarity index 88% rename from app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java index 5b1dd6c817..a837d7781b 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/CommandResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java @@ -1,12 +1,12 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; import android.support.annotation.Nullable; import java.util.LinkedList; import java.util.List; -import de.jotomo.ruffyscripter.history.Bolus; -import de.jotomo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; public class CommandResult { /** Whether the command was executed successfully. */ diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java similarity index 91% rename from app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java index 28b7ff5f08..63cd81e3a6 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpErrorCodes.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpErrorCodes.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; public class PumpErrorCodes { public static final int CARTRIDGE_EMPTY = 1; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java similarity index 98% rename from app/src/main/java/de/jotomo/ruffyscripter/PumpState.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java index f1cb848e67..c6f08ed136 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; /** State displayed on the main screen of the pump. */ public class PumpState { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java similarity index 88% rename from app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java index c846fc3cfc..60d1898834 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/PumpWarningCodes.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpWarningCodes.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; public class PumpWarningCodes { public static final int CARTRIDGE_LOW = 1; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java similarity index 91% rename from app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java index 7e239f1c0c..344b63d8f9 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java @@ -1,6 +1,6 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; -import de.jotomo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; public interface RuffyCommands { /** Issues a bolus issues updates on progress through via {@link BolusProgressReporter}. */ diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index e2a88481a1..d63c8b165e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; import android.content.ComponentName; import android.content.Context; @@ -28,18 +28,18 @@ import java.util.Date; import java.util.List; import java.util.Objects; -import de.jotomo.ruffyscripter.history.PumpHistoryRequest; -import de.jotomo.ruffyscripter.commands.BolusCommand; -import de.jotomo.ruffyscripter.commands.CancelTbrCommand; -import de.jotomo.ruffyscripter.commands.Command; -import de.jotomo.ruffyscripter.commands.CommandException; -import de.jotomo.ruffyscripter.commands.ConfirmAlertCommand; -import de.jotomo.ruffyscripter.commands.ReadBasalProfileCommand; -import de.jotomo.ruffyscripter.commands.ReadHistoryCommand; -import de.jotomo.ruffyscripter.commands.ReadPumpStateCommand; -import de.jotomo.ruffyscripter.commands.ReadReservoirLevelAndLastBolus; -import de.jotomo.ruffyscripter.commands.SetBasalProfileCommand; -import de.jotomo.ruffyscripter.commands.SetTbrCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.Command; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CommandException; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ConfirmAlertCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadBasalProfileCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadPumpStateCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadReservoirLevelAndLastBolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetBasalProfileCommand; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand; import info.nightscout.androidaps.BuildConfig; /** @@ -74,7 +74,7 @@ public class RuffyScripter implements RuffyCommands { @Override public void fail(String message) throws RemoteException { - // TODO 10-28 19:50:54.059 1426 1826 W RuffyScripter: [Thread-268] WARN [de.jotomo.ruffyscripter.RuffyScripter$1:78]: Ruffy warns: no connection possible + // TODO 10-28 19:50:54.059 1426 1826 W RuffyScripter: [Thread-268] WARN [info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter$1:78]: Ruffy warns: no connection possible log.warn("Ruffy warns: " + message); } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java similarity index 91% rename from app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java index 0961d79a29..a4e21da289 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/WarningOrErrorCode.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/WarningOrErrorCode.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter; import android.support.annotation.Nullable; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java similarity index 74% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java index 0ef54cd955..623a3bb51f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java @@ -1,11 +1,11 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import java.util.Collections; import java.util.List; -import de.jotomo.ruffyscripter.CommandResult; -import de.jotomo.ruffyscripter.PumpWarningCodes; -import de.jotomo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; public abstract class BaseCommand implements Command { // RS will inject itself here diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java similarity index 92% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 7a07b3e474..36e8c9252a 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import android.os.SystemClock; @@ -11,17 +11,17 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import de.jotomo.ruffyscripter.BolusProgressReporter; -import de.jotomo.ruffyscripter.PumpWarningCodes; -import de.jotomo.ruffyscripter.WarningOrErrorCode; -import de.jotomo.ruffyscripter.history.Bolus; -import de.jotomo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; -import static de.jotomo.ruffyscripter.BolusProgressReporter.State.DELIVERED; -import static de.jotomo.ruffyscripter.BolusProgressReporter.State.DELIVERING; -import static de.jotomo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING; -import static de.jotomo.ruffyscripter.BolusProgressReporter.State.STOPPED; -import static de.jotomo.ruffyscripter.BolusProgressReporter.State.STOPPING; +import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERED; +import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.DELIVERING; +import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.PROGRAMMING; +import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPED; +import static info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter.State.STOPPING; public class BolusCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(BolusCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java similarity index 84% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java index 15808461ec..b1787005e1 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CancelTbrCommand.java @@ -1,11 +1,11 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; public class CancelTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(CancelTbrCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java similarity index 69% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java index d89a9734ac..152befe00d 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/Command.java @@ -1,9 +1,9 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import java.util.List; -import de.jotomo.ruffyscripter.RuffyScripter; -import de.jotomo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; /** * Interface for all commands to be executed by the pump. diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java similarity index 76% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java index 03b2acef2d..77c1db5437 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandException.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/CommandException.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; public class CommandException extends RuntimeException { public CommandException(String message) { diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java similarity index 87% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java index a561fb0003..636b6a624d 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ConfirmAlertCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ConfirmAlertCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; public class ConfirmAlertCommand extends BaseCommand { private final int warningCode; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java similarity index 91% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java index 87cb631694..2c23d5814b 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadBasalProfileCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadBasalProfileCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import org.monkey.d.ruffy.ruffy.driver.display.Menu; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; @@ -9,8 +9,8 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; -import de.jotomo.ruffyscripter.BasalProfile; -import de.jotomo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; public class ReadBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(ReadBasalProfileCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java index 9b8aec8391..4e94caf750 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import android.support.annotation.NonNull; @@ -13,12 +13,12 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; -import de.jotomo.ruffyscripter.history.Bolus; -import de.jotomo.ruffyscripter.history.PumpAlert; -import de.jotomo.ruffyscripter.history.PumpHistory; -import de.jotomo.ruffyscripter.history.PumpHistoryRequest; -import de.jotomo.ruffyscripter.history.Tbr; -import de.jotomo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpAlert; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; // Note: TBRs are added to history only after they've completed running // TODO remove duplication diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java similarity index 83% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java index 5b9218dd33..cfa8d0f329 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadPumpStateCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadPumpStateCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; public class ReadPumpStateCommand extends BaseCommand { @Override diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java index 00246f3809..a1f22f2013 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import android.support.annotation.NonNull; @@ -10,7 +10,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import java.util.Date; -import de.jotomo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; public class ReadReservoirLevelAndLastBolus extends BaseCommand { @Override diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java similarity index 96% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java index ae1cb4e4e3..f959c17f36 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetBasalProfileCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import android.os.SystemClock; @@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; -import de.jotomo.ruffyscripter.BasalProfile; -import de.jotomo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; public class SetBasalProfileCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetBasalProfileCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java similarity index 97% rename from app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java index 4a47679ac4..f618d50156 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/SetTbrCommand.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.commands; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; import android.os.SystemClock; @@ -12,9 +12,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import de.jotomo.ruffyscripter.PumpState; -import de.jotomo.ruffyscripter.PumpWarningCodes; -import de.jotomo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; public class SetTbrCommand extends BaseCommand { private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class); diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java similarity index 94% rename from app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java index 1e2eebf040..a5d989c331 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/Bolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Bolus.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java similarity index 68% rename from app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java index 64ddb21f24..57e173bb49 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/HistoryRecord.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/HistoryRecord.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; public abstract class HistoryRecord { public final long timestamp; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java index d770579209..413a9ca69b 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpAlert.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpAlert.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java index b5c8284f74..ecc8a1a29f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistory.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistory.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import android.support.annotation.NonNull; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java similarity index 95% rename from app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java index 2719059e32..40dd6e553e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/PumpHistoryRequest.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/PumpHistoryRequest.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java index 2d7c7c3f65..41ec245e89 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/Tbr.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tbr.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import java.util.Date; diff --git a/app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java similarity index 93% rename from app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java index 0e20de59f4..5f799f229e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/history/Tdd.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/history/Tdd.java @@ -1,4 +1,4 @@ -package de.jotomo.ruffyscripter.history; +package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history; import java.util.Date; From cd7af6c5fe7a411d5da626adae59452145ce0eda Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:31:43 +0100 Subject: [PATCH 17/54] Set custom version. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index e1a030130c..32e38b453e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { targetSdkVersion 23 multiDexEnabled true versionCode 1500 - version "1.57-combo-csv2-test" + version "1.57-combo-experimental" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() From eb7ec243358c268899a9ff69b7867f34ae43b6b0 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 22:33:05 +0100 Subject: [PATCH 18/54] Don't read pump TBR history. --- .../nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index bcd58edff5..399c956258 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1017,7 +1017,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf void readAllPumpData() { readHistory(new PumpHistoryRequest() .bolusHistory(PumpHistoryRequest.FULL) - .tbrHistory(PumpHistoryRequest.FULL) +// .tbrHistory(PumpHistoryRequest.FULL) .pumpErrorHistory(PumpHistoryRequest.FULL) .tddHistory(PumpHistoryRequest.FULL) ); From 9f5ffc6646c3528ba8426fbb87aa560cd40bde27 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 23:23:44 +0100 Subject: [PATCH 19/54] Actually do something with the basal rate profile after force-reading. --- .../nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 399c956258..0802c31e4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1021,7 +1021,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf .pumpErrorHistory(PumpHistoryRequest.FULL) .tddHistory(PumpHistoryRequest.FULL) ); - runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); + CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); + if (readBasalResult.success) { + pump.basalProfile = readBasalResult.basalProfile; + } ruffyScripter.disconnect(); } From 262fdf92c87fba439f0adcbe893142a63f71c032 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 23:24:32 +0100 Subject: [PATCH 20/54] Check pump basal rate matches cached profile, force re-read otherwise. --- .../plugins/PumpCombo/ComboPlugin.java | 31 ++++++++++++++++++- .../PumpCombo/ruffyscripter/PumpState.java | 10 +++--- .../ruffyscripter/RuffyScripter.java | 2 +- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 0802c31e4c..baaca002a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -819,11 +819,40 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf checkForUnsafeUsage(preCheckResult); checkAndResolveTbrMismatch(preCheckResult.state); checkPumpTime(preCheckResult.state); + checkBasalRate(preCheckResult.state); checkHistory(); return null; } + + private void checkBasalRate(PumpState state) { + if (!pump.initialized) { + // no cached profile to compare against + return; + } + if (state.tbrActive && state.tbrPercent == 0) { + // can't infer base basal rate if TBR is 0 + return; + } + double pumpBasalRate = state.tbrActive + ? state.basalRate * 100 / state.tbrPercent + : state.basalRate; + int pumpHour = new Date(state.pumpTime).getHours(); + int phoneHour = new Date().getHours(); + if (pumpHour != phoneHour) { + // only check if clocks are close + return; + } + + if (pumpBasalRate != getBaseBasalRate()) { + CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); + if (readBasalResult.success) { + pump.basalProfile = readBasalResult.basalProfile; + } + } + } + /** Check pump time (on the main menu) and raise notification if time is off. * (setting clock is not supported by ruffy) */ private void checkPumpTime(PumpState state) { @@ -1082,7 +1111,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); PumpState ps = pump.state; if (ps.tbrActive) { - extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate); + extendedJson.put("TempBasalAbsoluteRate", ps.basalRate); extendedJson.put("TempBasalPercent", ps.tbrPercent); extendedJson.put("TempBasalRemaining", ps.tbrRemainingDuration); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java index c6f08ed136..963cdd8b4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java @@ -13,8 +13,8 @@ public class PumpState { public boolean tbrActive = false; /** TBR percentage. 100% means no TBR active, just the normal basal rate running. */ public int tbrPercent = -1; - /** The absolute rate the TBR is running, e.g. 0.80U/h. */ - public double tbrRate = -1; + /** The absolute rate the pump is running (regular basal rate or TBR), e.g. 0.80U/h. */ + public double basalRate = -1; /** Remaining time of an active TBR. Note that 0:01 is te lowest displayed, the pump * jumps from that to TBR end, skipping 0:00(xx). */ public int tbrRemainingDuration = -1; @@ -52,8 +52,8 @@ public class PumpState { return this; } - public PumpState tbrRate(double tbrRate) { - this.tbrRate = tbrRate; + public PumpState basalRate(double basalRate) { + this.basalRate = basalRate; return this; } @@ -91,7 +91,7 @@ public class PumpState { ", suspended=" + suspended + ", tbrActive=" + tbrActive + ", tbrPercent=" + tbrPercent + - ", tbrRate=" + tbrRate + + ", basalRate=" + basalRate + ", tbrRemainingDuration=" + tbrRemainingDuration + ", activeAlert=" + activeAlert + ", batteryState=" + batteryState + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index d63c8b165e..9606c2c933 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -520,7 +520,7 @@ public class RuffyScripter implements RuffyCommands { state.tbrPercent = displayedTbr.intValue(); MenuTime durationMenuTime = ((MenuTime) menu.getAttribute(MenuAttribute.RUNTIME)); state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute(); - state.tbrRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE)); + state.basalRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE)); } if (menu.attributes().contains(MenuAttribute.BATTERY_STATE)) { state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE)); From 864100299d06917c5f0d5711484051adf9a3b43c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 23:39:14 +0100 Subject: [PATCH 21/54] Set activity indicator for refresh button. --- .../nightscout/androidaps/plugins/PumpCombo/ComboFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 4f4aa58460..cff810d382 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -75,6 +75,8 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis public void onClick(View view) { switch (view.getId()) { case R.id.combo_refresh_button: + // TODO why is activity in ComboPump? + ComboPlugin.getPlugin().getPump().activity = MainApp.gs(R.string.combo_pump_action_refreshing); ConfigBuilderPlugin.getCommandQueue().readStatus("User request", null); break; case R.id.combo_alerts_button: From 2b995a8a73ad684ea0a63b4e2598bb45ccd6f779 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 28 Jan 2018 23:56:27 +0100 Subject: [PATCH 22/54] RufyfScripter: log active/previous command in error routines. --- .../PumpCombo/ruffyscripter/RuffyScripter.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 9606c2c933..af25ff5e85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -58,6 +58,7 @@ public class RuffyScripter implements RuffyCommands { private volatile Menu currentMenu; private volatile long menuLastUpdated = 0; + private String previousCommand = ""; private volatile Command activeCmd = null; private boolean started = false; @@ -349,6 +350,7 @@ public class RuffyScripter implements RuffyCommands { // ignore } } + previousCommand = "" + activeCmd; activeCmd = null; } } @@ -418,6 +420,7 @@ public class RuffyScripter implements RuffyCommands { } log.debug("Recovery from connection loss " + (connected ? "succeeded" : "failed")); Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromConnectionLoss") + .putCustomAttribute("activeCommand", "" + activeCmd) .putCustomAttribute("success", connected ? "true" : "else")); return connected; } @@ -429,6 +432,9 @@ public class RuffyScripter implements RuffyCommands { private PumpState recoverFromCommandFailure() { Menu menu = this.currentMenu; if (menu == null) { + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailure") + .putCustomAttribute("activeCommand", "" + activeCmd) + .putCustomAttribute("success", "false")); return new PumpState(); } MenuType type = menu.getType(); @@ -442,9 +448,13 @@ public class RuffyScripter implements RuffyCommands { } try { PumpState pumpState = readPumpStateInternal(); - Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailureSucceded")); + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailureSucceded") + .putCustomAttribute("activeCommand", "" + activeCmd)); return pumpState; } catch (Exception e) { + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailure") + .putCustomAttribute("activeCommand", "" + activeCmd) + .putCustomAttribute("success", "false")); log.debug("Reading pump state during recovery failed", e); return new PumpState(); } @@ -466,7 +476,9 @@ public class RuffyScripter implements RuffyCommands { long initialUpdateTime = menuLastUpdated; while (initialUpdateTime == menuLastUpdated) { if (System.currentTimeMillis() > timeoutExpired) { - Answers.getInstance().logCustom(new CustomEvent("ComboConnectTimeout")); + Answers.getInstance().logCustom(new CustomEvent("ComboConnectTimeout") + .putCustomAttribute("activeCommand", "" + activeCmd) + .putCustomAttribute("previousCommand", previousCommand)); throw new CommandException("Timeout connecting to pump"); } SystemClock.sleep(50); From 038ea06abc2bea4d5f09add6271b6e592c95585e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 10:01:07 +0100 Subject: [PATCH 23/54] Log history reads. (cherry picked from commit 7326f29) --- .../plugins/PumpCombo/ruffyscripter/RuffyScripter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index af25ff5e85..26b5400285 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -219,8 +219,10 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult readReservoirLevelAndLastBolus() { if (readQuickInfoMenu) { + Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")); return runCommand(new ReadReservoirLevelAndLastBolus()); } + Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); } @@ -819,6 +821,7 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult readHistory(PumpHistoryRequest request) { + Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); return runCommand(new ReadHistoryCommand(request)); } From 3adda9bf6e27f5c6a2a9613f2b9b19a362f8b86f Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 13:18:49 +0100 Subject: [PATCH 24/54] Clean up bolus delivery code. --- .../plugins/PumpCombo/ComboPlugin.java | 30 ++++++++----------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index baaca002a8..d1173a103f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -493,18 +493,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true); + // check pump is ready and all pump bolus records are known CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus); - long pumpTimeWhenBolusWasRequested = stateResult .state.pumpTime; - if (!stateResult.success || pumpTimeWhenBolusWasRequested == 0) { + if (!stateResult.success) { return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); + .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered)); } - if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus)); } - // the commands above ensured a connection was made, which updated this field if (pumpHistoryChanged) { return new PumpEnactResult().success(false).enacted(false) @@ -529,32 +527,30 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter)); bolusInProgress = false; - // Note that the result of the issues the bolus command is not checked. If there was + // Note that the result of the issued bolus command is not checked. If there was // a connection problem, ruffyscripter tried to recover and we can just check the - // history below + // history below to see what was actually delivered CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); } - - Bolus lastBolus = postBolusStateResult.lastBolus; - if (lastBolus == null || lastBolus.equals(previousBolus)) { + Bolus lastPumpBolus = postBolusStateResult.lastBolus; + if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); } - - if (Math.abs(lastBolus.amount - detailedBolusInfo.insulin) > 0.01) { + if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) { return new PumpEnactResult().success(false).enacted(true) .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered)); } // seems we actually made it this far, let's add a treatment record - detailedBolusInfo.date = calculateFakeBolusDate(lastBolus); - detailedBolusInfo.pumpId = calculateFakeBolusDate(lastBolus); + detailedBolusInfo.date = calculateFakeBolusDate(lastPumpBolus); + detailedBolusInfo.pumpId = calculateFakeBolusDate(lastPumpBolus); detailedBolusInfo.source = Source.PUMP; - detailedBolusInfo.insulin = lastBolus.amount; + detailedBolusInfo.insulin = lastPumpBolus.amount; try { boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); if (!treatmentCreated) { @@ -579,8 +575,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return new PumpEnactResult() .success(true) - .enacted(lastBolus.amount > 0) - .bolusDelivered(lastBolus.amount) + .enacted(lastPumpBolus.amount > 0) + .bolusDelivered(lastPumpBolus.amount) .carbsDelivered(detailedBolusInfo.carbs); } finally { pump.activity = null; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca7dce0430..cb9ca63a59 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -858,6 +858,7 @@ This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed + The pump could\'nt be reached. No bolus was given Bolus delivery failed. It appears no bolus was delivered. To be sure, please check the pump to avoid a double bolus and then bolus again. To guard against bugs, boluses are not automatically retried. Only %.2f U of the requested bolus of %.2f U was delivered due to an error. Please check the pump to verify this and take appropriate actions. Delivering the bolus and verifying the pump\'s history failed, please check the pump and manually create a bolus record using the Careportal tab if a bolus was delivered. From 739e52dc47a9c9208e38676109718667e96f9af6 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 14:48:30 +0100 Subject: [PATCH 25/54] Remove CommandResult.lastBolus in favour of CR.history.bolusHistory. --- .../plugins/PumpCombo/ComboPlugin.java | 16 ++++++++-------- .../PumpCombo/ruffyscripter/CommandResult.java | 5 ----- .../ruffyscripter/commands/BolusCommand.java | 4 +++- .../commands/ReadReservoirLevelAndLastBolus.java | 7 ++++++- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index d1173a103f..56b5184602 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -402,9 +402,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf 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()) { + if (result.history != null && !result.history.bolusHistory.isEmpty()) { pump.lastBolus = result.history.bolusHistory.get(0); } if (result.state.menu != null) { @@ -487,7 +485,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (lastRequestedBolus != null && Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01 && lastRequestedBolus.timestamp + 120 * 1000 > System.currentTimeMillis()) { - log.error("Bolus delivery failure at stage 0", new Exception()); + log.error("Bolus request rejected, same bolus requested recently: " + lastRequestedBolus); return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.bolus_frequency_exceeded)); } @@ -509,7 +507,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf .comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change)); } - Bolus previousBolus = stateResult.lastBolus != null ? stateResult.lastBolus : new Bolus(0, 0, false); + Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty() + ? stateResult.history.bolusHistory.get(0) + : new Bolus(0, 0, false); try { pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin); @@ -536,7 +536,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); } - Bolus lastPumpBolus = postBolusStateResult.lastBolus; + Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty() + ? postBolusStateResult.history.bolusHistory.get(0) + : null; if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); @@ -892,8 +894,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf long lastViolation = 0; if (commandResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BOLUS_TYPE) { lastViolation = System.currentTimeMillis(); - } else if (commandResult.lastBolus != null && !commandResult.lastBolus.isValid) { - lastViolation = commandResult.lastBolus.timestamp; } else if (commandResult.history != null) { for (Bolus bolus : commandResult.history.bolusHistory) { if (!bolus.isValid && bolus.timestamp > lastViolation) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java index a837d7781b..5f140b1a37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java @@ -27,10 +27,6 @@ public class CommandResult { public int reservoirLevel = -1; - /** Only set when by ReadReservoirLevelCommand. */ - @Nullable - public Bolus lastBolus; - public CommandResult success(boolean success) { this.success = success; return this; @@ -59,7 +55,6 @@ public class CommandResult { ", history=" + history + ", basalProfile=" + basalProfile + ", forwardedWarnings='" + forwardedWarnings + '\'' + - ", lastBolus=" + lastBolus + '}'; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 36e8c9252a..5c232211ea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -188,7 +188,9 @@ public class BolusCommand extends BaseCommand { ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus(); readReservoirLevelAndLastBolus.setScripter(scripter); readReservoirLevelAndLastBolus.execute(); - Bolus lastBolus = readReservoirLevelAndLastBolus.result.lastBolus; + Bolus lastBolus = readReservoirLevelAndLastBolus.result.history != null && !readReservoirLevelAndLastBolus.result.history.bolusHistory.isEmpty() + ? readReservoirLevelAndLastBolus.result.history.bolusHistory.get(0) + : null; if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) { throw new CommandException("Unable to determine last bolus"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java index a1f22f2013..66017c6fb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java @@ -8,9 +8,12 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType; import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuDate; import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; public class ReadReservoirLevelAndLastBolus extends BaseCommand { @Override @@ -22,7 +25,9 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand { scripter.verifyMenuIsDisplayed(MenuType.QUICK_INFO); result.reservoirLevel = ((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.REMAINING_INSULIN)).intValue(); scripter.pressCheckKey(); - result.lastBolus = readBolusRecord(); + List bolusHistory = new ArrayList<>(1); + bolusHistory.add(readBolusRecord()); + result.history = new PumpHistory().bolusHistory(bolusHistory); scripter.returnToRootMenu(); result.success = true; } From 5fbd9097d83d79e822d57968d2c8c2aa94328503 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 14:51:39 +0100 Subject: [PATCH 26/54] Rename ReadReservoirLevelAndLastBolus to ReadQuickInfoCommand. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 9 +++++---- .../PumpCombo/ruffyscripter/RuffyCommands.java | 2 +- .../PumpCombo/ruffyscripter/RuffyScripter.java | 10 +++++----- .../ruffyscripter/commands/BolusCommand.java | 14 ++++++++------ ...AndLastBolus.java => ReadQuickInfoCommand.java} | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/{ReadReservoirLevelAndLastBolus.java => ReadQuickInfoCommand.java} (95%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 56b5184602..4cb2778adc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -345,7 +345,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!pump.initialized) { initializePump(); } else { - runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readReservoirLevelAndLastBolus); + runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readQuickInfo); // note that since the history is checked upon every connect, the above already updated // the DB with any changed history records } @@ -395,9 +395,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf MainApp.bus().post(new EventInitializationChanged()); // ComboFragment updates state fully only after the pump has initialized, so read full state here - updateLocalData(runCommand(null, 1, ruffyScripter::readReservoirLevelAndLastBolus)); + updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo)); } + /** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */ private void updateLocalData(CommandResult result) { if (result.reservoirLevel != PumpState.UNKNOWN) { pump.reservoirLevel = result.reservoirLevel; @@ -492,7 +493,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true); // check pump is ready and all pump bolus records are known - CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus); + CommandResult stateResult = runCommand(null, 2, ruffyScripter::readQuickInfo); if (!stateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered)); @@ -531,7 +532,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // a connection problem, ruffyscripter tried to recover and we can just check the // history below to see what was actually delivered - CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus); + CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java index 344b63d8f9..b6266ba829 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java @@ -32,7 +32,7 @@ public interface RuffyCommands { CommandResult readPumpState(); /** Read reservoir level and last bolus via Quick Info */ - CommandResult readReservoirLevelAndLastBolus(); + CommandResult readQuickInfo(); /** Reads pump history via the My Data menu. The {@link PumpHistoryRequest} specifies * what types of data and how far back data is returned. */ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 26b5400285..609c8195a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -28,6 +28,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadQuickInfoCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.BolusCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.CancelTbrCommand; @@ -37,7 +38,6 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.Confi import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadBasalProfileCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadHistoryCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadPumpStateCommand; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.ReadReservoirLevelAndLastBolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetBasalProfileCommand; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands.SetTbrCommand; import info.nightscout.androidaps.BuildConfig; @@ -48,7 +48,7 @@ import info.nightscout.androidaps.BuildConfig; * operations and are cleanly separated from the thread management, connection management etc */ public class RuffyScripter implements RuffyCommands { - private final boolean readQuickInfoMenu = true; + private final boolean readQuickInfo = true; private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class); @@ -217,10 +217,10 @@ public class RuffyScripter implements RuffyCommands { } @Override - public CommandResult readReservoirLevelAndLastBolus() { - if (readQuickInfoMenu) { + public CommandResult readQuickInfo() { + if (readQuickInfo) { Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")); - return runCommand(new ReadReservoirLevelAndLastBolus()); + return runCommand(new ReadQuickInfoCommand()); } Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 5c232211ea..134d4e0622 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Objects; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; @@ -185,17 +186,18 @@ public class BolusCommand extends BaseCommand { if (cancelInProgress) { log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery"); - ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus(); - readReservoirLevelAndLastBolus.setScripter(scripter); - readReservoirLevelAndLastBolus.execute(); - Bolus lastBolus = readReservoirLevelAndLastBolus.result.history != null && !readReservoirLevelAndLastBolus.result.history.bolusHistory.isEmpty() - ? readReservoirLevelAndLastBolus.result.history.bolusHistory.get(0) + ReadQuickInfoCommand readQuickInfoCommand = new ReadQuickInfoCommand(); + readQuickInfoCommand.setScripter(scripter); + readQuickInfoCommand.execute(); + CommandResult quickInfoResult = readQuickInfoCommand.result; + Bolus lastBolus = quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty() + ? quickInfoResult.history.bolusHistory.get(0) : null; if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) { throw new CommandException("Unable to determine last bolus"); } log.debug("Stage 4: " + lastBolus.amount + " U delivered before cancellation according to history"); - result.delivered = lastBolus.amount; + this.result.delivered = lastBolus.amount; } else { log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered"); result.delivered = bolus; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java index 66017c6fb7..5e84878f70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadReservoirLevelAndLastBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java @@ -15,7 +15,7 @@ import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; -public class ReadReservoirLevelAndLastBolus extends BaseCommand { +public class ReadQuickInfoCommand extends BaseCommand { @Override public void execute() { scripter.verifyRootMenuIsDisplayed(); @@ -62,6 +62,6 @@ public class ReadReservoirLevelAndLastBolus extends BaseCommand { @Override public String toString() { - return "ReadReservoirLevelAndLastBolus{}"; + return "ReadQuickInfoCommand{}"; } } From 2468f23e97aa274c27dbba4f5ebbb55a974fb3df Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 19:05:39 +0100 Subject: [PATCH 27/54] ComboFragment: i18n last bolus. --- .../plugins/PumpCombo/ComboFragment.java | 17 ++++++----------- .../plugins/PumpCombo/ComboPlugin.java | 2 +- .../java/info/nightscout/utils/DateUtil.java | 5 +++++ app/src/main/res/values-bg/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-el/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-it/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 3 +-- app/src/main/res/values/strings.xml | 5 +++-- 14 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index cff810d382..3929dbcacd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -75,8 +75,6 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis public void onClick(View view) { switch (view.getId()) { case R.id.combo_refresh_button: - // TODO why is activity in ComboPump? - ComboPlugin.getPlugin().getPump().activity = MainApp.gs(R.string.combo_pump_action_refreshing); ConfigBuilderPlugin.getCommandQueue().readStatus("User request", null); break; case R.id.combo_alerts_button: @@ -213,19 +211,16 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { long agoMsc = System.currentTimeMillis() - bolus.timestamp; double bolusMinAgo = agoMsc / 60d / 1000d; - double bolusHoursAgo = agoMsc / 60d / 60d / 1000d; - // TODO i18n + String unit = MainApp.gs(R.string.treatments_wizard_unit_label); + String ago; if ((agoMsc < 60 * 1000)) { - lastBolusView.setText(String.format("%.1f U (now)", bolus.amount)); + ago = MainApp.gs(R.string.combo_pump_connected_now); } else if (bolusMinAgo < 60) { - lastBolusView.setText(String.format("%.1f U (%d min ago)", bolus.amount, (int) bolusMinAgo)); -// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, -// getString(R.string.minago, bolusMinAgo), DateUtil.timeString(bolus.timestamp))); + ago = DateUtil.minAgo(bolus.timestamp); } else { - lastBolusView.setText(String.format("%.1f U (%.1f h ago)", bolus.amount, bolusHoursAgo)); -// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, -// String.format("%.1f", bolusHoursAgo) + getString(R.string.hoursago), DateUtil.timeString(bolus.timestamp))); + ago = DateUtil.hourAgo(bolus.timestamp); } + lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago)); } else { lastBolusView.setText(""); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 4cb2778adc..84659053fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -633,7 +633,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (pumpHistoryChanged && percent > 110) { return new PumpEnactResult().success(false).enacted(false) - .comment("Rejecting high temp since calculation didn't consider recently changed pump history"); + .comment(MainApp.gs(R.string.combo_high_temp_rejected_due_to_pump_history_changes)); } int adjustedPercent = percent; diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index 86965621d2..1c3be368bf 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -127,6 +127,11 @@ public class DateUtil { return String.format(MainApp.sResources.getString(R.string.minago), mins); } + public static String hourAgo(long time) { + double hours = (System.currentTimeMillis() - time) / 1000d / 60 / 60; + return String.format(MainApp.sResources.getString(R.string.hoursago), hours); + } + private static LongSparseArray timeStrings = new LongSparseArray<>(); public static String timeStringFromSeconds(int seconds) { diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 312b02b69a..dca1f6b0af 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -224,7 +224,6 @@ IOB на помпата Инсулин за деня Последен болус: - ч по-рано Грешни входящи данни Неправилна стойност Презареди профил diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 751d559130..f3559c9fa4 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -206,7 +206,6 @@ Provedeno Licenční ujednání ROZUMÍM A PORVZUJI - h zpět Nenalezen bluetooth adaptér Procent Obnovit profil diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 13e2c34d65..a12e6c3389 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -222,7 +222,6 @@ Ich verstehe und stimme zu DAS PROGRAMM DARF NICHT FÜR MEDIZINISCHE ENTSCHEIDUNGEN BENUTZT WERDEN. ES GIBT IN DIESEM PROJEKT KEINE GEWÄHRLEISTUNG ODER GARANTIERTE UNTERSTÜTZUNG IN IRGENDEINER ART. WENN DU DICH ENTSCHEIDEST ES ZU NUTZEN, HÄNGT DIE QUALITÄT UND LEISTUNGSFÄHIGKEIT DIESES PROJEKTES VON DIR SELBST AB. ES WIRD \"WIE BESEHEN\" ZUR VERFÜGUNG GESTELLT. SOLLTE SICH DAS PROGRAMM ALS FEHLERHAFT ERWEISEN, ÜBERNEHMEN SIE DIE KOSTEN ALLER NOTWENDIGEN KRANKHEITSKOSTEN, SERVICELEISTUNGEN, REPARATUREN ODER KORREKTUREN. Fehler beim Aktualisieren der Basalrate - "h her " SMS-Kommunikator Erlaubte Telefonnummern Auf Pumpenergebnis warten diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index b9fd9bff78..bb0220a7db 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -220,7 +220,6 @@ IOB αντλίας "Μονάδες ανά ημέρα " Τελευταίο Bolus: - ώρες πριν Μη έγκυρα δεδομένα Η τιμή δεν μπήκε σωστά Ξαναφορτώστε το προφίλ diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index aa59862b20..fc0e8f8ce8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -214,7 +214,6 @@ Bomba IOB Unidades diarias Último bolo: - h antes Datos invalidos Valor no establecido correctamente Recargar Perfil diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 148b1aab2d..89f8ca917c 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -178,7 +178,6 @@ Stato Micro Glucosio Sensore - h fa Importa impstazioni da Inizzializzazione INS diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 3b62dffeab..233d7ce73c 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -225,7 +225,6 @@ 펌프 IOB 일 인슐린 총량 최근 식사주입: - 시간 전 사용할수 없는 입력 데이터 값이 제대로 설정되지 않았습니다 Reload profile diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index ca434cc35a..40f477e0c6 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -419,7 +419,6 @@ STOP INGEDRUKT Kalibratie Oude gegevens druk \"VERNIEUW\" a.u.b. - u geleden %d min geleden Berekening Dosis diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 1535d82c26..f0bebf2474 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -221,7 +221,6 @@ палец сенсор ВЕРХНЯЯ отметка - час. назад импортировать настройки из инициализация... ИНС diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b27b70da43..79e286e44e 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -206,9 +206,8 @@ Sensor HÖG markering timmar - h sedan Importera inställningar från - Startar... + Startar… Ogiltig profil !!! IOB Italienska diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cb9ca63a59..5d5f1f54e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -235,7 +235,7 @@ Pump IOB Daily units Last bolus - h ago + %dh ago Invalid input data Value not set properly Reload profile @@ -820,7 +820,7 @@ Activity No connection for %d min %d%% (%d min remaining) - %.1f U (%s, %s) + %.1f %s (%s) Initializing Disconnected Suspended due to error @@ -869,5 +869,6 @@ Reading basal profile The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested with less than tow minutes between them for safety (regardless of whether they were administered or not). Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the last two minutes. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute and same amount. + Rejecting high temp since calculation didn\'t consider recently changed pump history From 216359312a139c16399c9d61906a145cd64aef51 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 19:57:41 +0100 Subject: [PATCH 28/54] Minor non-code tweaks. --- README-Combo.md | 2 +- .../plugins/PumpCombo/ComboPlugin.java | 16 +++++++++++----- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README-Combo.md b/README-Combo.md index 9d3e52ddf7..3088aed778 100644 --- a/README-Combo.md +++ b/README-Combo.md @@ -86,7 +86,7 @@ Setup: Usage: - Keep in mind that this is not a product, esp. in the beginning the user needs to monitor and understand the system, its limitations and how it can fail. It is strongly advised NOT to use this system when the person - using is not able to fully understand the system. + using it is not able to fully understand the system. - This integration uses the same functionality which the meter provides that comes with the Combo. The meter allows to mirror the pump screen and forwards button presses to the pump. The connection to the pump and this forwarding is what the ruffy app does. A `scripter` components reads the screen diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 84659053fd..1f825a32b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -98,8 +98,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private Bolus lastRequestedBolus; - /** this is set whenever a connection to the pump is made and indicates if new history - records on the pump have been found */ + /** + * This is set whenever a connection to the pump is made and indicates if new history + * records on the pump have been found. This effectively blocks high temps and boluses + * till the queue is empty and the connection is shut down. The next reconnect will + * then reset this flag. This might cause some grief when attempting to bolus again within + * the 5s of idling it takes before the connecting is shut down. + */ private volatile boolean pumpHistoryChanged = false; private volatile long timestampOfLastKnownPumpBolusRecord; @@ -362,7 +367,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } - CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing),1, ruffyScripter::readPumpState); + CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing),1, ruffyScripter::readQuickInfo); if (!stateResult.success) { return; } @@ -394,8 +399,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf pump.initialized = true; MainApp.bus().post(new EventInitializationChanged()); - // ComboFragment updates state fully only after the pump has initialized, so read full state here - updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo)); + // ComboFragment updates state fully only after the pump has initialized, + // so force an update after initialization completed + updateLocalData(stateResult); } /** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d5f1f54e2..13a5221bd0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -854,7 +854,7 @@ Pump clock update needed History Warning - Long press this button to (re)read all history data and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time was significantly off or the basal profile was changed on the pump (which should never be done under normal circumstances). + Long press this button to force a full read of history and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time was significantly off or the basal profile was changed on the pump (which should never be done under normal circumstances). This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed From 33ad68d26a56b0aad3c4a2959f329661dee7a64e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 20:10:35 +0100 Subject: [PATCH 29/54] Fix string. --- app/src/main/res/values-de/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a12e6c3389..8d41ca768c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -725,7 +725,7 @@ Bolus (%.1f IE) wird abgegeben Bitte starte dein Telefon neu oder starte AndroidAPS in den System-Einstellungen neu. Andernfalls wird AndroidAPS nicht protokolliert (wichtig zum Nachverfolgen und Verifizieren, dass der Algorithmus korrekt funktioniert) TBR - %.1f IE (%s, %s) + %.1f %s (%s) Ein gleich großer Bolus wurde in der letzten Minute angefordert. Dies ist nicht zulässig, um ungewollte Doppelboli zu verhindern und vor eventuellen Bugs zu schützen. Historie wird gelesen Basalratenprofil wird aktualisiert From 1e22599979480fb64a52ca9796f939603a41b273 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 21:05:26 +0100 Subject: [PATCH 30/54] Fix format specifier. --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 13a5221bd0..895e275d16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -235,7 +235,7 @@ Pump IOB Daily units Last bolus - %dh ago + %.1fh ago Invalid input data Value not set properly Reload profile From a8cca7fcea81fa14284f36e1a6939749e6e880cb Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 30 Jan 2018 23:16:27 +0100 Subject: [PATCH 31/54] Remove duplication in ruffyscripter commands. --- .../ruffyscripter/commands/BaseCommand.java | 36 +++++++++++++++++++ .../commands/ReadHistoryCommand.java | 30 +--------------- .../commands/ReadQuickInfoCommand.java | 29 --------------- 3 files changed, 37 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java index 623a3bb51f..5cc3e98b23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BaseCommand.java @@ -1,11 +1,21 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; +import android.support.annotation.NonNull; + +import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; +import org.monkey.d.ruffy.ruffy.driver.display.MenuType; +import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType; +import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuDate; +import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; + +import java.util.Calendar; import java.util.Collections; import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; public abstract class BaseCommand implements Command { // RS will inject itself here @@ -46,4 +56,30 @@ public abstract class BaseCommand implements Command { public CommandResult getResult() { return result; } + + @NonNull + protected Bolus readBolusRecord() { + scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); + BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE); + boolean isValid = bolusType == BolusType.NORMAL; + Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS); + long recordDate = readRecordDate(); + return new Bolus(recordDate, bolus, isValid); + } + + protected long readRecordDate() { + MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE); + MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME); + + int year = Calendar.getInstance().get(Calendar.YEAR); + if (date.getMonth() > Calendar.getInstance().get(Calendar.MONTH) + 1) { + year -= 1; + } + Calendar calendar = Calendar.getInstance(); + calendar.set(year, date.getMonth() - 1, date.getDay(), time.getHour(), time.getMinute(), 0); + + // round to second + return calendar.getTimeInMillis() - calendar.getTimeInMillis() % 1000; + + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java index 4e94caf750..a558fbddcd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java @@ -20,8 +20,6 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHi import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; -// Note: TBRs are added to history only after they've completed running -// TODO remove duplication public class ReadHistoryCommand extends BaseCommand { private static Logger log = LoggerFactory.getLogger(ReadHistoryCommand.class); @@ -78,7 +76,7 @@ public class ReadHistoryCommand extends BaseCommand { } } - // tdd history + // tdd history (TBRs are added to history only after they've completed running) scripter.pressMenuKey(); scripter.verifyMenuIsDisplayed(MenuType.DAILY_DATA); if (request.tddHistory != PumpHistoryRequest.SKIP) { @@ -234,16 +232,6 @@ public class ReadHistoryCommand extends BaseCommand { } } - @NonNull - private Bolus readBolusRecord() { - scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); - BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE); - boolean isValid = bolusType == BolusType.NORMAL; - Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS); - long recordDate = readRecordDate(); - return new Bolus(recordDate, bolus, isValid); - } - private void readAlertRecords(long requestedTime) { int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD); int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD); @@ -277,22 +265,6 @@ public class ReadHistoryCommand extends BaseCommand { return new PumpAlert(recordDate, warningCode, errorCode, message); } - private long readRecordDate() { - MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE); - MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME); - - int year = Calendar.getInstance().get(Calendar.YEAR); - if (date.getMonth() > Calendar.getInstance().get(Calendar.MONTH) + 1) { - year -= 1; - } - Calendar calendar = Calendar.getInstance(); - calendar.set(year, date.getMonth() - 1, date.getDay(), time.getHour(), time.getMinute(), 0); - - // round to second - return calendar.getTimeInMillis() - calendar.getTimeInMillis() % 1000; - - } - @Override public String toString() { return "ReadHistoryCommand{" + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java index 5e84878f70..b1e80c4e61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadQuickInfoCommand.java @@ -1,15 +1,9 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.commands; -import android.support.annotation.NonNull; - import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; -import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType; -import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuDate; -import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; @@ -32,29 +26,6 @@ public class ReadQuickInfoCommand extends BaseCommand { result.success = true; } - // TODO deduplicate -> ReadHistoryCommand - @NonNull - private Bolus readBolusRecord() { - scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA); - BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE); - boolean isValid = bolusType == BolusType.NORMAL; - Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS); - long recordDate = readRecordDate(); - return new Bolus(recordDate, bolus, isValid); - } - - private long readRecordDate() { - MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE); - MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME); - - int currentMonth = new Date().getMonth() + 1; - int currentYear = new Date().getYear() + 1900; - if (currentMonth == 1 && date.getMonth() == 12) { - currentYear -= 1; - } - return new Date(currentYear - 1900, date.getMonth() - 1, date.getDay(), time.getHour(), time.getMinute()).getTime(); - } - @Override public boolean needsRunMode() { return false; From d08958e43f1bd60924433563dd2e255a8e7434ab Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 30 Jan 2018 23:16:45 +0100 Subject: [PATCH 32/54] Remove dead ruffyscripter code. --- .../PumpCombo/ruffyscripter/RuffyCommands.java | 8 -------- .../PumpCombo/ruffyscripter/RuffyScripter.java | 16 ---------------- 2 files changed, 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java index b6266ba829..80f57774ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyCommands.java @@ -45,13 +45,5 @@ public interface RuffyCommands { CommandResult getDateAndTime(); CommandResult setDateAndTime(); - - // TODO below methods are drafts - void requestPairing(); - - /** Send the key displayed on the pump during pairing/bonding. */ - void sendAuthKey(String key); - - void unpair(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 609c8195a9..8c012f5699 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -75,7 +75,6 @@ public class RuffyScripter implements RuffyCommands { @Override public void fail(String message) throws RemoteException { - // TODO 10-28 19:50:54.059 1426 1826 W RuffyScripter: [Thread-268] WARN [info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter$1:78]: Ruffy warns: no connection possible log.warn("Ruffy warns: " + message); } @@ -847,21 +846,6 @@ public class RuffyScripter implements RuffyCommands { throw new RuntimeException("Not supported"); } - @Override - public void requestPairing() { - throw new UnsupportedOperationException(); - } - - @Override - public void sendAuthKey(String key) { - throw new UnsupportedOperationException(); - } - - @Override - public void unpair() { - throw new UnsupportedOperationException(); - } - /** * Confirms and dismisses the given alert if it's raised before the timeout */ From ecd16c26b8171b4208cbac6a690e00bc3279d570 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:04:15 +0100 Subject: [PATCH 33/54] ComboFragment: disable buttons when running. --- .../plugins/PumpCombo/ComboFragment.java | 286 ++++++++++-------- 1 file changed, 167 insertions(+), 119 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 3929dbcacd..54a88cd703 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -21,6 +21,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; +import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.events.EventQueueChanged; import info.nightscout.utils.DateUtil; @@ -71,11 +72,24 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis return view; } + private void runOnUiThread(Runnable action) { + Activity activity = getActivity(); + if (activity != null) { + activity.runOnUiThread(action); + } + } + @Override public void onClick(View view) { switch (view.getId()) { case R.id.combo_refresh_button: - ConfigBuilderPlugin.getCommandQueue().readStatus("User request", null); + refreshButton.setEnabled(false); + ConfigBuilderPlugin.getCommandQueue().readStatus("User request", new Callback() { + @Override + public void run() { + runOnUiThread(() -> refreshButton.setEnabled(true)); + } + }); break; case R.id.combo_alerts_button: ComboAlertHistoryDialog ehd = new ComboAlertHistoryDialog(); @@ -87,24 +101,60 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis break; case R.id.combo_full_history_button: AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(R.string.combo_warning); builder.setMessage(R.string.combo_read_full_history_info); builder.show(); break; } } + // TODO clean up when when queuing @Override public boolean onLongClick(View view) { switch (view.getId()) { case R.id.combo_alerts_button: - new Thread(() -> ComboPlugin.getPlugin().readAlertData()).start(); + alertsButton.setEnabled(false); + tddsButton.setEnabled(false); + fullHistoryButton.setEnabled(false); + new Thread(() -> ComboPlugin.getPlugin().readAlertData(new Callback() { + @Override + public void run() { + runOnUiThread(() -> { + alertsButton.setEnabled(true); + tddsButton.setEnabled(true); + fullHistoryButton.setEnabled(true); + }); + } + })).start(); return true; case R.id.combo_tdds_button: - new Thread(() -> ComboPlugin.getPlugin().readTddData()).start(); + alertsButton.setEnabled(false); + tddsButton.setEnabled(false); + fullHistoryButton.setEnabled(false); + new Thread(() -> ComboPlugin.getPlugin().readTddData(new Callback() { + @Override + public void run() { + runOnUiThread(() -> { + alertsButton.setEnabled(true); + tddsButton.setEnabled(true); + fullHistoryButton.setEnabled(true); + }); + } + })).start(); return true; case R.id.combo_full_history_button: - new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start(); + alertsButton.setEnabled(false); + tddsButton.setEnabled(false); + fullHistoryButton.setEnabled(false); + new Thread(() -> ComboPlugin.getPlugin().readAllPumpData(new Callback() { + @Override + public void run() { + runOnUiThread(() -> { + alertsButton.setEnabled(true); + tddsButton.setEnabled(true); + fullHistoryButton.setEnabled(true); + }); + } + })).start(); return true; } return false; @@ -122,123 +172,121 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis public void updateGUI() { - Activity fragmentActivity = getActivity(); - if (fragmentActivity != null) - fragmentActivity.runOnUiThread(() -> { - ComboPlugin plugin = ComboPlugin.getPlugin(); + runOnUiThread(() -> { + ComboPlugin plugin = ComboPlugin.getPlugin(); - // state - stateView.setText(plugin.getStateSummary()); - PumpState ps = plugin.getPump().state; - if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY - || ps.activeAlert != null && ps.activeAlert.errorCode != null) { - stateView.setTextColor(Color.RED); - stateView.setTypeface(null, Typeface.BOLD); - } else if (plugin.getPump().state.suspended - || ps.activeAlert != null && ps.activeAlert.warningCode != null) { - stateView.setTextColor(Color.YELLOW); - stateView.setTypeface(null, Typeface.BOLD); + // state + stateView.setText(plugin.getStateSummary()); + PumpState ps = plugin.getPump().state; + if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY + || ps.activeAlert != null && ps.activeAlert.errorCode != null) { + stateView.setTextColor(Color.RED); + stateView.setTypeface(null, Typeface.BOLD); + } else if (plugin.getPump().state.suspended + || ps.activeAlert != null && ps.activeAlert.warningCode != null) { + stateView.setTextColor(Color.YELLOW); + stateView.setTypeface(null, Typeface.BOLD); + } else { + stateView.setTextColor(Color.WHITE); + stateView.setTypeface(null, Typeface.NORMAL); + } + + // activity + String activity = plugin.getPump().activity; + activityView.setText(activity != null ? activity : ""); + + if (plugin.isInitialized()) { + refreshButton.setVisibility(View.VISIBLE); + alertsButton.setVisibility(View.VISIBLE); + tddsButton.setVisibility(View.VISIBLE); + fullHistoryButton.setVisibility(View.VISIBLE); + + // battery + batteryView.setTextSize(20); + if (ps.batteryState == PumpState.EMPTY) { + batteryView.setText("{fa-battery-empty}"); + batteryView.setTextColor(Color.RED); + } else if (ps.batteryState == PumpState.LOW) { + batteryView.setText("{fa-battery-quarter}"); + batteryView.setTextColor(Color.YELLOW); } else { - stateView.setTextColor(Color.WHITE); - stateView.setTypeface(null, Typeface.NORMAL); + batteryView.setText("{fa-battery-full}"); + batteryView.setTextColor(Color.WHITE); } - // activity - String activity = plugin.getPump().activity; - activityView.setText(activity != null ? activity : ""); - - if (plugin.isInitialized()) { - refreshButton.setVisibility(View.VISIBLE); - alertsButton.setVisibility(View.VISIBLE); - tddsButton.setVisibility(View.VISIBLE); - fullHistoryButton.setVisibility(View.VISIBLE); - - // battery - batteryView.setTextSize(20); - if (ps.batteryState == PumpState.EMPTY) { - batteryView.setText("{fa-battery-empty}"); - batteryView.setTextColor(Color.RED); - } else if (ps.batteryState == PumpState.LOW) { - batteryView.setText("{fa-battery-quarter}"); - batteryView.setTextColor(Color.YELLOW); - } else { - batteryView.setText("{fa-battery-full}"); - batteryView.setTextColor(Color.WHITE); - } - - // reservoir - int reservoirLevel = plugin.getPump().reservoirLevel; - if (reservoirLevel != -1) { - reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); - } else if (ps.insulinState == PumpState.LOW) { - reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low)); - } else if (ps.insulinState == PumpState.EMPTY) { - reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty)); - } else { - reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal)); - } - - if (ps.insulinState == PumpState.UNKNOWN) { - reservoirView.setTextColor(Color.WHITE); - reservoirView.setTypeface(null, Typeface.NORMAL); - } else if (ps.insulinState == PumpState.LOW) { - reservoirView.setTextColor(Color.YELLOW); - reservoirView.setTypeface(null, Typeface.BOLD); - } else if (ps.insulinState == PumpState.EMPTY) { - reservoirView.setTextColor(Color.RED); - reservoirView.setTypeface(null, Typeface.BOLD); - } else { - reservoirView.setTextColor(Color.WHITE); - reservoirView.setTypeface(null, Typeface.NORMAL); - } - - // last connection - String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulCmdTime); - long min = (System.currentTimeMillis() - plugin.getPump().lastSuccessfulCmdTime) / 1000 / 60; - if (plugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) { - lastConnectionView.setText(R.string.combo_pump_connected_now); - lastConnectionView.setTextColor(Color.WHITE); - } else if (plugin.getPump().lastSuccessfulCmdTime + 30 * 60 * 1000 < System.currentTimeMillis()) { - lastConnectionView.setText(MainApp.gs(R.string.combo_no_pump_connection, min)); - lastConnectionView.setTextColor(Color.RED); - } else { - lastConnectionView.setText(minAgo); - lastConnectionView.setTextColor(Color.WHITE); - } - - // last bolus - Bolus bolus = plugin.getPump().lastBolus; - if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { - long agoMsc = System.currentTimeMillis() - bolus.timestamp; - double bolusMinAgo = agoMsc / 60d / 1000d; - String unit = MainApp.gs(R.string.treatments_wizard_unit_label); - String ago; - if ((agoMsc < 60 * 1000)) { - ago = MainApp.gs(R.string.combo_pump_connected_now); - } else if (bolusMinAgo < 60) { - ago = DateUtil.minAgo(bolus.timestamp); - } else { - ago = DateUtil.hourAgo(bolus.timestamp); - } - lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago)); - } else { - lastBolusView.setText(""); - } - - // base basal rate - baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); - - // TBR - String tbrStr = ""; - if (ps.tbrPercent != -1 && ps.tbrPercent != 100) { - long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60; - long remaining = ps.tbrRemainingDuration - minSinceRead; - if (remaining >= 0) { - tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining); - } - } - tempBasalText.setText(tbrStr); + // reservoir + int reservoirLevel = plugin.getPump().reservoirLevel; + if (reservoirLevel != -1) { + reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label)); + } else if (ps.insulinState == PumpState.LOW) { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low)); + } else if (ps.insulinState == PumpState.EMPTY) { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty)); + } else { + reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal)); } - }); + + if (ps.insulinState == PumpState.UNKNOWN) { + reservoirView.setTextColor(Color.WHITE); + reservoirView.setTypeface(null, Typeface.NORMAL); + } else if (ps.insulinState == PumpState.LOW) { + reservoirView.setTextColor(Color.YELLOW); + reservoirView.setTypeface(null, Typeface.BOLD); + } else if (ps.insulinState == PumpState.EMPTY) { + reservoirView.setTextColor(Color.RED); + reservoirView.setTypeface(null, Typeface.BOLD); + } else { + reservoirView.setTextColor(Color.WHITE); + reservoirView.setTypeface(null, Typeface.NORMAL); + } + + // last connection + String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulCmdTime); + long min = (System.currentTimeMillis() - plugin.getPump().lastSuccessfulCmdTime) / 1000 / 60; + if (plugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) { + lastConnectionView.setText(R.string.combo_pump_connected_now); + lastConnectionView.setTextColor(Color.WHITE); + } else if (plugin.getPump().lastSuccessfulCmdTime + 30 * 60 * 1000 < System.currentTimeMillis()) { + lastConnectionView.setText(MainApp.gs(R.string.combo_no_pump_connection, min)); + lastConnectionView.setTextColor(Color.RED); + } else { + lastConnectionView.setText(minAgo); + lastConnectionView.setTextColor(Color.WHITE); + } + + // last bolus + Bolus bolus = plugin.getPump().lastBolus; + if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { + long agoMsc = System.currentTimeMillis() - bolus.timestamp; + double bolusMinAgo = agoMsc / 60d / 1000d; + String unit = MainApp.gs(R.string.treatments_wizard_unit_label); + String ago; + if ((agoMsc < 60 * 1000)) { + ago = MainApp.gs(R.string.combo_pump_connected_now); + } else if (bolusMinAgo < 60) { + ago = DateUtil.minAgo(bolus.timestamp); + } else { + ago = DateUtil.hourAgo(bolus.timestamp); + } + lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago)); + } else { + lastBolusView.setText(""); + } + + // base basal rate + baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); + + // TBR + String tbrStr = ""; + if (ps.tbrPercent != -1 && ps.tbrPercent != 100) { + long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60; + long remaining = ps.tbrRemainingDuration - minSinceRead; + if (remaining >= 0) { + tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining); + } + } + tempBasalText.setText(tbrStr); + } + }); } -} +} \ No newline at end of file From c7cccf32204be9258a8f27804785a5e305453741 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:06:04 +0100 Subject: [PATCH 34/54] Read quick info first when checking history. --- .../plugins/PumpCombo/ComboPlugin.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 1f825a32b6..64dd7a6661 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -8,21 +8,10 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; -import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tbr; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -44,6 +33,18 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BasalProfile; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.BolusProgressReporter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.CommandResult; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpWarningCodes; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyCommands; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.RuffyScripter; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.WarningOrErrorCode; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; +import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; +import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; /** @@ -350,9 +351,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!pump.initialized) { initializePump(); } else { - runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readQuickInfo); - // note that since the history is checked upon every connect, the above already updated - // the DB with any changed history records + // trigger a connect, which will update state and check history + runCommand(null, 3, ruffyScripter::readPumpState); } } @@ -367,7 +367,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } - CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing),1, ruffyScripter::readQuickInfo); + // trigger a connect, which will update state and check history + CommandResult stateResult = runCommand(null,1, ruffyScripter::readPumpState); if (!stateResult.success) { return; } @@ -1060,8 +1061,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf ruffyScripter.disconnect(); } - private void checkHistory() { - long start = System.currentTimeMillis(); + /** + * Reads QuickInfo to update reservoir level and determine if new boluses exist on the pump + * and if so, queries the history for all new records. + * + * @return null on success or the failed command result + */ + private CommandResult checkHistory() { + CommandResult quickInfoResult = runCommand(MainApp.gs(R.string.combo_activity_checking_for_history_changes), 3, ruffyScripter::readQuickInfo); + if (quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty() + && quickInfoResult.history.bolusHistory.get(0).timestamp == timestampOfLastKnownPumpBolusRecord) { + return null; + } // TODO maybe optimize for the default case where no new records exists by checking quick info; // and only read My Data history when quick info shows a new record From 3db7aedb06afad16ab19fed74fde636af4113985 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:09:38 +0100 Subject: [PATCH 35/54] Fix activity indicator during on-connect-checks. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 64dd7a6661..6a34805bd9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -735,17 +735,15 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf /** * Runs a command, sets an activity if provided, retries if requested and updates fields * concerned with last connection. - * NO history, reservoir level fields are updated, this make be done separately if desired. + * Local cache (history, reservoir level, pump state) are updated via #updateLocalData() + * if returned by a command. */ private synchronized CommandResult runCommand(String activity, int retries, CommandExecution commandExecution) { CommandResult commandResult; try { - if (activity != null) { - pump.activity = activity; - MainApp.bus().post(new EventComboPumpUpdateGUI()); - } - if (!ruffyScripter.isConnected()) { + pump.activity = MainApp.gs(R.string.combo_activity_checking_pump_state); + MainApp.bus().post(new EventComboPumpUpdateGUI()); CommandResult preCheckError = runOnConnectChecks(); if (preCheckError != null) { updateLocalData(preCheckError); @@ -753,6 +751,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } + if (activity != null) { + pump.activity = activity; + MainApp.bus().post(new EventComboPumpUpdateGUI()); + } + commandResult = commandExecution.execute(); if (!commandResult.success && retries > 0) { From 34db941c29ce294cfebc7250a721b9c3b41d86bc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:10:46 +0100 Subject: [PATCH 36/54] Remove unused code to import TBRs from the pump. --- .../plugins/PumpCombo/ComboPlugin.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 6a34805bd9..9aff14af68 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -997,7 +997,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) { boolean updated = false; - // Bolus for (Bolus pumpBolus : history.bolusHistory) { DetailedBolusInfo dbi = new DetailedBolusInfo(); dbi.date = calculateFakeBolusDate(pumpBolus); @@ -1009,21 +1008,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf updated = true; } } - - // TBRs - for (Tbr pumpTbr : history.tbrHistory) { - TemporaryBasal temporaryBasal = new TemporaryBasal(); - temporaryBasal.date = pumpTbr.timestamp; - temporaryBasal.pumpId = pumpTbr.timestamp + pumpTbr.percent; - temporaryBasal.source = Source.PUMP; - temporaryBasal.percentRate = pumpTbr.percent; - temporaryBasal.durationInMinutes = pumpTbr.duration; - temporaryBasal.isAbsolute = false; - if (MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal)) { - updated = true; - } - } - return updated; } From e790c87940e900a41ff7ee163439e31344d26c05 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:12:04 +0100 Subject: [PATCH 37/54] Cleanups and strings. --- .../plugins/PumpCombo/ComboPlugin.java | 62 ++++++++++++------- app/src/main/res/values/strings.xml | 6 +- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 9aff14af68..54cf5406b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1021,30 +1021,46 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return pumpBolus.timestamp + (Math.min((int) (pumpBolus.amount - 0.1) * 10 * 1000, 59 * 1000)); } - // TODO queue - void readTddData() { - readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)); + // TODO use queue once ready + void readTddData(Callback post) { +// ConfigBuilderPlugin.getCommandQueue().custom(new Callback() { +// @Override +// public void run() { + readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)); +// } +// }, post); + post.run(); ruffyScripter.disconnect(); } - // TODO queue - void readAlertData() { - readHistory(new PumpHistoryRequest().pumpErrorHistory(PumpHistoryRequest.FULL)); + // TODO use queue once ready + void readAlertData(Callback post) { +// ConfigBuilderPlugin.getCommandQueue().custom(new Callback() { +// @Override +// public void run() { + readHistory(new PumpHistoryRequest().pumpErrorHistory(PumpHistoryRequest.FULL)); +// } +// }, post); + post.run(); ruffyScripter.disconnect(); } - // TODO queue - void readAllPumpData() { - readHistory(new PumpHistoryRequest() - .bolusHistory(PumpHistoryRequest.FULL) -// .tbrHistory(PumpHistoryRequest.FULL) - .pumpErrorHistory(PumpHistoryRequest.FULL) - .tddHistory(PumpHistoryRequest.FULL) - ); - CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); - if (readBasalResult.success) { - pump.basalProfile = readBasalResult.basalProfile; - } + // TODO use queue once ready + void readAllPumpData(Callback post) { +// ConfigBuilderPlugin.getCommandQueue().custom(new Callback() { +// @Override +// public void run() { + readHistory(new PumpHistoryRequest() + .bolusHistory(PumpHistoryRequest.FULL) + .pumpErrorHistory(PumpHistoryRequest.FULL) + .tddHistory(PumpHistoryRequest.FULL)); + CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); + if (readBasalResult.success) { + pump.basalProfile = readBasalResult.basalProfile; + } +// } +// }, post); + post.run(); ruffyScripter.disconnect(); } @@ -1061,13 +1077,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return null; } - // TODO maybe optimize for the default case where no new records exists by checking quick info; - // and only read My Data history when quick info shows a new record + // OPTIMIZE this reads the entire history on start, so this could be optimized by persisting + // `timestampOfLastKnownPumpBolusRecord`, though this should be thought through, to make sure + // all scenarios are covered CommandResult historyResult = runCommand(MainApp.gs(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(new PumpHistoryRequest() .bolusHistory(timestampOfLastKnownPumpBolusRecord))); if (!historyResult.success) { - return; + return historyResult; } pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history); @@ -1076,8 +1093,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf timestampOfLastKnownPumpBolusRecord = historyResult.history.bolusHistory.get(0).timestamp; } - long end = System.currentTimeMillis(); - log.debug("History check took: " + ((end - start) / 1000) + "s"); + return null; } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 895e275d16..b4e18a0160 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -854,7 +854,7 @@ Pump clock update needed History Warning - Long press this button to force a full read of history and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time was significantly off or the basal profile was changed on the pump (which should never be done under normal circumstances). + Long press this button to force a full read of history and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time changed significantly or the pump was replaced. This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed @@ -870,5 +870,9 @@ The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested with less than tow minutes between them for safety (regardless of whether they were administered or not). Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the last two minutes. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute and same amount. Rejecting high temp since calculation didn\'t consider recently changed pump history + Refreshing pump state + The basal rate on the pump has changed and will be updated soon + Basal rate changed on pump, but reading it failed + Checking for history changes From 154902acdc18ffcf8eff3e808d328981fc83360c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:12:28 +0100 Subject: [PATCH 38/54] Fix ReadHistoryCommand not reading errors, TDDs. --- .../ruffyscripter/commands/ReadHistoryCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java index a558fbddcd..1cf5b86e28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/ReadHistoryCommand.java @@ -58,9 +58,9 @@ public class ReadHistoryCommand extends BaseCommand { } } - if (request.pumpErrorHistory == PumpHistoryRequest.SKIP - && request.tddHistory == PumpHistoryRequest.SKIP - && request.tbrHistory == PumpHistoryRequest.SKIP) { + if (request.pumpErrorHistory != PumpHistoryRequest.SKIP + || request.tddHistory != PumpHistoryRequest.SKIP + || request.tbrHistory != PumpHistoryRequest.SKIP) { // error history scripter.pressMenuKey(); scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA); From 6981c0fec6ad58cacb586e741aa13b4a72263987 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:30:53 +0100 Subject: [PATCH 39/54] Pump needs rest. (cherry picked from commit 2e88fb9) --- .../androidaps/plugins/PumpCombo/ComboFragment.java | 10 +++++++++- app/src/main/res/layout/combopump_fragment.xml | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 54a88cd703..df9b6e84f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -14,6 +14,8 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; +import org.apache.commons.lang3.StringUtils; + import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.PumpState; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.MainApp; @@ -193,7 +195,13 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis // activity String activity = plugin.getPump().activity; - activityView.setText(activity != null ? activity : ""); + if (StringUtils.isNotEmpty(activity)) { + activityView.setTextSize(14); + activityView.setText(activity); + } else { + activityView.setTextSize(18); + activityView.setText("{fa-bed}"); + } if (plugin.isInitialized()) { refreshButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index 29d8659d53..3aaddeea51 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -87,7 +87,7 @@ android:text=":" android:textSize="14sp" /> - Date: Wed, 31 Jan 2018 00:55:30 +0100 Subject: [PATCH 40/54] Fix pump state display during init. (cherry picked from commit 3967c4b) --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 54cf5406b8..789474f7d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -151,13 +151,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf PumpState ps = pump.state; if (!validBasalRateProfileSelectedOnPump) { return MainApp.gs(R.string.loopdisabled); + } else if (!pump.initialized) { + return MainApp.gs(R.string.combo_pump_state_initializing); } else if (ps.activeAlert != null) { return ps.activeAlert.errorCode != null ? "E" + ps.activeAlert.errorCode + ": " + ps.activeAlert.message : "W" + ps.activeAlert.warningCode + ": " + ps.activeAlert.message; - } else if (ps.menu == null) - return MainApp.gs(R.string.combo_pump_state_initializing); - else if (ps.suspended && (ps.batteryState == PumpState.EMPTY || ps.insulinState == PumpState.EMPTY)) + } else if (ps.suspended && (ps.batteryState == PumpState.EMPTY || ps.insulinState == PumpState.EMPTY)) return MainApp.gs(R.string.combo_pump_state_suspended_due_to_error); else if (ps.suspended) return MainApp.gs(R.string.combo_pump_state_suspended_by_user); From 6108e9f17a1f0432781b3880e329312fc3afeb18 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 00:10:08 +0100 Subject: [PATCH 41/54] Fix basal rate check. --- .../plugins/PumpCombo/ComboPlugin.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 789474f7d0..3b6cb94a2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -829,7 +829,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf checkAndResolveTbrMismatch(preCheckResult.state); checkPumpTime(preCheckResult.state); checkBasalRate(preCheckResult.state); - checkHistory(); + CommandResult historyCheckError = checkHistory(); + if (historyCheckError != null) { + return historyCheckError; + } return null; } @@ -840,12 +843,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // no cached profile to compare against return; } + if (state.unsafeUsageDetected != PumpState.SAFE_USAGE) { + // with an extended or multiwavo bolus running it's not (easily) possible + // to infer base basal rate and not supported either. Also don't compare + // if set basal rate profile is != -1. + return; + } if (state.tbrActive && state.tbrPercent == 0) { // can't infer base basal rate if TBR is 0 return; } double pumpBasalRate = state.tbrActive - ? state.basalRate * 100 / state.tbrPercent + ? Math.round(state.basalRate * 100 / state.tbrPercent * 100) / 100d : state.basalRate; int pumpHour = new Date(state.pumpTime).getHours(); int phoneHour = new Date().getHours(); @@ -854,10 +863,15 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return; } - if (pumpBasalRate != getBaseBasalRate()) { + if (Math.abs(pumpBasalRate - getBaseBasalRate()) > 0.001) { CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); if (readBasalResult.success) { pump.basalProfile = readBasalResult.basalProfile; + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_warning_pump_basal_rate_changed), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } else { + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_failure_reading_changed_basal_rate), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); } } } From 4defd40023f074beab8cbae33d53c31046a5558d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 01:34:58 +0100 Subject: [PATCH 42/54] RuffyScripter: clean up answers. (cherry picked from commit 0c30e1b) --- .../ruffyscripter/RuffyScripter.java | 60 ++++++++++++++----- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 8c012f5699..16fbee25cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -165,8 +165,9 @@ public class RuffyScripter implements RuffyCommands { if (!boundSucceeded) { log.error("No connection to ruffy. Pump control unavailable."); } else { - Answers.getInstance().logCustom(new CustomEvent("RuffyScripterInit") - .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION)); + Answers.getInstance().logCustom(new CustomEvent("ComboScripterInit") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); } } @@ -218,10 +219,14 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult readQuickInfo() { if (readQuickInfo) { - Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboReadQuickInfoCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new ReadQuickInfoCommand()); } - Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new ReadHistoryCommand(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST))); } @@ -421,6 +426,8 @@ public class RuffyScripter implements RuffyCommands { } log.debug("Recovery from connection loss " + (connected ? "succeeded" : "failed")); Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromConnectionLoss") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) .putCustomAttribute("activeCommand", "" + activeCmd) .putCustomAttribute("success", connected ? "true" : "else")); return connected; @@ -434,6 +441,8 @@ public class RuffyScripter implements RuffyCommands { Menu menu = this.currentMenu; if (menu == null) { Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailure") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) .putCustomAttribute("activeCommand", "" + activeCmd) .putCustomAttribute("success", "false")); return new PumpState(); @@ -449,11 +458,16 @@ public class RuffyScripter implements RuffyCommands { } try { PumpState pumpState = readPumpStateInternal(); - Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailureSucceded") - .putCustomAttribute("activeCommand", "" + activeCmd)); + Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailure") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) + .putCustomAttribute("activeCommand", "" + activeCmd) + .putCustomAttribute("success", "true")); return pumpState; } catch (Exception e) { Answers.getInstance().logCustom(new CustomEvent("ComboRecoveryFromCommandFailure") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) .putCustomAttribute("activeCommand", "" + activeCmd) .putCustomAttribute("success", "false")); log.debug("Reading pump state during recovery failed", e); @@ -478,6 +492,8 @@ public class RuffyScripter implements RuffyCommands { while (initialUpdateTime == menuLastUpdated) { if (System.currentTimeMillis() > timeoutExpired) { Answers.getInstance().logCustom(new CustomEvent("ComboConnectTimeout") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) .putCustomAttribute("activeCommand", "" + activeCmd) .putCustomAttribute("previousCommand", previousCommand)); throw new CommandException("Timeout connecting to pump"); @@ -786,14 +802,18 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter) { - Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new BolusCommand(amount, bolusProgressReporter)); } @Override public void cancelBolus() { if (activeCmd instanceof BolusCommand) { - Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmdCancel")); + Answers.getInstance().logCustom(new CustomEvent("ComboBolusCmdCancel") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); ((BolusCommand) activeCmd).requestCancellation(); } else { log.error("cancelBolus called, but active command is not a bolus:" + activeCmd); @@ -802,37 +822,49 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult setTbr(int percent, int duration) { - Answers.getInstance().logCustom(new CustomEvent("ComboSetTbrCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboSetTbrCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new SetTbrCommand(percent, duration)); } @Override public CommandResult cancelTbr() { - Answers.getInstance().logCustom(new CustomEvent("ComboCancelTbrCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboCancelTbrCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new CancelTbrCommand()); } @Override public CommandResult confirmAlert(int warningCode) { - Answers.getInstance().logCustom(new CustomEvent("ComboConfirmAlertCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboConfirmAlertCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new ConfirmAlertCommand(warningCode)); } @Override public CommandResult readHistory(PumpHistoryRequest request) { - Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboReadHistoryCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new ReadHistoryCommand(request)); } @Override public CommandResult readBasalProfile() { - Answers.getInstance().logCustom(new CustomEvent("ComboReadBasalProfileCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboReadBasalProfileCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new ReadBasalProfileCommand()); } @Override public CommandResult setBasalProfile(BasalProfile basalProfile) { - Answers.getInstance().logCustom(new CustomEvent("ComboSetBasalProfileCmd")); + Answers.getInstance().logCustom(new CustomEvent("ComboSetBasalProfileCmd") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION)); return runCommand(new SetBasalProfileCommand(basalProfile)); } From 8be8f961aebcfb04702b6fe8c50bbbb0b87def5d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 02:01:06 +0100 Subject: [PATCH 43/54] Answer ruffy warnings. (cherry picked from commit b73a822) --- .../plugins/PumpCombo/ruffyscripter/RuffyScripter.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 16fbee25cd..8e452c8803 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -69,13 +69,21 @@ public class RuffyScripter implements RuffyCommands { @Override public void log(String message) throws RemoteException { if (log.isTraceEnabled()) { - log.debug("Ruffy says: " + message); + log.trace("Ruffy says: " + message); } } @Override public void fail(String message) throws RemoteException { log.warn("Ruffy warns: " + message); + if (message.startsWith("no connection possible")) + Answers.getInstance().logCustom(new CustomEvent("ComboRuffyWarning").putCustomAttribute("message", "no connection possible")); + else if (message.startsWith("Error sending keep alive while rtModeRunning is still true")) + Answers.getInstance().logCustom(new CustomEvent("ComboRuffyWarning").putCustomAttribute("message", "Error sending keep alive while rtModeRunning is still true")); + else if (message.startsWith("Error sending keep alive. rtModeRunning is false, so this is most likely a race condition during disconnect")) + Answers.getInstance().logCustom(new CustomEvent("ComboRuffyWarning").putCustomAttribute("message", "Error sending keep alive. rtModeRunning is false, so this is most likely a race condition during disconnect")); + else + Answers.getInstance().logCustom(new CustomEvent("ComboRuffyWarning").putCustomAttribute("message", message.substring(0, 98))); } @Override From 47ce9d85619dbfab4e6a74dc0ff2143a6f3fb03b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 11:56:12 +0100 Subject: [PATCH 44/54] Revert "Set custom version." This reverts commit cd7af6c5fe7a411d5da626adae59452145ce0eda. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 32e38b453e..e1a030130c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { targetSdkVersion 23 multiDexEnabled true versionCode 1500 - version "1.57-combo-experimental" + version "1.57-combo-csv2-test" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() From 5bb8bdde3e6db9affb6fcf23f4f4c236fcada8c2 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 11:59:30 +0100 Subject: [PATCH 45/54] BolusCommand: don't check pump history on cancel, ComboPlugin.deliverBolus has that responsibility now. --- .../ruffyscripter/commands/BolusCommand.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 134d4e0622..0e0ad9c9b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -185,19 +185,8 @@ public class BolusCommand extends BaseCommand { } if (cancelInProgress) { - log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery"); - ReadQuickInfoCommand readQuickInfoCommand = new ReadQuickInfoCommand(); - readQuickInfoCommand.setScripter(scripter); - readQuickInfoCommand.execute(); - CommandResult quickInfoResult = readQuickInfoCommand.result; - Bolus lastBolus = quickInfoResult.history != null && !quickInfoResult.history.bolusHistory.isEmpty() - ? quickInfoResult.history.bolusHistory.get(0) - : null; - if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) { - throw new CommandException("Unable to determine last bolus"); - } - log.debug("Stage 4: " + lastBolus.amount + " U delivered before cancellation according to history"); - this.result.delivered = lastBolus.amount; + log.debug("Stage 4: bolus was cancelled, with unknown amount delivered"); + this.result.delivered = -1; } else { log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered"); result.delivered = bolus; From 344984e2012735eaeed2ef53f091d238a06f5425 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 12:36:41 +0100 Subject: [PATCH 46/54] Fix recording partially delivered boluses. --- .../plugins/PumpCombo/ComboPlugin.java | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 3b6cb94a2b..0eea734a65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -8,7 +8,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -539,6 +538,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // a connection problem, ruffyscripter tried to recover and we can just check the // history below to see what was actually delivered + // get last bolus from pump histqry for verification CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) @@ -547,42 +547,34 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty() ? postBolusStateResult.history.bolusHistory.get(0) : null; - if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) { - return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); + + // no bolus delivered? + if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus) ) { + if (cancelBolus) { + return new PumpEnactResult().success(true).enacted(false); + } else { + return new PumpEnactResult() + .success(false) + .enacted(false) + .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); + } } + + // at least some insulin delivered, so add it to treatments + if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus)) + return new PumpEnactResult().success(false).enacted(true) + .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); + + // partial bolus was delivered if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) { + if (cancelBolus) { + return new PumpEnactResult().success(true).enacted(true); + } return new PumpEnactResult().success(false).enacted(true) .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered)); } - // seems we actually made it this far, let's add a treatment record - detailedBolusInfo.date = calculateFakeBolusDate(lastPumpBolus); - detailedBolusInfo.pumpId = calculateFakeBolusDate(lastPumpBolus); - detailedBolusInfo.source = Source.PUMP; - detailedBolusInfo.insulin = lastPumpBolus.amount; - try { - boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); - if (!treatmentCreated) { - if (detailedBolusInfo.isSMB) { - Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - return new PumpEnactResult().success(false).enacted(true) - .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); - } - return new PumpEnactResult().success(false).enacted(true) - .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); - } - } catch (Exception e) { - log.error("Adding treatment record failed", e); - if (detailedBolusInfo.isSMB) { - Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - } - return new PumpEnactResult().success(false).enacted(true) - .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); - } - + // full bolus was delivered successfully return new PumpEnactResult() .success(true) .enacted(lastPumpBolus.amount > 0) @@ -596,6 +588,37 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } + /** + * Updates a DetailedBolusInfo from a pump bolus and adds it as a Treatment to the DB. + * Handles edge cases when dates aren't unique which are extremely unlikely to occur, + * but if they do, the user should be warned since a bolus will be missing from calculations. + */ + private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { + detailedBolusInfo.date = calculateFakeBolusDate(lastPumpBolus); + detailedBolusInfo.pumpId = calculateFakeBolusDate(lastPumpBolus); + detailedBolusInfo.source = Source.PUMP; + detailedBolusInfo.insulin = lastPumpBolus.amount; + try { + boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + if (!treatmentCreated) { + log.error("Adding treatment record overrode an existing necord: " + detailedBolusInfo); + if (detailedBolusInfo.isSMB) { + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } + return false; + } + } catch (Exception e) { + log.error("Adding treatment record failed", e); + if (detailedBolusInfo.isSMB) { + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } + return false; + } + return true; + } + @Override public void stopBolusDelivering() { if (bolusInProgress) { From 1aee181f6269210eef3436a18ab7b2ebfc78ca2d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 12:54:25 +0100 Subject: [PATCH 47/54] RuffyScripter: fix reading basal rate when no TBR is active --- .../plugins/PumpCombo/ruffyscripter/RuffyScripter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index 8e452c8803..cdbb40c413 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -557,6 +557,8 @@ public class RuffyScripter implements RuffyCommands { state.tbrPercent = displayedTbr.intValue(); MenuTime durationMenuTime = ((MenuTime) menu.getAttribute(MenuAttribute.RUNTIME)); state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute(); + } + if (menu.attributes().contains(MenuAttribute.BASAL_RATE)) { state.basalRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE)); } if (menu.attributes().contains(MenuAttribute.BATTERY_STATE)) { From 1ba3a85655386feed51394bae5399fe5eac09e71 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 13:54:15 +0100 Subject: [PATCH 48/54] Add DetailedBolusInfo.copy() method. --- .../androidaps/data/DetailedBolusInfo.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java index 7720b03d3e..07dd1c9ed3 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java @@ -6,16 +6,14 @@ import org.json.JSONObject; import java.util.Date; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.interfaces.InsulinInterface; /** * Created by mike on 29.05.2017. */ -public class DetailedBolusInfo { +public class DetailedBolusInfo implements Cloneable { public long date = System.currentTimeMillis(); public String eventType = CareportalEvent.MEALBOLUS; public double insulin = 0; @@ -30,6 +28,24 @@ public class DetailedBolusInfo { public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment) public boolean isSMB = false; // is a Super-MicroBolus + public DetailedBolusInfo copy() { + DetailedBolusInfo copy = new DetailedBolusInfo(); + copy.date = this.date; + copy.eventType = this.eventType; + copy.insulin = this.insulin; + copy.carbs = this.carbs; + copy.source = this.source; + copy.isValid = this.isValid; + copy.glucose = this.glucose; + copy.glucoseType = this.glucoseType; + copy.carbTime = this.carbTime; + copy.boluscalc = this.boluscalc; + copy.context = this.context; + copy.pumpId = this.pumpId; + copy.isSMB = this.isSMB; + return copy; + } + @Override public String toString() { return new Date(date).toLocaleString() + From 98d666098be18c92a3ba98925a63a7999f1bc4bc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 13:54:42 +0100 Subject: [PATCH 49/54] Remove now unused PumpState.delivered field. --- .../plugins/PumpCombo/ruffyscripter/CommandResult.java | 2 -- .../plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java index 5f140b1a37..9da5d4d6fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/CommandResult.java @@ -13,8 +13,6 @@ public class CommandResult { public boolean success; /** State of the pump *after* command execution. */ public PumpState state; - /** Bolus actually delivered if request was a bolus command. */ - public double delivered; /** History if requested by the command. */ @Nullable public PumpHistory history; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java index 0e0ad9c9b4..4188716553 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/commands/BolusCommand.java @@ -186,10 +186,8 @@ public class BolusCommand extends BaseCommand { if (cancelInProgress) { log.debug("Stage 4: bolus was cancelled, with unknown amount delivered"); - this.result.delivered = -1; } else { log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered"); - result.delivered = bolus; bolusProgressReporter.report(DELIVERED, 100, bolus); } result.success = true; From b32351145a8ee5b4367409b42b1aa4ef4a412b79 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 13:55:25 +0100 Subject: [PATCH 50/54] Fix 'last bolus' not being displayed on start. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 0eea734a65..cc991f1745 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -148,10 +148,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf String getStateSummary() { PumpState ps = pump.state; - if (!validBasalRateProfileSelectedOnPump) { - return MainApp.gs(R.string.loopdisabled); - } else if (!pump.initialized) { + if (!pump.initialized) { return MainApp.gs(R.string.combo_pump_state_initializing); + } else if (!validBasalRateProfileSelectedOnPump) { + return MainApp.gs(R.string.loopdisabled); } else if (ps.activeAlert != null) { return ps.activeAlert.errorCode != null ? "E" + ps.activeAlert.errorCode + ": " + ps.activeAlert.message @@ -401,7 +401,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // ComboFragment updates state fully only after the pump has initialized, // so force an update after initialization completed - updateLocalData(stateResult); + updateLocalData(runCommand(null, 1, ruffyScripter::readQuickInfo)); } /** Updates local cache with state (reservoir level, last bolus ...) returned from the pump */ From c62ca899313a75e07cb73a87141da60bf35488b7 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 13:56:09 +0100 Subject: [PATCH 51/54] Fix adding a partial bolus to treatments. --- .../plugins/PumpCombo/ComboPlugin.java | 22 ++++++++++--------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index cc991f1745..9103264d32 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -538,7 +538,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // a connection problem, ruffyscripter tried to recover and we can just check the // history below to see what was actually delivered - // get last bolus from pump histqry for verification + // get last bolus from pump history for verification CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readQuickInfo); if (!postBolusStateResult.success) { return new PumpEnactResult().success(false).enacted(false) @@ -571,7 +571,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return new PumpEnactResult().success(true).enacted(true); } return new PumpEnactResult().success(false).enacted(true) - .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered)); + .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered, + lastPumpBolus.amount, detailedBolusInfo.insulin)); } // full bolus was delivered successfully @@ -594,15 +595,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf * but if they do, the user should be warned since a bolus will be missing from calculations. */ private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { - detailedBolusInfo.date = calculateFakeBolusDate(lastPumpBolus); - detailedBolusInfo.pumpId = calculateFakeBolusDate(lastPumpBolus); - detailedBolusInfo.source = Source.PUMP; - detailedBolusInfo.insulin = lastPumpBolus.amount; + DetailedBolusInfo dbi = detailedBolusInfo.copy(); + dbi.date = calculateFakeBolusDate(lastPumpBolus); + dbi.pumpId = calculateFakeBolusDate(lastPumpBolus); + dbi.source = Source.PUMP; + dbi.insulin = lastPumpBolus.amount; try { - boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(dbi); if (!treatmentCreated) { - log.error("Adding treatment record overrode an existing necord: " + detailedBolusInfo); - if (detailedBolusInfo.isSMB) { + log.error("Adding treatment record overrode an existing record: " + dbi); + if (dbi.isSMB) { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); } @@ -610,7 +612,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } catch (Exception e) { log.error("Adding treatment record failed", e); - if (detailedBolusInfo.isSMB) { + if (dbi.isSMB) { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_error_updating_treatment_record), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4e18a0160..31dabb2284 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -834,7 +834,7 @@ Requested operation not supported by pump Unsafe usage: extended or multiwave boluses are active. Loop mode has been set to low-suspend only 6 hours. Only normal boluses are supported in loop mode Unsafe usage: the pump uses a different basal rate profile than the first. The loop has been disabled. Select the first profile on the pump and refresh. - A bolus with the same amount was requested within the last minute. To prevent accidental double boluses and to guard against bugs this is disallowed. + A bolus with the same amount was requested within the last two minutes. To prevent accidental double boluses and to guard against bugs this is disallowed. Now Reading pump history pump history From d336c176fba3f12eeb6caffb18899f91f480a32e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 14:07:47 +0100 Subject: [PATCH 52/54] Update some descriptions. --- app/src/main/res/values/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 31dabb2284..f6d2245060 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -843,8 +843,8 @@ Pump cartridge level is low Pump battery is low The pump is showing the error E%d: %s - To read the pump\'s error history, long press the ALERTS 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. - To read the pump\'s TDD history, long press the TDDS 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. + To read the pump\'s error history, long press this button + To read the pump\'s TDD history, long press this button Minimum: %3.1f U Average: %3.1f U Maximum: %3.1f U @@ -854,7 +854,7 @@ Pump clock update needed History Warning - Long press this button to force a full read of history and basal profile from the pump. This is generally not needed, but can be useful if the pump\'s date and time changed significantly or the pump was replaced. + Long press this button to force a full read of history and basal profile from the pump. This is generally not needed, since the pump\'s history is read continuously, but can be useful if the pump\'s date and time changed significantly or the pump was replaced. This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed From bb04bd9b23c2eeb4670f8d25f636e721b5347a72 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 14:41:37 +0100 Subject: [PATCH 53/54] Update README-Combo.md --- README-Combo.md | 169 +++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 94 deletions(-) diff --git a/README-Combo.md b/README-Combo.md index 3088aed778..c6ffd5d7c7 100644 --- a/README-Combo.md +++ b/README-Combo.md @@ -2,10 +2,12 @@ requires YOU to read, learn and understand the system and how to use it. It is not something that does all your diabetes management for you, but allows you to improve your diabetes and quality of life significantly -if you're willing to put in the time required. -You alone are responsible for what you do with it.** +if you're willing to put in the time required. Don't rush into it, +but allow yourself time to learn. You alone are responsible for what +you do with it.** -Hardware requirements: +Hardware requirements +--------------------- - A Roche Accu-Chek Combo (any firmware, they all work) - A Smartpix or Realtyme device together with the 360 Configuration Software to configure the pump. @@ -18,58 +20,58 @@ Hardware requirements: has not been widely tested: https://github.com/gregorybel/combo-pairing/blob/master/README.md - To build AndroidAPS with Combo support you need the latest Android Studio 3 version -Limitations: +Limitations +----------- - Extended bolus and multiwave bolus are not supported. - Only one basal profile is supported. - Setting a basal profile other than 1 on the pump, or delivering extended boluses or multiwave boluses from the pump interferes with TBRs and forces the loop into low-suspend only mode for 6 hours as the the loop can't run safely under those conditions. - It's currently not possible to set the time and date on the pump, so daylight saving times - changes have to be performed manually. -- There's a bug in the pump's firmware that's triggered when "too much" communication happens - with the pump. Specifically, this issue occurs when going from just issuing commands to the pump - to reading the pump's data and history. For that reason, a minimal amount of data is read from - the pump. - The bug might still rarely occur and causes the pump to not accept any connection - unless a button is physically pressed on the pump (make sure the 'pump unreachable' alert is enabled - so you'll get an alarm if the bug occurs. - Therefore, the pump's reservoir level is not read and the pump status information uploaded to Nightscout - shows fake numbers of 150 (above low threshold - which can be configured via the configuration - tool), 8 (below low threshold, triggers NS alarm since < 10) and 0 if the reservoir is empty. - Furthermore, no history (from the My Data menu) is read unless absolutely required. - Reading all pump data can be forced through the Combo tab, to import - events that happened solely on the pump, but that code has been tested less, might cause duplicates and may - trigger the bug, so it's strongly recommended to stick to the usage scenario of controlling the - pump solely through AAPS. - Checking history, reservoir level etc on the pump causes no issues but should be avoided - when the Bluetooth icon is displayed on the display, indicating that AAPS is communicating with the pump. + changes have to be performed manually (disable automatic phone clock update in the evening and + update change back in the morning while also updating the pump's clock to avoid an alarm during the night). - Currently only basal rates in the range of 0.05 to 10 U/h are supported (this also applies when modifying a profile, e.g. when increasing to 200%, the highest basal rate must not exceed 5 U/h since it will be doubled. Similarly, when reducing to 50%, the lowest basal rate must be at least 0.10 U/h). +- If the loop requests a running TBR to be cancelled the Combo will set a TBR of 90% or 110% + for 15 minutes instead. This is because cancelling a TBR causes an alert on the pump which + causes a lot of vibrations. +- Occasionally (every couple of days or so) AAPS might fail to automatically cancel + a TBR CANCELLED alert the user then needs to deal with (press the refresh button in AAPS + to transfer the warning to AAPS or confirm the alert on the pump). -Setup: +Setup +----- - Configure pump using 360 config software. - - Set/leave the menu configuration as "Standard", this will show only the supported - menus/actions on the pump and hide those which are unsupported (extended/multiwave bolus, - multiple basal rates), which cause the loop functionality to be restricted when used because - it's not possible to run the loop in a safe manner when used. - - Verify the _Quick Info Text_ is set to "QUICK INFO" (without the quotes, found under _Insulin Pump Options_). - - Set maximum TBR to 500% - - Disable end of TBR alert - - Set TBR duration step-size to 15 min - - Set low cartridge alarm to your liking - - Configure a max bolus suited for your therapy to protect against bugs in the software - - Similarly, configure maximum TBR duration as a safeguard. Allow at least 3 hours, since - the option to disconnect the pump for 3 hours sets a 0% for 3 hours. - - Enable keylock (can also be set on the pump directly, see usage section on reasoning) -- Get Android Studio 3 https://developer.android.com/studio/index.html -- Follow the link http://ruffy.AndroidAPS.org and clone via git (branch `combo-scripter-v2`) + - Required: + - Set/leave the menu configuration as "Standard", this will show only the supported + menus/actions on the pump and hide those which are unsupported (extended/multiwave bolus, + multiple basal rates), which cause the loop functionality to be restricted when used because + it's not possible to run the loop in a safe manner when used. + - Verify the _Quick Info Text_ is set to "QUICK INFO" (without the quotes, found under _Insulin Pump Options_). + - Set maximum TBR to 500% + - Disable end of TBR alert + - Set TBR duration step-size to 15 min + - Recommended: + - Set low cartridge alarm to your liking + - Configure a max bolus suited for your therapy to protect against bugs in the software + - Similarly, configure maximum TBR duration as a safeguard. Allow at least 3 hours, since + the option to disconnect the pump for 3 hours sets a 0% for 3 hours. + - Enable key lock on the pump to prevent bolusing from the pump, esp. when the + pump was used before and quick bolusing was a habit. + - Set display timeout and menu timeout to the mininum of 5.5 and 5 respectively. This allows the AAPS to + recover more quickly from error situations and reduces the amount of vibrations that can occur during + such errors +- Install AndroidAPS as described in the wiki http://wiki.AndroidAPS.org +- Make sure to read the wiki to understand how to setup AndroidAPS. +- Select the MDI plugin in AndroidAPS, not the Combo plugin at this point to avoid the Combo + plugin from interfering with ruffy during the pairing process. +- Follow the link http://ruffy.AndroidAPS.org and clone ruffy via git. Use the same branch as you use for + AndroidAPS, which is usally `master`. + if you you want to help test the in-development version. - Pair the pump using ruffy. If it doesn't work after multiple attempts, switch to the `pairing` branch, pair the pump and then switch back the original branch. - If the pump is already paired and can be controlled via ruffy, installing the - `combo-scripter-v2` branch is sufficient. - If AAPS is already installed, switch to the MDI plugin to avoid the Combo - plugin from interfering with ruffy during the pairing process. + If the pump is already paired and can be controlled via ruffy, installing the `master` branch is sufficient. Note that the pairing processing is somewhat fragile (but only has to be done once) and may need a few attempts; quickly acknowledge prompts and when starting over, remove the pump device from the bluetooth settings beforehand. Another option to try is to go to the bluetooth menu after @@ -77,35 +79,40 @@ Setup: and switch back to ruffy after confirming the pairing on the pump, when the pump displays the authorization code. When AAPS is using ruffy, the ruffy app can't be used. The easiest way is to just reboot the phone after the pairing process and let AAPS start ruffy in the background. -- Clone AndroidAPS from https://github.com/jotomo/AndroidAPS (branch `combo-scripter-v2`) - and build AAPS using the instructions in the wiki http://wiki.AndroidAPS.org - Before enabling the Combo plugin in AAPS make sure your profile is set up correctly and your basal profile is up to date as AAPS will sync the basal profile - to the pump. + to the pump. Then activate the Combo plugin. -Usage: +Usage +----- - Keep in mind that this is not a product, esp. in the beginning the user needs to monitor and understand the system, its limitations and how it can fail. It is strongly advised NOT to use this system when the person using it is not able to fully understand the system. +- Read the OpenAPS documentation https://openaps.org to understand the loop algorithm AndroidAPS + is based upon. +- Read in the wiki to learn about and understand AndroidAPS http://wiki.AndroidAPS.org - This integration uses the same functionality which the meter provides that comes with the Combo. The meter allows to mirror the pump screen and forwards button presses to the pump. The connection to the pump and this forwarding is what the ruffy app does. A `scripter` components reads the screen - and automates inputing boluses, TBRs etc and making sure inputs are processed correctly (that's what - the scripter-part in the branch name stands for). + and automates inputing boluses, TBRs etc and making sure inputs are processed correctly. AAPS then interacts with the scripter to apply loop commands and to administer boluses. This mode has some restrictions: it's comparatively slow (but well fast enough for what it is used for), - doesn't support reading history continuously and setting a TBR or giving a bolus causes the pump to - vibrate. + and setting a TBR or giving a bolus causes the pump to vibrate. - The integration of the Combo with AndroidAPS is designed with the assumption that all inputs are - made via AndroidAPS. Boluses entered on the pump will NOT be detected by AAPS and may therefore - result in too much insulin being delivered. -- The pump's first basal rate profile is read on app start and is updated by AAPS. Manually changing - the pump's basal rate profile will lead to wrong basals being delivered and is NOT supported. + made via AndroidAPS. Boluses entered on the pump directly will be detected by AAPS, but it can take + up to 25 min before AndroidAPS becomes aware of such a bolus. Reading boluses delivered directly on + the pump is a safety feature and not meant to be regularly used (the loop requires knowledge of carbs + consumed, which can't be entered on the pump, which is another reason why all inputs should be done + in AndroidAPS). +- The pump's first basal rate profile is read on application start and is updated by AAPS. + The basal rate should not be manually changed on the pump, but will be detected and corrected as a safety + measure (don't rely on safety measures by default, this is meant to detect an unintended change on the pump). - It's recommended to enable key lock on the pump to prevent bolusing from the pump, esp. when the pump was used before and quick bolusing was a habit. - Also, with keylock enabled, accidentally pressing a key will NOT interrupt a running command + Also, with keylock enabled, accidentally pressing a key will NOT interrupt active communication + between AAPS and pmup. - When a BOLUS/TBR CANCELLED alert starts on the pump during bolusing or setting a TBR, this is - caused by a disconnect between pump and phone. The app will try to reconnect and confirm the alert + caused by a disconnect between pump and phone. AAPS will try to reconnect and confirm the alert and then retry the last action (boluses are NOT retried for safety reasons). Therefore, such an alarm shall be ignored (cancelling it is not a big issue, but will lead to the currently active action to have to wait till the pump's display turns off before it can reconnect to the @@ -113,7 +120,7 @@ Usage: needs to confirm the alarm. - When a low cartridge or low battery alarm is raised during a bolus, they are confirmed and shown as a notification in AAPS. If they occur while no connection is open to the pump, going to the - combo tab and hitting the Refresh button will take over those alerts by confirming them and + Combo tab and hitting the Refresh button will take over those alerts by confirming them and showing a notification in AAPS. - When AAPS fails to confirm a TBR CANCELLED alert, or one is raised for a different reason, hitting Refresh in the Combo tab establishes a connection, confirms the alert and shows @@ -121,52 +128,26 @@ Usage: appropriate TBR will be set again during the next loop iteration. - For all other alerts raised by the pump: connecting to the pump will show the alert message in the Combo tab, e.g. "State: E4: Occlusion" as well as showing a notification on the main screen. - An error will raise an urgent notification. + An error will raise an urgent notification. AAPS never confirms serious errors on the pump, + but let's the pump vibrate and ring to make sure the user is informed of a critical situation + that needs action. - After pairing, ruffy should not be used directly (AAPS will start in the background as needed), since using ruffy at AAPS at the same time is not supported. -- If AAPS crashes (or is stopped from the debugger) while AAPS and the pump were comunicating (using +- If AAPS crashes (or is stopped from the debugger) while AAPS and the pump were communicating (using ruffy), it might be necessary to force close ruffy. Restarting AAPS will start ruffy again. -- Read the documentation on the wiki as well as the docs at https://openaps.org + Restarting the phone is also an easy way to resolve this or you don't know how to force kill + an app. - Don't press any buttons on the pump while AAPS communicates with the pump (Bluetooth logo is shown on the pump). -- If the loop requests a running TBR to be cancelled the Combo will set a TBR of 90% or 110% - for 15 minutes instead. This is because cancelling a TBR causes an alert on the pump which - causes a lot of vibrations. -- Due to the bug (which causes the pump to become unreachable when reading history regularly), - a delivered bolus will NOT be added to treatments when the connection was lost during bolusing - or when a pump error occurs (e.g. occlusion). This will raise a message (and play an annoying - sound) and the user will have a create a bolus record via Careportal/NS manually. Currently - this requires an available NS installation and being online (for a short time). Hopefully - both of these issues can be resolved in future versions. -Known issues: -- Occasionally (every couple of days or so) AAPS might fail to automatically cancel - a TBR CANCELLED alert the user then needs to deal with (press the refresh button in AAPS - to transfer the warning to AAPS or confirm the alert on the pump). -- Similarly, the 'pump unreachable' bug may occur from time to time, which requires confirming - the alert on the pump to get the pump to accept connections again. -- Overall the integration seems rather robust, but there are limits to the way the - pump is controlled and how stable BT is, so there will be minor issues like the above - from time to time, though they're small compared to what works well. -- AAPS might be unresponsive for 10-30s or so when starting and calculating sensitivity. - AAPS might also be unresponsive when doing background work, e.g. after receiving a new - glucose reading. -- Since the pump's date & time can't be updated automatically at this time, daylight saving changes - will cause an alert asking to update the pump clock. A usable workaround should be to disable - the automatic update of the phone's clock for the night and then enabling it again in the morning - when also updating the pump. - -Reporting bugs: +Reporting bugs +-------------- +- See https://github.com/MilosKozak/AndroidAPS/blob/master/ISSUE_TEMPLATE.md - Note the precise time the problem occurred and describe the circumstances and steps that caused the problem - Note the Build version (found in the About dialog in the app, when pressing the three dots in the upper-right corner). -- Attach the app's log files, which can be found on the phone in +- Obtain the app's log files, which can be found on the phone in _/storage/emulated/0/Android/data/info.nightscout.androidaps/_ +- Open an issue at https://github.com/MilosKozak/AndroidAPS/issues/new -Components/Layers (developers): -- AndroidAPS -- ComboPlugin -- ruffy-spi (RuffyCommands interface to plug in lower layer) -- Scripting layer (ruffyscripter) / Command layer -- Driver layer (ruffy) From 79f993cd26e641ec1d2eae1a438dbc3d69ee3f10 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 31 Jan 2018 15:13:43 +0100 Subject: [PATCH 54/54] Set version. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index e1a030130c..e488472e52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { targetSdkVersion 23 multiDexEnabled true versionCode 1500 - version "1.57-combo-csv2-test" + version "1.57-combo-csv2-beta" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild()