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 d8926fc4c1..d37971c654 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -51,11 +51,13 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.PumpHistory; import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory; import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.PercentageSplitter; @@ -85,8 +87,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_INSIGHT_HISTORY_OFFSETS = "InsightHistoryOffsets"; public static final String DATABASE_INSIGHT_BOLUS_IDS = "InsightBolusIDs"; public static final String DATABASE_INSIGHT_PUMP_IDS = "InsightPumpIDs"; + public static final String DATABASE_POD_HISTORY = "PodHistory"; - private static final int DATABASE_VERSION = 11; + private static final int DATABASE_VERSION = 12; public static Long earliestDataChange = null; @@ -134,6 +137,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class); TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class); TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class); + TableUtils.createTableIfNotExists(connectionSource, PodHistory.class); database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " + "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")"); database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " + @@ -219,6 +223,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); TableUtils.dropTable(connectionSource, TDD.class, true); + TableUtils.dropTable(connectionSource, PodHistory.class, true); TableUtils.createTableIfNotExists(connectionSource, TempTarget.class); TableUtils.createTableIfNotExists(connectionSource, BgReading.class); TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class); @@ -228,6 +233,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); TableUtils.createTableIfNotExists(connectionSource, TDD.class); + TableUtils.createTableIfNotExists(connectionSource, PodHistory.class); updateEarliestDataChange(0); } catch (SQLException e) { log.error("Unhandled exception", e); @@ -362,6 +368,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return getDao(InsightHistoryOffset.class); } + private Dao getDaoPodHistory() throws SQLException { + return getDao(PodHistory.class); + } + public static long roundDateToSec(long date) { long rounded = date - date % 1000; if (rounded != date) @@ -1890,4 +1900,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } // ---------------- Food handling --------------- + + // ---------------- PodHistory handling --------------- + + public void createOrUpdate(PodHistory podHistory) { + try { + getDaoPodHistory().createOrUpdate(podHistory); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java index 783553f431..76e8697666 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java @@ -119,6 +119,14 @@ public class DateTimeUtil { } + public static long toATechDate(long timeInMillis) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTimeInMillis(timeInMillis); + + return toATechDate(gc); + } + + public static boolean isSameDay(LocalDateTime ldt1, LocalDateTime ldt2) { return (ldt1.getYear() == ldt2.getYear() && // diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index dc1dea851f..b9d9b4356b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -132,7 +132,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump for (int i = 0; i < 20; i++) { - if (OmnipodUtil.getPumpStatus() != null) { + if (pumpStatusLocal != null) { if (isLoggingEnabled()) LOG.debug("Starting OmniPod-RileyLink service"); if (OmnipodUtil.getPumpStatus().setNotInPreInit()) { @@ -528,8 +528,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump : OmnipodConst.Statistics.StandardBoluses); // calculate time for bolus and set driver to busy for that time + // TODO fix this - int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d); + int bolusTime = 1; //omnipodCommunicationManager.get; long time = System.currentTimeMillis() + (bolusTime * 1000); this.busyTimestamps.add(time); @@ -780,17 +781,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump private CustomAction customActionResetRLConfig = new CustomAction( R.string.medtronic_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true); - protected CustomAction customActionPairAndPrime = new CustomAction( - R.string.omnipod_cmd_init_pod, OmnipodCustomActionType.PairAndPrime, true); - - protected CustomAction customActionFillCanullaSetBasalProfile = new CustomAction( - R.string.omnipod_cmd_init_pod, OmnipodCustomActionType.FillCanulaSetBasalProfile, false); - - protected CustomAction customActionDeactivatePod = new CustomAction( - R.string.omnipod_cmd_deactivate_pod, OmnipodCustomActionType.DeactivatePod, false); - - protected CustomAction customActionResetPod = new CustomAction( - R.string.omnipod_cmd_reset_pod, OmnipodCustomActionType.ResetPodStatus, true); +// protected CustomAction customActionPairAndPrime = new CustomAction( +// R.string.omnipod_cmd_init_pod, OmnipodCustomActionType.PairAndPrime, true); +// +// protected CustomAction customActionFillCanullaSetBasalProfile = new CustomAction( +// R.string.omnipod_cmd_init_pod, OmnipodCustomActionType.FillCanulaSetBasalProfile, false); +// +// protected CustomAction customActionDeactivatePod = new CustomAction( +// R.string.omnipod_cmd_deactivate_pod, OmnipodCustomActionType.DeactivatePod, false); +// +// protected CustomAction customActionResetPod = new CustomAction( +// R.string.omnipod_cmd_reset_pod, OmnipodCustomActionType.ResetPodStatus, true); @Override @@ -811,9 +812,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } - LogReceiver logReceiver = new LogReceiver(); - - // TODO we need to brainstorm how we want to do this -- Andy @Override public void executeCustomAction(CustomActionType customActionType) { @@ -826,31 +824,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } break; - case PairAndPrime: { - omnipodUIComm.executeCommand(OmnipodCommandType.PairAndPrimePod, PodInitActionType.PairAndPrimeWizardStep, logReceiver); - } - break; - - case FillCanulaSetBasalProfile: { - if (this.currentProfile != null) { - omnipodUIComm.executeCommand(OmnipodCommandType.FillCanulaAndSetBasalProfile, PodInitActionType.FillCannulaSetBasalProfileWizardStep, logReceiver, this.currentProfile); - } else { - OKDialog.show(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.combo_warning), - MainApp.gs(R.string.omnipod_error_operation_not_possible_no_profile), null); - } - } - break; - - case DeactivatePod: { - omnipodUIComm.executeCommand(OmnipodCommandType.DeactivatePod); - } - break; - - case ResetPodStatus: { - omnipodUIComm.executeCommand(OmnipodCommandType.ResetPodStatus); - } - break; - default: break; } @@ -864,34 +837,12 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump // LOG.warn(getLogPrefix() + "Time, Date and/or TimeZone changed. "); // // this.hasTimeDateOrTimeZoneChanged = true; + + // TODO } public void setEnableCustomAction(OmnipodCustomActionType customAction, boolean isEnabled) { - - switch (customAction) { - - case PairAndPrime: { - this.customActionPairAndPrime.setEnabled(isEnabled); - } - break; - - case FillCanulaSetBasalProfile: { - this.customActionFillCanullaSetBasalProfile.setEnabled(isEnabled); - } - break; - - - case DeactivatePod: { - this.customActionDeactivatePod.setEnabled(isEnabled); - } - break; - - default: - break; - } - - refreshCustomActionsList(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistory.java index 93a228316c..68fff6d972 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistory.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistory.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.db; +package info.nightscout.androidaps.plugins.pump.omnipod.driver.db; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @@ -6,54 +6,115 @@ import com.j256.ormlite.table.DatabaseTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.db.DbObjectBase; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; /** - * Created by mike on 20.09.2017. + * Created by andy on 30.11.2019. */ -@DatabaseTable(tableName = DatabaseHelper.DATABASE_TDDS) -public class TDD { +@DatabaseTable(tableName = DatabaseHelper.DATABASE_POD_HISTORY) +public class PodHistory implements DbObjectBase { + private static Logger log = LoggerFactory.getLogger(L.DATABASE); @DatabaseField(id = true) public long date; - @DatabaseField - public double bolus; + private PodDbEntryType podDbEntryType; @DatabaseField - public double basal; + private long podEntryTypeCode; @DatabaseField - public double total; + private String data; + + @DatabaseField + private boolean success; + + @DatabaseField + private long pumpId; + + @DatabaseField + private Boolean successConfirmed; - public double getTotal(){ - return (total > 0d) ? total:(bolus+basal); + + public PodHistory(PodDbEntryType podDbEntryType) { + this.date = System.currentTimeMillis(); + this.podDbEntryType = podDbEntryType; + generatePumpId(); } - public TDD() { } - - public TDD(long date, double bolus, double basal, double total){ - this.date = date; - this.bolus = bolus; - this.basal = basal; - this.total = total; + public PodHistory(long dateTimeInMillis, PodDbEntryType podDbEntryType) { + this.date = dateTimeInMillis; + this.podDbEntryType = podDbEntryType; + generatePumpId(); } @Override - public String toString() { - return "TDD [" + - "date=" + date + - "date(str)=" + DateTimeUtil.toStringFromTimeInMillis(date) + - ", bolus=" + bolus + - ", basal=" + basal + - ", total=" + total + - ']'; + public long getDate() { + return this.date; } + + public void setDate(long date) { + this.date = date; + } + + public PodDbEntryType getPodDbEntryType() { + return podDbEntryType; + } + + public void setPodDbEntryType(PodDbEntryType podDbEntryType) { + this.podDbEntryType = podDbEntryType; + this.podEntryTypeCode = podDbEntryType.getCode(); + } + + public long getPodEntryTypeCode() { + return podEntryTypeCode; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public void setPumpId(long pumpId) { + this.pumpId = pumpId; + } + + public Boolean getSuccessConfirmed() { + return successConfirmed; + } + + public void setSuccessConfirmed(Boolean successConfirmed) { + this.successConfirmed = successConfirmed; + } + + @Override + public long getPumpId() { + return pumpId; + } + + private void generatePumpId() { + this.pumpId = (DateTimeUtil.toATechDate(this.date) * 100L) + podEntryTypeCode; + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java index 91da9b1d1c..7b52920040 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java @@ -16,13 +16,11 @@ public class OmnipodUIPostprocessor { private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); - OmnipodPumpStatus pumpStatus; - OmnipodPumpPlugin omnipodPumpPlugin; + private OmnipodPumpStatus pumpStatus; + private OmnipodPumpPlugin omnipodPumpPlugin; public OmnipodUIPostprocessor(OmnipodPumpPlugin plugin, OmnipodPumpStatus pumpStatus) { -// pumpStatus = OmnipodUtil.getPumpStatus(); -// omnipodPumpPlugin = OmnipodPumpPlugin.getPlugin(); this.pumpStatus = pumpStatus; this.omnipodPumpPlugin = plugin; } @@ -34,29 +32,29 @@ public class OmnipodUIPostprocessor { switch (uiTask.commandType) { - case PairAndPrimePod: { - if (uiTask.returnData.success) { - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, false); - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, true); - } - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); - } - break; - - case FillCanulaAndSetBasalProfile: { - if (uiTask.returnData.success) { - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, false); - } - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); - } - break; - - case DeactivatePod: - case ResetPodStatus: { - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, true); - omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, false); - } - break; +// case PairAndPrimePod: { +// if (uiTask.returnData.success) { +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, false); +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, true); +// } +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); +// } +// break; +// +// case FillCanulaAndSetBasalProfile: { +// if (uiTask.returnData.success) { +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.FillCanulaSetBasalProfile, false); +// } +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, true); +// } +// break; +// +// case DeactivatePod: +// case ResetPodStatus: { +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.PairAndPrime, true); +// omnipodPumpPlugin.setEnableCustomAction(OmnipodCustomActionType.DeactivatePod, false); +// } +// break; default: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java index 0ec828ee97..daa88bda6e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/OmnipodDashPumpPlugin.java @@ -272,10 +272,11 @@ public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements OmnipodP if (customActions == null) { this.customActions = Arrays.asList( - customActionPairAndPrime, // - customActionFillCanullaSetBasalProfile, // - customActionDeactivatePod, // - customActionResetPod); +// customActionPairAndPrime, // +// customActionFillCanullaSetBasalProfile, // +// customActionDeactivatePod, // +// customActionResetPod + ); } return this.customActions;