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 5766f59c31..370d613909 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventReloadTempBasalData; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempBasalChange; @@ -193,6 +194,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleExtendedBolusChange(); scheduleTemporaryTargetChange(); scheduleCareportalEventChange(); + new java.util.Timer().schedule( + new java.util.TimerTask() { + @Override + public void run() { + MainApp.bus().post(new EventRefreshGui(false)); + } + }, + 3000 + ); } public void resetTreatments() { @@ -440,7 +450,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // -------------------- TREATMENT HANDLING ------------------- public boolean changeAffectingIobCob(Treatment t) { - Treatment existing = findTreatmentByTimeIndex(t.date); + Treatment existing = findTreatmentByTime(t.date); if (existing == null) return true; if (existing.insulin == t.insulin && existing.carbs == t.carbs) @@ -507,7 +517,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } @Nullable - public Treatment findTreatmentByTimeIndex(Long timeIndex) { + public Treatment findTreatmentByTime(Long timeIndex) { try { QueryBuilder qb = null; Dao daoTreatments = getDaoTreatments(); @@ -518,10 +528,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { PreparedQuery preparedQuery = queryBuilder.prepare(); List trList = daoTreatments.query(preparedQuery); if (trList.size() != 1) { - log.debug("Treatment findTreatmentByTimeIndex query size: " + trList.size()); + //log.debug("Treatment findTreatmentByTime query size: " + trList.size()); return null; } else { - log.debug("Treatment findTreatmentByTimeIndex found: " + trList.get(0).log()); + //log.debug("Treatment findTreatmentByTime found: " + trList.get(0).log()); return trList.get(0); } } catch (SQLException e) { @@ -853,6 +863,30 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + @Nullable + public TemporaryBasal findTempBasalByTime(Long timeIndex) { + try { + QueryBuilder qb = null; + Dao daoTemporaryBasal = getDaoTemporaryBasal(); + QueryBuilder queryBuilder = daoTemporaryBasal.queryBuilder(); + Where where = queryBuilder.where(); + where.eq("date", timeIndex); + queryBuilder.limit(10L); + PreparedQuery preparedQuery = queryBuilder.prepare(); + List trList = daoTemporaryBasal.query(preparedQuery); + if (trList.size() != 1) { + //log.debug("TemporaryBasal findTempBasalByTime query size: " + trList.size()); + return null; + } else { + //log.debug("TemporaryBasal findTempBasalByTime found: " + trList.get(0).log()); + return trList.get(0); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + static public void scheduleTemporaryBasalChange() { class PostRunnable implements Runnable { public void run() { @@ -1050,6 +1084,30 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + @Nullable + public ExtendedBolus findExtendedBolusByTime(Long timeIndex) { + try { + QueryBuilder qb = null; + Dao daoExtendedBolus = getDaoExtendedBolus(); + QueryBuilder queryBuilder = daoExtendedBolus.queryBuilder(); + Where where = queryBuilder.where(); + where.eq("date", timeIndex); + queryBuilder.limit(10L); + PreparedQuery preparedQuery = queryBuilder.prepare(); + List trList = daoExtendedBolus.query(preparedQuery); + if (trList.size() != 1) { + //log.debug("ExtendedBolus findExtendedBolusByTime query size: " + trList.size()); + return null; + } else { + //log.debug("ExtendedBolus findExtendedBolusByTime found: " + trList.get(0).log()); + return trList.get(0); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + public void deleteExtendedBolusById(String _id) { try { QueryBuilder queryBuilder = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index aee078d5f6..417b58d190 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -133,12 +133,12 @@ public class ActionsFragment extends Fragment implements View.OnClickListener { profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) extendedBolus.setVisibility(View.GONE); else { extendedBolus.setVisibility(View.VISIBLE); } - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) extendedBolusCancel.setVisibility(View.GONE); else { extendedBolusCancel.setVisibility(View.VISIBLE); @@ -205,26 +205,28 @@ public class ActionsFragment extends Fragment implements View.OnClickListener { fillDialog.show(manager, "FillDialog"); break; case R.id.actions_50_30: - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - sHandler.post(new Runnable() { - @Override - public void run() { - DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); - danaRv2Plugin.setHighTempBasalPercent(50); + sHandler.post(new Runnable() { + @Override + public void run() { + DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + danaRv2Plugin.cancelTempBasal(); } - }); - } + danaRv2Plugin.setHighTempBasalPercent(50); + } + }); break; case R.id.actions_400_15: - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - sHandler.post(new Runnable() { - @Override - public void run() { - DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); - danaRv2Plugin.setHighTempBasalPercent(400); + sHandler.post(new Runnable() { + @Override + public void run() { + DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + danaRv2Plugin.cancelTempBasal(); } - }); - } + danaRv2Plugin.setHighTempBasalPercent(400); + } + }); break; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index 3beacec424..e95b45d760 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -33,6 +33,22 @@ public class DanaRPump { public static final String PROFILE_PREFIX = "DanaR-"; + // v2 history entries + public static final int TEMPSTART = 1; + public static final int TEMPSTOP = 2; + public static final int EXTENDEDSTART = 3; + public static final int EXTENDEDSTOP = 4; + public static final int BOLUS = 5; + public static final int DUALBOLUS = 6; + public static final int DUALEXTENDEDSTART = 7; + public static final int DUALEXTENDEDSTOP = 8; + public static final int SUSPENDON = 9; + public static final int SUSPENDOFF = 10; + public static final int REFILL = 11; + public static final int PRIME = 12; + public static final int PROFILECHANGE = 13; + public static final int CARBS = 14; + public Date lastConnection = new Date(0); public Date lastSettingsRead = new Date(0); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java index e9851d4df8..943d4ee502 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java @@ -47,7 +47,7 @@ public class MessageBase { AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100)); AddParamByte((byte) (date.get(Calendar.MONTH) + 1)); AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH))); - AddParamByte((byte) (date.get(Calendar.HOUR))); + AddParamByte((byte) (date.get(Calendar.HOUR_OF_DAY))); AddParamByte((byte) (date.get(Calendar.MINUTE))); } @@ -55,7 +55,7 @@ public class MessageBase { AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100)); AddParamByte((byte) (date.get(Calendar.MONTH) + 1)); AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH))); - AddParamByte((byte) (date.get(Calendar.HOUR))); + AddParamByte((byte) (date.get(Calendar.HOUR_OF_DAY))); AddParamByte((byte) (date.get(Calendar.MINUTE))); AddParamByte((byte) (date.get(Calendar.SECOND))); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java index 6a16fd1a57..4fcd6dee9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntry.java @@ -14,20 +14,21 @@ public class MsgSetCarbsEntry extends MessageBase { SetCommand(0x0402); } - public MsgSetCarbsEntry(Calendar time, int amount) { + public MsgSetCarbsEntry(long time, int amount) { this(); - + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(time); AddParamByte((byte) RecordTypes.RECORD_TYPE_CARBO); - AddParamByte((byte) (time.get(Calendar.YEAR) % 100)); - AddParamByte((byte) (time.get(Calendar.MONTH) + 1)); - AddParamByte((byte) (time.get(Calendar.DAY_OF_MONTH))); - AddParamByte((byte) (time.get(Calendar.HOUR_OF_DAY))); - AddParamByte((byte) (time.get(Calendar.MINUTE))); - AddParamByte((byte) (time.get(Calendar.SECOND))); + AddParamByte((byte) (calendar.get(Calendar.YEAR) % 100)); + AddParamByte((byte) (calendar.get(Calendar.MONTH) + 1)); + AddParamByte((byte) (calendar.get(Calendar.DAY_OF_MONTH))); + AddParamByte((byte) (calendar.get(Calendar.HOUR_OF_DAY))); + AddParamByte((byte) (calendar.get(Calendar.MINUTE))); + AddParamByte((byte) (calendar.get(Calendar.SECOND))); AddParamByte((byte) 0x43); //?? AddParamInt(amount); if (Config.logDanaMessageDetail) - log.debug("Set carb entry: " + amount + " date " + time.getTime().toString()); + log.debug("Set carb entry: " + amount + " date " + calendar.getTime().toString()); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index ff10012f2b..0c1b50d109 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -400,8 +400,7 @@ public class DanaRExecutionService extends Service { if (!isConnected()) return false; if (carbs > 0) { - Calendar time = Calendar.getInstance(); - mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs)); + mSerialIOThread.sendMessage(new MsgSetCarbsEntry(new Date().getTime(), carbs)); } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables @@ -463,8 +462,7 @@ public class DanaRExecutionService extends Service { public boolean carbsEntry(int amount) { connect("carbsEntry"); if (!isConnected()) return false; - Calendar time = Calendar.getInstance(); - MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount); + MsgSetCarbsEntry msg = new MsgSetCarbsEntry(new Date().getTime(), amount); mSerialIOThread.sendMessage(msg); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index d1203a35cb..524e7b0682 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -394,8 +394,7 @@ public class DanaRKoreanExecutionService extends Service { if (!isConnected()) return false; if (carbs > 0) { - Calendar time = Calendar.getInstance(); - mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs)); + mSerialIOThread.sendMessage(new MsgSetCarbsEntry(new Date().getTime(), carbs)); } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables @@ -440,8 +439,7 @@ public class DanaRKoreanExecutionService extends Service { public boolean carbsEntry(int amount) { connect("carbsEntry"); if (!isConnected()) return false; - Calendar time = Calendar.getInstance(); - MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount); + MsgSetCarbsEntry msg = new MsgSetCarbsEntry(new Date().getTime(), amount); mSerialIOThread.sendMessage(msg); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 14f078a86a..9b17a3e192 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -287,7 +287,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { Treatment t = new Treatment(detailedBolusInfo.insulinInterface); boolean connectionOK = false; - if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t); + if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, new Date().getTime() + detailedBolusInfo.carbTime * 60 * 1000, t); PumpEnactResult result = new PumpEnactResult(); result.success = connectionOK; result.bolusDelivered = t.insulin; @@ -295,9 +295,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); - detailedBolusInfo.insulin = t.insulin; - detailedBolusInfo.date = new Date().getTime(); - MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo); return result; } else { PumpEnactResult result = new PumpEnactResult(); @@ -357,8 +354,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); else percentRate = Round.floorTo((double) percentRate, 10d).intValue(); - if (percentRate > getPumpDescription().maxTempPercent) - percentRate = getPumpDescription().maxTempPercent; + if (percentRate > 500) // Special high temp 500/15min + percentRate = 500; // Check if some temp is already in progress if (MainApp.getConfigBuilder().isTempBasalInProgress()) { // Correct basal already set ? @@ -387,7 +384,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte // Convert duration from minutes to hours if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); - return setTempBasalPercent(percentRate, durationInMinutes); + // use special APS temp basal call ... 100+/15min .... 100-/30min + setHighTempBasalPercent(percentRate); } // We should never end here log.error("setTempBasalAbsolute: Internal error"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java index 9e2760b47b..0940efd73f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java @@ -24,8 +24,10 @@ public class MessageHashTable_v2 { put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING - put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE - put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I + + put(new MsgStatusTempBasal_v2()); // 0x0205 CMD_PUMP_EXERCISE_MODE + put(new MsgStatusBolusExtended_v2()); // 0x0207 CMD_PUMP_EXPANS_INS_I + put(new MsgStatusBasic()); // 0x020A CMD_PUMP_INITVIEW_I put(new MsgStatus()); // 0x020B CMD_PUMP_STATUS put(new MsgInitConnStatusTime()); // 0x0301 CMD_PUMPINIT_TIME_INFO diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java index b74259f6f9..2dfc7cb64d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java @@ -6,17 +6,24 @@ import org.slf4j.LoggerFactory; import java.util.Date; import java.util.GregorianCalendar; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; -import info.nightscout.utils.DateUtil; public class MsgHistoryEvents_v2 extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents_v2.class); public boolean done; - public MsgHistoryEvents_v2(Date from) { + public static long lastEventTimeLoaded = 0; + + public MsgHistoryEvents_v2(long from) { SetCommand(0xE003); GregorianCalendar gfrom = new GregorianCalendar(); - gfrom.setTimeInMillis(from.getTime()); + gfrom.setTimeInMillis(from); AddParamDate(gfrom); done = false; } @@ -45,54 +52,108 @@ public class MsgHistoryEvents_v2 extends MessageBase { int param1 = intFromBuff(bytes, 7, 2); int param2 = intFromBuff(bytes, 9, 2); + TemporaryBasal temporaryBasal = MainApp.getDbHelper().findTempBasalByTime(datetime.getTime()); + if (temporaryBasal != null) { + log.debug("Existing temporaryBasal found. Skipping ..."); + return; + } + temporaryBasal = new TemporaryBasal(); + + ExtendedBolus extendedBolus = MainApp.getDbHelper().findExtendedBolusByTime(datetime.getTime()); + if (extendedBolus != null) { + log.debug("Existing extendedBolus found. Skipping ..."); + return; + } + extendedBolus = new ExtendedBolus(); + + Treatment treatment = MainApp.getDbHelper().findTreatmentByTime(datetime.getTime()); + if (treatment != null) { + log.debug("Existing treatment found. Skipping ..."); + return; + } + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + switch (recordCode) { - case 1: - log.debug("EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Ratio: " + param1 + "% Duration: " + param2 + "min"); + case DanaRPump.TEMPSTART: + log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min"); + temporaryBasal.date = datetime.getTime(); + temporaryBasal.percentRate = param1; + temporaryBasal.durationInMinutes = param2; + MainApp.getConfigBuilder().addToHistoryTempBasalStart(temporaryBasal); break; - case 2: - log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime)); + case DanaRPump.TEMPSTOP: + log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString()); + temporaryBasal.date = datetime.getTime(); + temporaryBasal.durationInMinutes = 0; + MainApp.getConfigBuilder().addToHistoryTempBasalStart(temporaryBasal); break; - case 3: - log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + case DanaRPump.EXTENDEDSTART: + log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + extendedBolus.date = datetime.getTime(); + extendedBolus.insulin = param1 / 100d; + extendedBolus.durationInMinutes = param2; + MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus); break; - case 4: - log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); + case DanaRPump.EXTENDEDSTOP: + log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); + extendedBolus.date = datetime.getTime(); + extendedBolus.durationInMinutes = 0; + MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus); break; - case 5: - log.debug("EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + case DanaRPump.BOLUS: + log.debug("EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + detailedBolusInfo.date = datetime.getTime(); + detailedBolusInfo.insulin = param1 / 100d; + MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo); break; - case 6: - log.debug("EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + case DanaRPump.DUALBOLUS: + log.debug("EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + detailedBolusInfo.date = datetime.getTime(); + detailedBolusInfo.insulin = param1 / 100d; + MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo); break; - case 7: - log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + case DanaRPump.DUALEXTENDEDSTART: + log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); + extendedBolus.date = datetime.getTime(); + extendedBolus.insulin = param1 / 100d; + extendedBolus.durationInMinutes = param2; + MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus); break; - case 8: - log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); + case DanaRPump.DUALEXTENDEDSTOP: + log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); + extendedBolus.date = datetime.getTime(); + extendedBolus.durationInMinutes = 0; + MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus); break; - case 9: - log.debug("EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime)); + case DanaRPump.SUSPENDON: + log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString()); break; - case 10: - log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime)); + case DanaRPump.SUSPENDOFF: + log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString()); break; - case 11: - log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + param1 + "U"); + case DanaRPump.REFILL: + log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U"); break; - case 12: - log.debug("EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + param1 + "U"); + case DanaRPump.PRIME: + log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U"); break; - case 13: - log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " No: " + param1 + "U CurrentRate: " + param2 + "U/h"); + case DanaRPump.PROFILECHANGE: + log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + "U CurrentRate: " + param2 + "U/h"); break; - case 14: - log.debug("EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Carbs: " + param1 + "g"); + case DanaRPump.CARBS: + log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); + detailedBolusInfo.date = datetime.getTime(); + detailedBolusInfo.carbs = param1; + MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo); break; default: - log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " Param1: " + param1 + " Param2: " + param2); + log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2); break; } + if (datetime.getTime() > lastEventTimeLoaded) + lastEventTimeLoaded = datetime.getTime(); + return; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java index ea65abaaa0..abeb656f03 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java @@ -16,17 +16,17 @@ public class MsgSetHistoryEntry_v2 extends MessageBase { SetCommand(0xE004); } - public MsgSetHistoryEntry_v2(int type, Date time, int param1, int param2) { + public MsgSetHistoryEntry_v2(int type, long time, int param1, int param2) { this(); AddParamByte((byte) type); GregorianCalendar gtime = new GregorianCalendar(); - gtime.setTimeInMillis(time.getTime()); + gtime.setTimeInMillis(time); AddParamDateTime(gtime); AddParamInt(param1); AddParamInt(param2); if (Config.logDanaMessageDetail) - log.debug("Set history entry: type: " + type + " date: " + time.toString() + " param1: " + param1 + " param2: " + param2); + log.debug("Set history entry: type: " + type + " date: " + new Date(time).toString() + " param1: " + param1 + " param2: " + param2); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java new file mode 100644 index 0000000000..5f4ccf960f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended_v2.java @@ -0,0 +1,65 @@ +package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; + +import android.support.annotation.NonNull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; + +public class MsgStatusBolusExtended_v2 extends MessageBase { + private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended_v2.class); + + public MsgStatusBolusExtended_v2() { + SetCommand(0x0207); + } + + public void handleMessage(byte[] bytes) { + boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1; + int extendedBolusHalfHours = intFromBuff(bytes, 1, 1); + int extendedBolusMinutes = extendedBolusHalfHours * 30; + + double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d; + int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3); +// This is available only on korean, but not needed now +// int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2); +// int isEasyUIUserSleep = intFromBuff(bytes, 9, 1); + + int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60; + double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d; + Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0); + int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes; + + DanaRPump pump = DanaRPump.getInstance(); + pump.isExtendedInProgress = isExtendedInProgress; + pump.extendedBolusMinutes = extendedBolusMinutes; + pump.extendedBolusAmount = extendedBolusAmount; + pump.extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes; + pump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate; + pump.extendedBolusStart = extendedBolusStart; + pump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes; + + if (Config.logDanaMessageDetail) { + log.debug("Is extended bolus running: " + isExtendedInProgress); + log.debug("Extended bolus min: " + extendedBolusMinutes); + log.debug("Extended bolus amount: " + extendedBolusAmount); + log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes); + log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate); + log.debug("Extended bolus start: " + extendedBolusStart); + log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes); + } + } + + @NonNull + private Date getDateFromSecAgo(int tempBasalAgoSecs) { + return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java new file mode 100644 index 0000000000..5cc8068f4d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal_v2.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; + +import android.support.annotation.NonNull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; + +public class MsgStatusTempBasal_v2 extends MessageBase { + private static Logger log = LoggerFactory.getLogger(MsgStatusTempBasal_v2.class); + + public MsgStatusTempBasal_v2() { + SetCommand(0x0205); + } + + public void handleMessage(byte[] bytes) { + boolean isTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x01) == 0x01; + boolean isAPSTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x02) == 0x02; + int tempBasalPercent = intFromBuff(bytes, 1, 1); + if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10; + int tempBasalTotalSec; + if (intFromBuff(bytes, 2, 1) == 150) tempBasalTotalSec = 15 * 60; + else if (intFromBuff(bytes, 2, 1) == 160) tempBasalTotalSec = 30 * 60; + else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60; + int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3); + int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60; + Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0); + + DanaRPump pump = DanaRPump.getInstance(); + pump.isTempBasalInProgress = isTempBasalInProgress; + pump.tempBasalPercent = tempBasalPercent; + pump.tempBasalRemainingMin = tempBasalRemainingMin; + pump.tempBasalTotalSec = tempBasalTotalSec; + pump.tempBasalStart = tempBasalStart; + + if (Config.logDanaMessageDetail) { + log.debug("Is temp basal running: " + isTempBasalInProgress); + log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress); + log.debug("Current temp basal percent: " + tempBasalPercent); + log.debug("Current temp basal remaining min: " + tempBasalRemainingMin); + log.debug("Current temp basal total sec: " + tempBasalTotalSec); + log.debug("Current temp basal start: " + tempBasalStart); + } + } + + @NonNull + private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) { + return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 72009003f6..2d1f8d9739 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -44,8 +44,11 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2; +import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2; +import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2; +import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; @@ -70,6 +73,8 @@ public class DanaRv2ExecutionService extends Service { private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); + private long lastHistoryFetched = 0; + private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -247,8 +252,8 @@ public class DanaRv2ExecutionService extends Service { MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); - MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); - MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(); + MsgStatusTempBasal_v2 tempStatusMsg = new MsgStatusTempBasal_v2(); + MsgStatusBolusExtended_v2 exStatusMsg = new MsgStatusBolusExtended_v2(); MsgCheckValue_v2 checkValue = new MsgCheckValue_v2(); if (danaRPump.isNewPump) { @@ -325,7 +330,8 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); - mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); + loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } @@ -335,8 +341,8 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent)); - mSerialIOThread.sendMessage(new MsgStatusAPS_v2()); - mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); + loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } @@ -346,7 +352,8 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); - mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); + loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } @@ -356,7 +363,8 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2()); + loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } @@ -366,12 +374,13 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); - mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2()); + loadEvents(); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); return true; } - public boolean bolus(double amount, int carbs, Treatment t) { + public boolean bolus(double amount, int carbs, long carbtime, Treatment t) { bolusingTreatment = t; MsgBolusStart start = new MsgBolusStart(amount); MsgBolusStop stop = new MsgBolusStop(amount, t); @@ -380,8 +389,11 @@ public class DanaRv2ExecutionService extends Service { if (!isConnected()) return false; if (carbs > 0) { - Calendar time = Calendar.getInstance(); - mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs)); + MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); + mSerialIOThread.sendMessage(msg); + MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, carbtime, carbs, 0); + mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); + lastHistoryFetched = carbtime - 1000; } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables MainApp.bus().post(new EventDanaRBolusStart()); @@ -402,7 +414,7 @@ public class DanaRv2ExecutionService extends Service { } waitMsec(300); bolusingTreatment = null; - getPumpStatus(); + loadEvents(); return true; } @@ -422,12 +434,14 @@ public class DanaRv2ExecutionService extends Service { } } - public boolean carbsEntry(int amount) { + public boolean carbsEntry(int amount, long time) { connect("carbsEntry"); if (!isConnected()) return false; - Calendar time = Calendar.getInstance(); MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount); mSerialIOThread.sendMessage(msg); + MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, time, amount, 0); + mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); + lastHistoryFetched = time - 1; return true; } @@ -478,12 +492,20 @@ public class DanaRv2ExecutionService extends Service { public boolean loadEvents() { if (!isConnected()) return false; - MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(); + MsgHistoryEvents_v2 msg; + if (lastHistoryFetched == 0) { + msg = new MsgHistoryEvents_v2(); + log.debug("Loading complete event history"); + } else { + msg = new MsgHistoryEvents_v2(lastHistoryFetched); + log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString()); + } mSerialIOThread.sendMessage(msg); while (!msg.done && mRfcommSocket.isConnected()) { waitMsec(100); } waitMsec(200); + lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded; return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 0e892fbc67..bbfd2ce4c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -341,7 +341,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus) { - log.debug("Adding new ExtentedBolus record" + extendedBolus); + log.debug("Adding new ExtentedBolus record" + extendedBolus.log()); MainApp.getDbHelper().createOrUpdate(extendedBolus); } @@ -350,7 +350,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { ExtendedBolus extendedBolus = new ExtendedBolus(); extendedBolus.date = time; extendedBolus.durationInMinutes = 0; - log.debug("Adding new ExtentedBolus stop record" + extendedBolus); + log.debug("Adding new ExtentedBolus stop record" + extendedBolus.log()); MainApp.getDbHelper().createOrUpdate(extendedBolus); } @@ -390,7 +390,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public void addToHistoryTempBasalStart(TemporaryBasal tempBasal) { - log.debug("Adding new TemporaryBasal record" + tempBasal); + log.debug("Adding new TemporaryBasal record" + tempBasal.log()); MainApp.getDbHelper().createOrUpdate(tempBasal); } @@ -399,7 +399,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { TemporaryBasal temporaryBasal = new TemporaryBasal(); temporaryBasal.date = time; temporaryBasal.durationInMinutes = 0; - log.debug("Adding new TemporaryBasal stop record" + temporaryBasal); + log.debug("Adding new TemporaryBasal stop record" + temporaryBasal.log()); MainApp.getDbHelper().createOrUpdate(temporaryBasal); } @@ -413,7 +413,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { treatment.source = detailedBolusInfo.source; treatment.mealBolus = treatment.carbs > 0; MainApp.getDbHelper().createOrUpdate(treatment); - log.debug("Adding new Treatment record" + treatment); + log.debug("Adding new Treatment record" + treatment.log()); if (detailedBolusInfo.carbTime != 0) { Treatment carbsTreatment = new Treatment(detailedBolusInfo.insulinInterface); carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L;