diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index 22b278abba..d3701c94b0 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -186,7 +186,6 @@ public class MainApp extends DaggerApplication {
filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_CHANGED);
- filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(new TimeDateOrTZChangeReceiver(), filter);
diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java
index b6f22aae07..f1204f8b72 100644
--- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java
+++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java
@@ -29,6 +29,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.MidnightTime;
+import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class Profile {
@@ -496,6 +497,18 @@ public class Profile {
public int timeAsSeconds;
public double value;
+
+
+ public boolean equals(Object otherObject) {
+ if (!(otherObject instanceof ProfileValue)) {
+ return false;
+ }
+
+ ProfileValue otherProfileValue = (ProfileValue) otherObject;
+
+ return (timeAsSeconds == otherProfileValue.timeAsSeconds) && Round.isSame(value, otherProfileValue.value);
+
+ }
}
public synchronized ProfileValue[] getBasalValues() {
@@ -818,4 +831,26 @@ public class Profile {
}
return new Profile(injector, o);
}
+
+
+ public boolean areProfileBasalPatternsSame(Profile otherProfile) {
+
+ if (!Round.isSame(this.baseBasalSum(), otherProfile.baseBasalSum()))
+ return false;
+
+ ProfileValue[] basalValues = this.getBasalValues();
+ ProfileValue[] otherBasalValues = otherProfile.getBasalValues();
+
+ if (basalValues.length != otherBasalValues.length)
+ return false;
+
+ for (int i = 0; i < basalValues.length; i++) {
+ if (!basalValues[i].equals(otherBasalValues[i])) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java
index e4a02883e8..0b83944d94 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java
@@ -55,6 +55,8 @@ public class PumpDescription {
public boolean supportsTDDs;
public boolean needsManualTDDLoad;
+ public boolean hasFixedUnreachableAlert;
+ public boolean hasCustomUnreachableAlertCheck;
public void resetSettings() {
isBolusCapable = true;
@@ -87,6 +89,9 @@ public class PumpDescription {
supportsTDDs = false;
needsManualTDDLoad = true;
+
+ hasFixedUnreachableAlert = false;
+ hasCustomUnreachableAlertCheck = false;
}
public void setPumpDescription(PumpType pumpType) {
@@ -134,6 +139,9 @@ public class PumpDescription {
needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad);
is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min);
+
+ hasFixedUnreachableAlert = pumpType.getHasFixedUnreachableAlert();
+ hasCustomUnreachableAlertCheck = pumpType.getHasCustomUnreachableAlertCheck();
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
index aab6d4089a..d85a383752 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
@@ -14,6 +14,7 @@ import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.utils.TimeChangeType;
/**
* Created by mike on 04.06.2016.
@@ -115,5 +116,10 @@ public interface PumpInterface {
* This method will be called when time or Timezone changes, and pump driver can then do a specific action (for
* example update clock on pump).
*/
- void timeDateOrTimeZoneChanged();
+ void timezoneOrDSTChanged(TimeChangeType timeChangeType);
+
+ /* Only used for pump types where hasCustomUnreachableAlertCheck=true */
+ default boolean isUnreachableAlertTimeoutExceeded(long alertTimeoutMilliseconds) {
+ return false;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
index c4fb00cc4c..0ec21a8014 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java
@@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.InstanceId;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@@ -1404,9 +1405,8 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
}
@Override
- public void timeDateOrTimeZoneChanged() {
-
+ public void timezoneOrDSTChanged(TimeChangeType changeType) {
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java
index 00ecd5ef0c..ebea05f906 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java
@@ -6,6 +6,7 @@ import android.content.ServiceConnection;
import androidx.annotation.NonNull;
+import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
@@ -20,6 +21,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppExit;
+import info.nightscout.androidaps.events.EventCustomActionsChanged;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
@@ -30,6 +32,7 @@ import info.nightscout.androidaps.interfaces.PumpPluginBase;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
+import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
@@ -40,6 +43,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
+import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@@ -57,6 +61,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected ActivePluginProvider activePlugin;
protected Context context;
protected FabricPrivacy fabricPrivacy;
+ protected SP sp;
/*
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
@@ -71,6 +76,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
// protected boolean isInitialized = false;
protected PumpDriverState pumpState = PumpDriverState.NotInitialized;
protected boolean displayConnectionMessages = false;
+ protected PumpType pumpType;
protected PumpPluginAbstract(
@@ -82,6 +88,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
CommandQueueProvider commandQueue,
RxBusWrapper rxBus,
ActivePluginProvider activePlugin,
+ SP sp,
Context context,
FabricPrivacy fabricPrivacy
) {
@@ -92,8 +99,10 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
this.activePlugin = activePlugin;
this.context = context;
this.fabricPrivacy = fabricPrivacy;
+ this.sp = sp;
pumpDescription.setPumpDescription(pumpType);
+ this.pumpType = pumpType;
}
@@ -435,6 +444,37 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
}
+
+ protected void refreshCustomActionsList() {
+ rxBus.send(new EventCustomActionsChanged());
+ }
+
+
+ public ManufacturerType manufacturer() {
+ return pumpType.getManufacturer() ;
+ }
+
+ @NotNull
+ public PumpType model() {
+ return pumpType;
+ }
+
+
+ public PumpType getPumpType() {
+ return pumpType;
+ }
+
+
+ public void setPumpType(PumpType pumpType) {
+ this.pumpType = pumpType;
+ }
+
+
+ public boolean canHandleDST() {
+ return false;
+ }
+
+
protected abstract PumpEnactResult deliverBolus(DetailedBolusInfo detailedBolusInfo);
protected abstract void triggerUIChange();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java
index 11fd84a016..fee0ac914d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java
@@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.pump.common.data;
-import java.util.Date;
-
import org.joda.time.LocalDateTime;
+import java.util.Date;
+
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
@@ -19,7 +19,9 @@ public abstract class PumpStatus {
public LocalDateTime lastDataTime;
public long lastConnection = 0L;
public long previousConnection = 0L; // here should be stored last connection of previous session (so needs to be
- // read before lastConnection is modified for first time).
+ // read before lastConnection is modified for first time).
+
+ public long lastErrorConnection = 0L;
// last bolus
public Date lastBolusTime;
@@ -27,10 +29,10 @@ public abstract class PumpStatus {
// other pump settings
public String activeProfileName = "0";
- public double reservoirRemainingUnits = 0d;
+ public double reservoirRemainingUnits = 0.0d;
public int reservoirFullUnits = 0;
public int batteryRemaining = 0; // percent, so 0-100
- public Double batteryVoltage = null;
+ public Double batteryVoltage = null;
// iob
@@ -68,6 +70,10 @@ public abstract class PumpStatus {
this.lastConnection = System.currentTimeMillis();
}
+ public void setLastFailedCommunicationToNow() {
+ this.lastErrorConnection = System.currentTimeMillis();
+ }
+
public abstract String getErrorInfo();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/TempBasalPair.java
new file mode 100644
index 0000000000..1e53734b5f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/TempBasalPair.java
@@ -0,0 +1,79 @@
+package info.nightscout.androidaps.plugins.pump.common.data;
+
+import com.google.gson.annotations.Expose;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import info.nightscout.androidaps.logging.L;
+
+public class TempBasalPair {
+
+ private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
+
+ @Expose
+ protected double insulinRate = 0.0d;
+ @Expose
+ protected int durationMinutes = 0;
+ @Expose
+ protected boolean isPercent = false;
+
+ private Long start;
+ private Long end;
+
+ public TempBasalPair() {
+ }
+
+
+ public TempBasalPair(double insulinRate, boolean isPercent, int durationMinutes) {
+ this.insulinRate = insulinRate;
+ this.isPercent = isPercent;
+ this.durationMinutes = durationMinutes;
+ }
+
+
+ public double getInsulinRate() {
+ return insulinRate;
+ }
+
+
+ public void setInsulinRate(double insulinRate) {
+ this.insulinRate = insulinRate;
+ }
+
+
+ public int getDurationMinutes() {
+ return durationMinutes;
+ }
+
+
+ public void setDurationMinutes(int durationMinutes) {
+ this.durationMinutes = durationMinutes;
+ }
+
+
+ public boolean isPercent() {
+ return isPercent;
+ }
+
+
+ public void setIsPercent(boolean yesIsPercent) {
+ this.isPercent = yesIsPercent;
+ }
+
+ public void setStartTime(Long startTime) {
+ this.start = startTime;
+ }
+
+
+ public void setEndTime(Long endTime) {
+ this.end = endTime;
+ }
+
+
+ @Override
+ public String toString() {
+ return "TempBasalPair [" + "Rate=" + insulinRate + ", DurationMinutes=" + durationMinutes + ", IsPercent="
+ + isPercent + "]";
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
index 074670f360..8917d3e834 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpCapability.java
@@ -23,6 +23,7 @@ public enum PumpCapability {
DanaWithHistoryCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), //
InsightCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill,TDD,BasalRate30min), //
MedtronicCapabilities(Bolus, TempBasal, BasalProfileSet, Refill, TDD), //
+ OmnipodCapabilities(Bolus, TempBasal, BasalProfileSet, BasalRate30min), //
// BasalRates (separately grouped)
BasalRate_Duration15minAllowed, //
@@ -69,4 +70,4 @@ public enum PumpCapability {
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryGroup.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.java
similarity index 95%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryGroup.java
rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.java
index 33a7c89870..48d1df3b9d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryGroup.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.java
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
+package info.nightscout.androidaps.plugins.pump.common.defs;
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +9,7 @@ import info.nightscout.androidaps.R;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
- *
+ *
* Author: Andy {andy.rozman@gmail.com}
*/
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
index 9e47bf71dd..4cd32df3f7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java
@@ -57,7 +57,14 @@ public enum PumpType {
new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
- 0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
+ 0.02d, null, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities, false, false), //
+
+ AccuChekSolo("Accu-Chek Solo", ManufacturerType.Roche, "Solo", 0.01d, null, //
+ new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
+ PumpTempBasalType.Percent,
+ new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.02d, null, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities, false, false), //
+
// Animas
AnimasVibe("Animas Vibe", ManufacturerType.Animas, "Vibe", 0.05d, null, // AnimasBolus?
@@ -91,11 +98,17 @@ public enum PumpType {
// Insulet
- Insulet_Omnipod("Insulet Omnipod", ManufacturerType.Insulet, "Omnipod", 0.05d, null, //
+ Insulet_Omnipod("Insulet Omnipod", ManufacturerType.Insulet, "Omnipod (Eros)", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
- new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
- 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities),
+ new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true, true),
+
+ Insulet_Omnipod_Dash("Insulet Omnipod Dash", ManufacturerType.Insulet, "Omnipod Dash", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Absolute, //
+ new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true, true), // TODO just copied OmniPod for now
// Medtronic
Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, //
@@ -150,6 +163,8 @@ public enum PumpType {
private double baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability;
+ private boolean hasFixedUnreachableAlert;
+ private boolean hasCustomUnreachableAlertCheck;
private PumpType parent;
private static Map mapByDescription;
@@ -184,17 +199,58 @@ public enum PumpType {
parent.model = model;
}
- PumpType(String description, ManufacturerType manufacturer, String model, double bolusSize, DoseStepSize specialBolusSize, //
+ PumpType(String description,
+ ManufacturerType manufacturer,
+ String model,
+ double bolusSize,
+ DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
- PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
- double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
+ PumpTempBasalType pumpTempBasalType,
+ DoseSettings tbrSettings,
+ PumpCapability specialBasalDurations, //
+ double baseBasalMinValue,
+ double baseBasalStep,
+ DoseStepSize baseBasalSpecialSteps,
+ PumpCapability pumpCapability) {
this(description, manufacturer, model, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
}
- PumpType(String description, ManufacturerType manufacturer, String model, double bolusSize, DoseStepSize specialBolusSize, //
+ PumpType(String description,
+ ManufacturerType manufacturer,
+ String model,
+ double bolusSize,
+ DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
- PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
- double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
+ PumpTempBasalType pumpTempBasalType,
+ DoseSettings tbrSettings,
+ PumpCapability specialBasalDurations, //
+ double baseBasalMinValue,
+ Double baseBasalMaxValue,
+ double baseBasalStep,
+ DoseStepSize baseBasalSpecialSteps,
+ PumpCapability pumpCapability) {
+ this(description, manufacturer, model, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType,
+ tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep,
+ baseBasalSpecialSteps, pumpCapability, false, false);
+ }
+
+
+ PumpType(String description,
+ ManufacturerType manufacturer,
+ String model,
+ double bolusSize,
+ DoseStepSize specialBolusSize, //
+ DoseSettings extendedBolusSettings, //
+ PumpTempBasalType pumpTempBasalType,
+ DoseSettings tbrSettings,
+ PumpCapability specialBasalDurations, //
+ double baseBasalMinValue,
+ Double baseBasalMaxValue,
+ double baseBasalStep,
+ DoseStepSize baseBasalSpecialSteps, //
+ PumpCapability pumpCapability,
+ boolean hasFixedUnreachableAlert,
+ boolean hasCustomUnreachableAlertCheck) {
this.description = description;
this.manufacturer = manufacturer;
this.model = model;
@@ -209,9 +265,19 @@ public enum PumpType {
this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability;
+ this.hasFixedUnreachableAlert = hasFixedUnreachableAlert;
+ this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck;
}
+ public boolean getHasFixedUnreachableAlert() {
+ return hasFixedUnreachableAlert;
+ }
+
+ public boolean getHasCustomUnreachableAlertCheck() {
+ return hasFixedUnreachableAlert;
+ }
+
public String getDescription() {
return description;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java
index 5a30a75fe1..47d2181252 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java
@@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import android.content.Context;
-
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
@@ -39,7 +37,6 @@ public abstract class RileyLinkCommunicationManager {
private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
protected final RFSpy rfspy;
- protected final Context context;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
protected long lastGoodReceiverCommunicationTime = 0;
@@ -52,8 +49,7 @@ public abstract class RileyLinkCommunicationManager {
private int timeoutCount = 0;
- public RileyLinkCommunicationManager(Context context, RFSpy rfspy) {
- this.context = context;
+ public RileyLinkCommunicationManager(RFSpy rfspy) {
this.rfspy = rfspy;
this.rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
RileyLinkUtil.setRileyLinkCommunicationManager(this);
@@ -66,7 +62,23 @@ public abstract class RileyLinkCommunicationManager {
// All pump communications go through this function.
- protected E sendAndListen(RLMessage msg, int timeout_ms, Class clazz)
+ public E sendAndListen(RLMessage msg, int timeout_ms, Class clazz)
+ throws RileyLinkCommunicationException {
+ return sendAndListen(msg, timeout_ms, null, clazz);
+ }
+
+ public E sendAndListen(RLMessage msg, int timeout_ms, Integer extendPreamble_ms, Class clazz)
+ throws RileyLinkCommunicationException {
+ return sendAndListen(msg, timeout_ms, 0, extendPreamble_ms, clazz);
+ }
+
+ // For backward compatibility
+ public E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, Integer extendPreamble_ms, Class clazz)
+ throws RileyLinkCommunicationException {
+ return sendAndListen(msg, timeout_ms, repeatCount, 0, extendPreamble_ms, clazz);
+ }
+
+ public E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms, Class clazz)
throws RileyLinkCommunicationException {
if (showPumpMessages) {
@@ -74,11 +86,11 @@ public abstract class RileyLinkCommunicationManager {
LOG.info("Sent:" + ByteUtil.shortHexString(msg.getTxData()));
}
- RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()), timeout_ms);
+ RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
+ (byte)0, (byte)repeatCount, (byte)0, (byte)0, timeout_ms, (byte)retryCount, extendPreamble_ms);
RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
-
- E response = createResponseMessage(rfSpyResponse.getRadioResponse().getPayload(), clazz);
+ E response = createResponseMessage(radioResponse.getPayload(), clazz);
if (response.isValid()) {
// Mark this as the last time we heard from the pump.
@@ -88,14 +100,16 @@ public abstract class RileyLinkCommunicationManager {
rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam());
if (rfSpyResponse.wasTimeout()) {
- timeoutCount++;
+ if (hasTunning()) {
+ timeoutCount++;
- long diff = System.currentTimeMillis() - pumpStatus.lastConnection;
+ long diff = System.currentTimeMillis() - pumpStatus.lastConnection;
- if (diff > ALLOWED_PUMP_UNREACHABLE) {
- LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
- ServiceTaskExecutor.startTask(new WakeAndTuneTask());
- timeoutCount = 0;
+ if (diff > ALLOWED_PUMP_UNREACHABLE) {
+ LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
+ ServiceTaskExecutor.startTask(new WakeAndTuneTask());
+ timeoutCount = 0;
+ }
}
throw new RileyLinkCommunicationException(RileyLinkBLEError.Timeout);
@@ -125,6 +139,9 @@ public abstract class RileyLinkCommunicationManager {
return rfspy != null ? rfspy.notConnectedCount : 0;
}
+ public boolean hasTunning() {
+ return true;
+ }
// FIXME change wakeup
@@ -405,7 +422,9 @@ public abstract class RileyLinkCommunicationManager {
lastGoodReceiverCommunicationTime = System.currentTimeMillis();
SP.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
- pumpStatus.setLastCommunicationToNow();
+ if(pumpStatus != null) {
+ pumpStatus.setLastCommunicationToNow();
+ }
}
@@ -437,4 +456,7 @@ public abstract class RileyLinkCommunicationManager {
return L.isEnabled(L.PUMPCOMM);
}
+ public void setPumpStatus(PumpStatus pumpStatus) {
+ this.pumpStatus = pumpStatus;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java
index 031de05e23..bb5f435f5f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java
@@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
+
import info.nightscout.androidaps.utils.SP;
/**
@@ -116,6 +117,12 @@ public class RFSpy {
}
}
+ public boolean isRileyLinkStillAvailable() {
+ RileyLinkFirmwareVersion firmwareVersion = getFirmwareVersion();
+
+ return (firmwareVersion!= RileyLinkFirmwareVersion.UnknownVersion);
+ }
+
public RileyLinkFirmwareVersion getFirmwareVersion() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java
index 69b1f245fd..595da51847 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpyReader.java
@@ -64,7 +64,7 @@ public class RFSpyReader {
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
+ " mDataQueue size is " + mDataQueue.size());
- if (mDataQueue.isEmpty())
+ if (mDataQueue.isEmpty()) {
try {
// block until timeout or data available.
// returns null if timeout.
@@ -72,7 +72,7 @@ public class RFSpyReader {
if (dataFromQueue != null) {
if (isLogEnabled())
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
- + SystemClock.uptimeMillis());
+ + SystemClock.uptimeMillis());
} else {
if (isLogEnabled())
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
@@ -81,6 +81,8 @@ public class RFSpyReader {
} catch (InterruptedException e) {
LOG.error("poll: Interrupted waiting for data");
}
+ }
+
return null;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkCommunicationException.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkCommunicationException.java
index e694609571..4a1ff7bdb0 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkCommunicationException.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkCommunicationException.java
@@ -27,4 +27,7 @@ public class RileyLinkCommunicationException extends Exception {
// this.extendedErrorText = extendedErrorText;
}
+ public RileyLinkBLEError getErrorCode() {
+ return errorCode;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java
index a887fede5c..be6cfb3e2d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/data/RLHistoryItem.java
@@ -97,7 +97,8 @@ public class RLHistoryItem {
public enum RLHistoryItemSource {
RileyLink("RileyLink"), //
MedtronicPump("Medtronic"), //
- MedtronicCommand("Medtronic");
+ MedtronicCommand("Medtronic"), //
+ OmnipodCommand("Omnipod");
private String desc;
@@ -112,4 +113,12 @@ public class RLHistoryItem {
}
}
+ public static class Comparator implements java.util.Comparator {
+
+ @Override
+ public int compare(RLHistoryItem o1, RLHistoryItem o2) {
+ return o2.dateTime.compareTo(o1.dateTime);
+ }
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistory.java
index d6af799550..ae32018111 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistory.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistory.java
@@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import android.os.Bundle;
@@ -12,12 +13,15 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
+
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
+import info.nightscout.androidaps.utils.DateUtil;
/**
* Created by andy on 5/19/18.
@@ -83,6 +87,8 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
public void addItemsAndClean(List items) {
this.historyList.clear();
+ Collections.sort(items, new RLHistoryItem.Comparator());
+
for (RLHistoryItem item : items) {
if (!historyList.contains(item) && isValidItem(item)) {
@@ -110,6 +116,7 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
}
+ @NotNull
@Override
public RecyclerViewAdapter.HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rileylink_status_history_item, //
@@ -123,7 +130,7 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
RLHistoryItem item = historyList.get(position);
if (item != null) {
- holder.timeView.setText(StringUtil.toDateTimeString(item.getDateTime()));
+ holder.timeView.setText(DateUtil.dateAndTimeAndSecondsString(item.getDateTime().toDateTime().getMillis()));
holder.typeView.setText(item.getSource().getDesc());
holder.valueView.setText(item.getDescription());
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java
index 0b697fe6eb..41c4028f96 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java
@@ -48,7 +48,6 @@ public abstract class RileyLinkService extends DaggerService {
@Override
public void onCreate() {
super.onCreate();
- //LOG.debug("onCreate");
RileyLinkUtil.setContext(this.context);
RileyLinkUtil.setRileyLinkService(this);
@@ -61,8 +60,6 @@ public abstract class RileyLinkService extends DaggerService {
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
bluetoothStateReceiver.registerBroadcasts(this);
-
- //LOG.debug("onCreate(): It's ALIVE!");
}
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ByteUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ByteUtil.java
index 5451689ebe..6923b42020 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ByteUtil.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ByteUtil.java
@@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.utils;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -28,6 +29,14 @@ public class ByteUtil {
return (b < 0) ? b + 256 : b;
}
+ public static byte[] getBytesFromInt16(int value) {
+ byte[] array = getBytesFromInt(value);
+ return new byte[] {array[2], array[3]};
+ }
+
+ public static byte[] getBytesFromInt(int value) {
+ return ByteBuffer.allocate(4).putInt(value).array();
+ }
/* For Reference: static void System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) */
@@ -107,6 +116,21 @@ public class ByteUtil {
return rval;
}
+ public static String shortHexStringWithoutSpaces(byte[] byteArray) {
+ String hexString = "";
+ if (byteArray == null) {
+ return hexString;
+ }
+ if (byteArray.length == 0) {
+ return hexString;
+ }
+ for (byte b : byteArray) {
+ hexString = hexString + HEX_DIGITS[(b & 0xF0) >> 4];
+ hexString = hexString + HEX_DIGITS[(b & 0x0F)];
+ }
+ return hexString;
+ }
+
public static String shortHexString(List list) {
byte[] abyte0 = getByteArrayFromList(list);
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 17dfd96083..7db9fcfb5a 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
@@ -120,6 +120,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() && //
@@ -276,4 +284,21 @@ public class DateTimeUtil {
}
+ public static long getTimeInFutureFromMinutes(long startTime, int minutes) {
+ return startTime + getTimeInMs(minutes);
+ }
+
+ public static long getTimeInFutureFromMinutes(int minutes) {
+ return System.currentTimeMillis() + getTimeInMs(minutes);
+ }
+
+
+ public static long getTimeInMs(int minutes) {
+ return getTimeInS(minutes) * 1000L;
+ }
+
+ public static int getTimeInS(int minutes) {
+ return minutes * 60;
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java
new file mode 100644
index 0000000000..5f1dd3c6ef
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java
@@ -0,0 +1,54 @@
+package info.nightscout.androidaps.plugins.pump.common.utils;
+
+import java.util.Locale;
+
+import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+
+public class ProfileUtil {
+
+
+ public static String getProfileDisplayable(Profile profile, PumpType pumpType) {
+
+ StringBuilder stringBuilder = new StringBuilder();
+
+ for (Profile.ProfileValue basalValue : profile.getBasalValues()) {
+
+ double basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value);
+
+ int hour = basalValue.timeAsSeconds / (60 * 60);
+
+ stringBuilder.append((hour < 10 ? "0" : "") + hour + ":00");
+
+ stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValueValue));
+ stringBuilder.append(", ");
+ }
+ if (stringBuilder.length() > 3)
+ return stringBuilder.toString().substring(0, stringBuilder.length() - 2);
+ else
+ return stringBuilder.toString();
+ }
+
+ public static String getBasalProfilesDisplayable(Profile.ProfileValue[] profiles, PumpType pumpType) {
+
+ StringBuilder stringBuilder = new StringBuilder();
+
+ for (Profile.ProfileValue basalValue : profiles) {
+
+ double basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value);
+
+ int hour = basalValue.timeAsSeconds / (60 * 60);
+
+ stringBuilder.append((hour < 10 ? "0" : "") + hour + ":00");
+
+ stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValueValue));
+ stringBuilder.append(", ");
+ }
+ if (stringBuilder.length() > 3)
+ return stringBuilder.toString().substring(0, stringBuilder.length() - 2);
+ else
+ return stringBuilder.toString();
+ }
+
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java
index ed7e4e2634..f7d86e5774 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/StringUtil.java
@@ -7,6 +7,8 @@ import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
+import info.nightscout.androidaps.utils.DateUtil;
+
/**
* Created by geoff on 4/28/15.
* modified by Andy
@@ -83,7 +85,8 @@ public class StringUtil {
public static String toDateTimeString(LocalDateTime localDateTime) {
- return localDateTime.toString("dd.MM.yyyy HH:mm:ss");
+ return DateUtil.dateAndTimeAndSecondsString(localDateTime.toDateTime().getMillis());
+ //return localDateTime.toString("dd.MM.yyyy HH:mm:ss");
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
index b448990575..4fe2815bdc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java
@@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.Round;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@@ -485,8 +486,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
}
@Override
- public void timeDateOrTimeZoneChanged() {
-
+ public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
index 13c41933f5..2227c905a9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java
@@ -61,6 +61,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.T;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
@@ -826,8 +827,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
}
@Override
- public void timeDateOrTimeZoneChanged() {
-
+ public void timezoneOrDSTChanged(TimeChangeType changeType) {
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java
index efc14fed0d..0b3a513bf5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java
@@ -135,6 +135,7 @@ import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@@ -1684,8 +1685,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
}
@Override
- public void timeDateOrTimeZoneChanged() {
-
+ public void timezoneOrDSTChanged(TimeChangeType changeType) {
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java
index d494912990..b5d7fafb4e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java
@@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.InstanceId;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@@ -289,7 +290,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
}
@Override
- public void timeDateOrTimeZoneChanged() {
+ public void timezoneOrDSTChanged(TimeChangeType changeType) {
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java
index 19e6abebe1..523a9c5f53 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java
@@ -81,6 +81,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtro
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
+import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@@ -94,8 +95,6 @@ import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUt
@Singleton
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
- private final SP sp;
-
protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService;
private MedtronicPumpStatus pumpStatusLocal = null;
@@ -135,7 +134,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), //
PumpType.Medtronic_522_722, // we default to most basic model, correct model from config is loaded later
- injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, context, fabricPrivacy
+ injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy
);
this.plugin = this;
@@ -1569,17 +1568,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
- public void timeDateOrTimeZoneChanged() {
+ public void timezoneOrDSTChanged(TimeChangeType changeType) {
- aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. ");
+ aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time or TimeZone changed. ");
this.hasTimeDateOrTimeZoneChanged = true;
}
- private void refreshCustomActionsList() {
- rxBus.send(new EventCustomActionsChanged());
- }
-
public void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java
index 81d1425e91..261e53e7ab 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java
@@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm;
-import android.content.Context;
import android.os.SystemClock;
import org.joda.time.LocalDateTime;
@@ -72,8 +71,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean doWakeUpBeforeCommand = true;
- public MedtronicCommunicationManager(Context context, RFSpy rfspy) {
- super(context, rfspy);
+ public MedtronicCommunicationManager(RFSpy rfspy) {
+ super(rfspy);
medtronicCommunicationManager = this;
this.medtronicConverter = new MedtronicConverter();
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.java
index 90cb11f71f..51b8993b05 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.java
@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java
index 850df2ccc0..83ee3baf03 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java
@@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
-import com.google.gson.annotations.Expose;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -19,18 +17,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
*
* Just need a class to keep the pair together, for parcel transport.
*/
-public class TempBasalPair {
+public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
- @Expose
- private double insulinRate = 0.0d;
- @Expose
- private int durationMinutes = 0;
- @Expose
- private boolean isPercent = false;
-
-
public TempBasalPair() {
}
@@ -43,6 +33,8 @@ public class TempBasalPair {
* @param isPercent
*/
public TempBasalPair(byte rateByte, int startTimeByte, boolean isPercent) {
+ super();
+
int rateInt = ByteUtil.asUINT8(rateByte);
if (isPercent)
@@ -54,13 +46,6 @@ public class TempBasalPair {
}
- public TempBasalPair(double insulinRate, boolean isPercent, int durationMinutes) {
- this.insulinRate = insulinRate;
- this.isPercent = isPercent;
- this.durationMinutes = durationMinutes;
- }
-
-
public TempBasalPair(byte[] response) {
if (L.isEnabled(L.PUMPCOMM))
@@ -87,33 +72,8 @@ public class TempBasalPair {
}
- public double getInsulinRate() {
- return insulinRate;
- }
-
-
- public void setInsulinRate(double insulinRate) {
- this.insulinRate = insulinRate;
- }
-
-
- public int getDurationMinutes() {
- return durationMinutes;
- }
-
-
- public void setDurationMinutes(int durationMinutes) {
- this.durationMinutes = durationMinutes;
- }
-
-
- public boolean isPercent() {
- return isPercent;
- }
-
-
- public void setIsPercent(boolean yesIsPercent) {
- this.isPercent = yesIsPercent;
+ public TempBasalPair(double insulinRate, boolean isPercent, int durationMinutes) {
+ super(insulinRate, isPercent, durationMinutes);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.java
index 75577098d0..e4673fbc5d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.java
@@ -20,9 +20,10 @@ import javax.inject.Inject;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
-import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryGroup;
+
public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java
index 255696aba4..0de5e3f355 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java
@@ -102,7 +102,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager
- medtronicCommunicationManager = new MedtronicCommunicationManager(context, rfspy);
+ medtronicCommunicationManager = new MedtronicCommunicationManager(rfspy);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
MedtronicUtil.setMedtronicService(this);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt
index 304d8177e3..4854112fc3 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt
@@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.InstanceId.instanceId
+import info.nightscout.androidaps.utils.TimeChangeType
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@@ -409,5 +410,6 @@ class VirtualPumpPlugin @Inject constructor(
pumpType = pumpTypeNew
}
- override fun timeDateOrTimeZoneChanged() {}
-}
\ No newline at end of file
+ override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {}
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.kt
index 3aa1c2122d..46cf58d99f 100644
--- a/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.kt
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.kt
@@ -2,25 +2,74 @@ package info.nightscout.androidaps.receivers
import android.content.Context
import android.content.Intent
+import com.google.gson.Gson
import dagger.android.DaggerBroadcastReceiver
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.PumpInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
+import info.nightscout.androidaps.utils.TimeChangeType
+import java.util.*
import javax.inject.Inject
class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePluginProvider
+ var gson: Gson
+
+ private var isDST = false
+
+ init {
+ isDST = calculateDST()
+ gson = Gson()
+ }
+
+ private fun calculateDST(): Boolean {
+ val timeZone = TimeZone.getDefault()
+ val nowDate = Date()
+ return if (timeZone.useDaylightTime()) {
+ timeZone.inDaylightTime(nowDate)
+ } else {
+ false
+ }
+ }
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
val action = intent.action
val activePump: PumpInterface = activePlugin.activePump
- aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
- if (action != null) {
- aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
- activePump.timeDateOrTimeZoneChanged()
+ if (activePump == null) {
+ aapsLogger.debug(LTag.PUMP,"TimeDateOrTZChangeReceiver::Time and/or TimeZone changed. [action={}]. Pump is null, exiting.", action)
+ return
+ }
+
+ aapsLogger.debug(LTag.PUMP,"TimeDateOrTZChangeReceiver::Date, Time and/or TimeZone changed. [action={}]", action)
+ aapsLogger.debug(LTag.PUMP,"TimeDateOrTZChangeReceiver::Intent::{}", gson.toJson(intent))
+
+ if (action == null) {
+ aapsLogger.error(LTag.PUMP,"TimeDateOrTZChangeReceiver::Action is null. Exiting.")
+ } else if (Intent.ACTION_TIMEZONE_CHANGED == action) {
+ aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::Timezone changed. Notifying pump driver.")
+ activePump.timezoneOrDSTChanged(TimeChangeType.TimezoneChange)
+ } else if (Intent.ACTION_TIME_CHANGED == action) {
+ val currentDst = calculateDST()
+ if (currentDst == isDST) {
+ aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::Time changed (manual). Notifying pump driver.")
+ activePump.timezoneOrDSTChanged(TimeChangeType.ManualTimeChange)
+ } else {
+ if (currentDst) {
+ aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::DST started. Notifying pump driver.")
+ activePump.timezoneOrDSTChanged(TimeChangeType.DST_Started)
+ } else {
+ aapsLogger.info(LTag.PUMP,"TimeDateOrTZChangeReceiver::DST ended. Notifying pump driver.")
+ activePump.timezoneOrDSTChanged(TimeChangeType.DST_Ended)
+ }
+ }
+ isDST = currentDst
+ } else {
+ aapsLogger.error(LTag.PUMP,"TimeDateOrTZChangeReceiver::Unknown action received [name={}]. Exiting.", action)
}
}
-}
\ No newline at end of file
+
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/Round.java b/app/src/main/java/info/nightscout/androidaps/utils/Round.java
index 3e312a20a9..bc3c5d8b9c 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/Round.java
+++ b/app/src/main/java/info/nightscout/androidaps/utils/Round.java
@@ -19,16 +19,25 @@ public class Round {
return newCalc;
}
+
public static Double floorTo(Double x, Double step) {
if (x != 0d) {
return Math.floor(x / step) * step;
}
return 0d;
}
+
public static Double ceilTo(Double x, Double step) {
if (x != 0d) {
return Math.ceil(x / step) * step;
}
return 0d;
}
+
+ public static boolean isSame(Double d1, Double d2) {
+ double diff = d1 - d2;
+
+ return (Math.abs(diff) <= 0.000001);
+ }
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeChangeType.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeChangeType.java
new file mode 100644
index 0000000000..720ecc1a1b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeChangeType.java
@@ -0,0 +1,8 @@
+package info.nightscout.androidaps.utils;
+
+public enum TimeChangeType {
+ TimezoneChange,
+ DST_Started,
+ DST_Ended,
+ ManualTimeChange
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bb5868cd66..b0f6821b69 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1557,7 +1557,7 @@
Scanning
Scanning finished
Scanning error: %1$d
-
+ Never
Settings
@@ -1710,6 +1710,7 @@
Clear started
Time detection
Do you want reset objective start? You may lose your progress.
+ Time and/or Timezone change on pump
No pump selected
Select units you want to display values in
ns_uploadlocalprofile
diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java
index a8a8b840a2..3233d4e1e4 100644
--- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java
+++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java
@@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.junit.Before;
import org.junit.Ignore;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
/**