Merge pull request #2596 from AAPS-Omnipod/dagger_omnipod_common

Dagger omnipod common
This commit is contained in:
Milos Kozak 2020-04-26 10:51:54 +02:00 committed by GitHub
commit 777dd9f91d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 542 additions and 122 deletions

View file

@ -186,7 +186,6 @@ public class MainApp extends DaggerApplication {
filter = new IntentFilter(); filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(new TimeDateOrTZChangeReceiver(), filter); registerReceiver(new TimeDateOrTZChangeReceiver(), filter);

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.MidnightTime; import info.nightscout.androidaps.utils.MidnightTime;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class Profile { public class Profile {
@ -496,6 +497,18 @@ public class Profile {
public int timeAsSeconds; public int timeAsSeconds;
public double value; 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() { public synchronized ProfileValue[] getBasalValues() {
@ -818,4 +831,26 @@ public class Profile {
} }
return new Profile(injector, o); 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;
}
} }

View file

@ -55,6 +55,8 @@ public class PumpDescription {
public boolean supportsTDDs; public boolean supportsTDDs;
public boolean needsManualTDDLoad; public boolean needsManualTDDLoad;
public boolean hasFixedUnreachableAlert;
public boolean hasCustomUnreachableAlertCheck;
public void resetSettings() { public void resetSettings() {
isBolusCapable = true; isBolusCapable = true;
@ -87,6 +89,9 @@ public class PumpDescription {
supportsTDDs = false; supportsTDDs = false;
needsManualTDDLoad = true; needsManualTDDLoad = true;
hasFixedUnreachableAlert = false;
hasCustomUnreachableAlertCheck = false;
} }
public void setPumpDescription(PumpType pumpType) { public void setPumpDescription(PumpType pumpType) {
@ -134,6 +139,9 @@ public class PumpDescription {
needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad); needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad);
is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min); is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min);
hasFixedUnreachableAlert = pumpType.getHasFixedUnreachableAlert();
hasCustomUnreachableAlertCheck = pumpType.getHasCustomUnreachableAlertCheck();
} }
} }

View file

@ -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.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.utils.TimeChangeType;
/** /**
* Created by mike on 04.06.2016. * 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 * 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). * 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;
}
} }

View file

@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.InstanceId; import info.nightscout.androidaps.utils.InstanceId;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -1404,8 +1405,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@Override @Override
public void timeDateOrTimeZoneChanged() { public void timezoneOrDSTChanged(TimeChangeType changeType) {
} }

View file

@ -6,6 +6,7 @@ import android.content.ServiceConnection;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; 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.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventCustomActionsChanged;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; 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.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; 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.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState; 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.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -57,6 +61,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected ActivePluginProvider activePlugin; protected ActivePluginProvider activePlugin;
protected Context context; protected Context context;
protected FabricPrivacy fabricPrivacy; protected FabricPrivacy fabricPrivacy;
protected SP sp;
/* /*
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false) 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 boolean isInitialized = false;
protected PumpDriverState pumpState = PumpDriverState.NotInitialized; protected PumpDriverState pumpState = PumpDriverState.NotInitialized;
protected boolean displayConnectionMessages = false; protected boolean displayConnectionMessages = false;
protected PumpType pumpType;
protected PumpPluginAbstract( protected PumpPluginAbstract(
@ -82,6 +88,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
RxBusWrapper rxBus, RxBusWrapper rxBus,
ActivePluginProvider activePlugin, ActivePluginProvider activePlugin,
SP sp,
Context context, Context context,
FabricPrivacy fabricPrivacy FabricPrivacy fabricPrivacy
) { ) {
@ -92,8 +99,10 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
this.activePlugin = activePlugin; this.activePlugin = activePlugin;
this.context = context; this.context = context;
this.fabricPrivacy = fabricPrivacy; this.fabricPrivacy = fabricPrivacy;
this.sp = sp;
pumpDescription.setPumpDescription(pumpType); 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 PumpEnactResult deliverBolus(DetailedBolusInfo detailedBolusInfo);
protected abstract void triggerUIChange(); protected abstract void triggerUIChange();

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.pump.common.data; package info.nightscout.androidaps.plugins.pump.common.data;
import java.util.Date;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import java.util.Date;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
@ -21,13 +21,15 @@ public abstract class PumpStatus {
public long previousConnection = 0L; // here should be stored last connection of previous session (so needs to be 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 // last bolus
public Date lastBolusTime; public Date lastBolusTime;
public Double lastBolusAmount; public Double lastBolusAmount;
// other pump settings // other pump settings
public String activeProfileName = "0"; public String activeProfileName = "0";
public double reservoirRemainingUnits = 0d; public double reservoirRemainingUnits = 0.0d;
public int reservoirFullUnits = 0; public int reservoirFullUnits = 0;
public int batteryRemaining = 0; // percent, so 0-100 public int batteryRemaining = 0; // percent, so 0-100
public Double batteryVoltage = null; public Double batteryVoltage = null;
@ -68,6 +70,10 @@ public abstract class PumpStatus {
this.lastConnection = System.currentTimeMillis(); this.lastConnection = System.currentTimeMillis();
} }
public void setLastFailedCommunicationToNow() {
this.lastErrorConnection = System.currentTimeMillis();
}
public abstract String getErrorInfo(); public abstract String getErrorInfo();

View file

@ -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 + "]";
}
}

View file

@ -23,6 +23,7 @@ public enum PumpCapability {
DanaWithHistoryCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), // DanaWithHistoryCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), //
InsightCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill,TDD,BasalRate30min), // InsightCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill,TDD,BasalRate30min), //
MedtronicCapabilities(Bolus, TempBasal, BasalProfileSet, Refill, TDD), // MedtronicCapabilities(Bolus, TempBasal, BasalProfileSet, Refill, TDD), //
OmnipodCapabilities(Bolus, TempBasal, BasalProfileSet, BasalRate30min), //
// BasalRates (separately grouped) // BasalRates (separately grouped)
BasalRate_Duration15minAllowed, // BasalRate_Duration15minAllowed, //

View file

@ -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.ArrayList;
import java.util.List; 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 * This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS. * management and modified/extended for AAPS.
* * <p>
* Author: Andy {andy.rozman@gmail.com} * Author: Andy {andy.rozman@gmail.com}
*/ */

View file

@ -57,7 +57,14 @@ public enum PumpType {
new DoseSettings(0.01d, 15, 24 * 60, 0.05d), // new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // 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 // Animas
AnimasVibe("Animas Vibe", ManufacturerType.Animas, "Vibe", 0.05d, null, // AnimasBolus? AnimasVibe("Animas Vibe", ManufacturerType.Animas, "Vibe", 0.05d, null, // AnimasBolus?
@ -91,11 +98,17 @@ public enum PumpType {
// Insulet // 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), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), 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
Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, // Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, //
@ -150,6 +163,8 @@ public enum PumpType {
private double baseBasalStep; // private double baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; // private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability; private PumpCapability pumpCapability;
private boolean hasFixedUnreachableAlert;
private boolean hasCustomUnreachableAlertCheck;
private PumpType parent; private PumpType parent;
private static Map<String, PumpType> mapByDescription; private static Map<String, PumpType> mapByDescription;
@ -184,17 +199,58 @@ public enum PumpType {
parent.model = model; 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, // DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // PumpTempBasalType pumpTempBasalType,
double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) { 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); 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, // DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // PumpTempBasalType pumpTempBasalType,
double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) { 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.description = description;
this.manufacturer = manufacturer; this.manufacturer = manufacturer;
this.model = model; this.model = model;
@ -209,9 +265,19 @@ public enum PumpType {
this.baseBasalStep = baseBasalStep; this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps; this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability; this.pumpCapability = pumpCapability;
this.hasFixedUnreachableAlert = hasFixedUnreachableAlert;
this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck;
} }
public boolean getHasFixedUnreachableAlert() {
return hasFixedUnreachableAlert;
}
public boolean getHasCustomUnreachableAlertCheck() {
return hasFixedUnreachableAlert;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import android.content.Context;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; 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 private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
protected final RFSpy rfspy; protected final RFSpy rfspy;
protected final Context context;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation 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 String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
protected long lastGoodReceiverCommunicationTime = 0; protected long lastGoodReceiverCommunicationTime = 0;
@ -52,8 +49,7 @@ public abstract class RileyLinkCommunicationManager {
private int timeoutCount = 0; private int timeoutCount = 0;
public RileyLinkCommunicationManager(Context context, RFSpy rfspy) { public RileyLinkCommunicationManager(RFSpy rfspy) {
this.context = context;
this.rfspy = rfspy; this.rfspy = rfspy;
this.rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData(); this.rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
RileyLinkUtil.setRileyLinkCommunicationManager(this); RileyLinkUtil.setRileyLinkCommunicationManager(this);
@ -66,7 +62,23 @@ public abstract class RileyLinkCommunicationManager {
// All pump communications go through this function. // All pump communications go through this function.
protected <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz) public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz)
throws RileyLinkCommunicationException {
return sendAndListen(msg, timeout_ms, null, clazz);
}
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Integer extendPreamble_ms, Class<E> clazz)
throws RileyLinkCommunicationException {
return sendAndListen(msg, timeout_ms, 0, extendPreamble_ms, clazz);
}
// For backward compatibility
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, Integer extendPreamble_ms, Class<E> clazz)
throws RileyLinkCommunicationException {
return sendAndListen(msg, timeout_ms, repeatCount, 0, extendPreamble_ms, clazz);
}
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms, Class<E> clazz)
throws RileyLinkCommunicationException { throws RileyLinkCommunicationException {
if (showPumpMessages) { if (showPumpMessages) {
@ -74,11 +86,11 @@ public abstract class RileyLinkCommunicationManager {
LOG.info("Sent:" + ByteUtil.shortHexString(msg.getTxData())); 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(); RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
E response = createResponseMessage(radioResponse.getPayload(), clazz);
E response = createResponseMessage(rfSpyResponse.getRadioResponse().getPayload(), clazz);
if (response.isValid()) { if (response.isValid()) {
// Mark this as the last time we heard from the pump. // Mark this as the last time we heard from the pump.
@ -88,6 +100,7 @@ public abstract class RileyLinkCommunicationManager {
rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam()); rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam());
if (rfSpyResponse.wasTimeout()) { if (rfSpyResponse.wasTimeout()) {
if (hasTunning()) {
timeoutCount++; timeoutCount++;
long diff = System.currentTimeMillis() - pumpStatus.lastConnection; long diff = System.currentTimeMillis() - pumpStatus.lastConnection;
@ -97,6 +110,7 @@ public abstract class RileyLinkCommunicationManager {
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask());
timeoutCount = 0; timeoutCount = 0;
} }
}
throw new RileyLinkCommunicationException(RileyLinkBLEError.Timeout); throw new RileyLinkCommunicationException(RileyLinkBLEError.Timeout);
} else if (rfSpyResponse.wasInterrupted()) { } else if (rfSpyResponse.wasInterrupted()) {
@ -125,6 +139,9 @@ public abstract class RileyLinkCommunicationManager {
return rfspy != null ? rfspy.notConnectedCount : 0; return rfspy != null ? rfspy.notConnectedCount : 0;
} }
public boolean hasTunning() {
return true;
}
// FIXME change wakeup // FIXME change wakeup
@ -405,8 +422,10 @@ public abstract class RileyLinkCommunicationManager {
lastGoodReceiverCommunicationTime = System.currentTimeMillis(); lastGoodReceiverCommunicationTime = System.currentTimeMillis();
SP.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime); SP.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
if(pumpStatus != null) {
pumpStatus.setLastCommunicationToNow(); pumpStatus.setLastCommunicationToNow();
} }
}
private long getLastGoodReceiverCommunicationTime() { private long getLastGoodReceiverCommunicationTime() {
@ -437,4 +456,7 @@ public abstract class RileyLinkCommunicationManager {
return L.isEnabled(L.PUMPCOMM); return L.isEnabled(L.PUMPCOMM);
} }
public void setPumpStatus(PumpStatus pumpStatus) {
this.pumpStatus = pumpStatus;
}
} }

View file

@ -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.StringUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.utils.SP; 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() { public RileyLinkFirmwareVersion getFirmwareVersion() {

View file

@ -64,7 +64,7 @@ public class RFSpyReader {
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
+ " mDataQueue size is " + mDataQueue.size()); + " mDataQueue size is " + mDataQueue.size());
if (mDataQueue.isEmpty()) if (mDataQueue.isEmpty()) {
try { try {
// block until timeout or data available. // block until timeout or data available.
// returns null if timeout. // returns null if timeout.
@ -81,6 +81,8 @@ public class RFSpyReader {
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.error("poll: Interrupted waiting for data"); LOG.error("poll: Interrupted waiting for data");
} }
}
return null; return null;
} }

View file

@ -27,4 +27,7 @@ public class RileyLinkCommunicationException extends Exception {
// this.extendedErrorText = extendedErrorText; // this.extendedErrorText = extendedErrorText;
} }
public RileyLinkBLEError getErrorCode() {
return errorCode;
}
} }

View file

@ -97,7 +97,8 @@ public class RLHistoryItem {
public enum RLHistoryItemSource { public enum RLHistoryItemSource {
RileyLink("RileyLink"), // RileyLink("RileyLink"), //
MedtronicPump("Medtronic"), // MedtronicPump("Medtronic"), //
MedtronicCommand("Medtronic"); MedtronicCommand("Medtronic"), //
OmnipodCommand("Omnipod");
private String desc; private String desc;
@ -112,4 +113,12 @@ public class RLHistoryItem {
} }
} }
public static class Comparator implements java.util.Comparator<RLHistoryItem> {
@Override
public int compare(RLHistoryItem o1, RLHistoryItem o2) {
return o2.dateTime.compareTo(o1.dateTime);
}
}
} }

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import android.os.Bundle; import android.os.Bundle;
@ -12,12 +13,15 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; 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.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; 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.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.utils.DateUtil;
/** /**
* Created by andy on 5/19/18. * Created by andy on 5/19/18.
@ -83,6 +87,8 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
public void addItemsAndClean(List<RLHistoryItem> items) { public void addItemsAndClean(List<RLHistoryItem> items) {
this.historyList.clear(); this.historyList.clear();
Collections.sort(items, new RLHistoryItem.Comparator());
for (RLHistoryItem item : items) { for (RLHistoryItem item : items) {
if (!historyList.contains(item) && isValidItem(item)) { if (!historyList.contains(item) && isValidItem(item)) {
@ -110,6 +116,7 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
} }
@NotNull
@Override @Override
public RecyclerViewAdapter.HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public RecyclerViewAdapter.HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rileylink_status_history_item, // 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); RLHistoryItem item = historyList.get(position);
if (item != null) { 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.typeView.setText(item.getSource().getDesc());
holder.valueView.setText(item.getDescription()); holder.valueView.setText(item.getDescription());
} }

View file

@ -48,7 +48,6 @@ public abstract class RileyLinkService extends DaggerService {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
//LOG.debug("onCreate");
RileyLinkUtil.setContext(this.context); RileyLinkUtil.setContext(this.context);
RileyLinkUtil.setRileyLinkService(this); RileyLinkUtil.setRileyLinkService(this);
@ -61,8 +60,6 @@ public abstract class RileyLinkService extends DaggerService {
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver(); bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
bluetoothStateReceiver.registerBroadcasts(this); bluetoothStateReceiver.registerBroadcasts(this);
//LOG.debug("onCreate(): It's ALIVE!");
} }
/** /**

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.utils; package info.nightscout.androidaps.plugins.pump.common.utils;
import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,6 +29,14 @@ public class ByteUtil {
return (b < 0) ? b + 256 : b; 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) */ /* 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; 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<Byte> list) { public static String shortHexString(List<Byte> list) {
byte[] abyte0 = getByteArrayFromList(list); byte[] abyte0 = getByteArrayFromList(list);

View file

@ -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) { public static boolean isSameDay(LocalDateTime ldt1, LocalDateTime ldt2) {
return (ldt1.getYear() == ldt2.getYear() && // 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;
}
} }

View file

@ -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();
}
}

View file

@ -7,6 +7,8 @@ import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.utils.DateUtil;
/** /**
* Created by geoff on 4/28/15. * Created by geoff on 4/28/15.
* modified by Andy * modified by Andy
@ -83,7 +85,8 @@ public class StringUtil {
public static String toDateTimeString(LocalDateTime localDateTime) { 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");
} }

View file

@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -485,8 +486,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@Override @Override
public void timeDateOrTimeZoneChanged() { public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
} }

View file

@ -61,6 +61,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -826,8 +827,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
} }
@Override @Override
public void timeDateOrTimeZoneChanged() { public void timezoneOrDSTChanged(TimeChangeType changeType) {
} }
} }

View file

@ -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.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -1684,8 +1685,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
} }
@Override @Override
public void timeDateOrTimeZoneChanged() { public void timezoneOrDSTChanged(TimeChangeType changeType) {
} }
} }

View file

@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.InstanceId; import info.nightscout.androidaps.utils.InstanceId;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -289,7 +290,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@Override @Override
public void timeDateOrTimeZoneChanged() { public void timezoneOrDSTChanged(TimeChangeType changeType) {
} }

View file

@ -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.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -94,8 +95,6 @@ import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUt
@Singleton @Singleton
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface { public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
private final SP sp;
protected static MedtronicPumpPlugin plugin = null; protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService; private RileyLinkMedtronicService medtronicService;
private MedtronicPumpStatus pumpStatusLocal = null; private MedtronicPumpStatus pumpStatusLocal = null;
@ -135,7 +134,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.shortName(R.string.medtronic_name_short) // .shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), // .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 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; this.plugin = this;
@ -1569,17 +1568,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@Override @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; this.hasTimeDateOrTimeZoneChanged = true;
} }
private void refreshCustomActionsList() {
rxBus.send(new EventCustomActionsChanged());
}
public void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) { public void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm; package info.nightscout.androidaps.plugins.pump.medtronic.comm;
import android.content.Context;
import android.os.SystemClock; import android.os.SystemClock;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
@ -72,8 +71,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean doWakeUpBeforeCommand = true; private boolean doWakeUpBeforeCommand = true;
public MedtronicCommunicationManager(Context context, RFSpy rfspy) { public MedtronicCommunicationManager(RFSpy rfspy) {
super(context, rfspy); super(rfspy);
medtronicCommunicationManager = this; medtronicCommunicationManager = this;
this.medtronicConverter = new MedtronicConverter(); this.medtronicConverter = new MedtronicConverter();
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder(); this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto; package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import com.google.gson.annotations.Expose;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -19,18 +17,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
* <p> * <p>
* Just need a class to keep the pair together, for parcel transport. * 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); 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() { public TempBasalPair() {
} }
@ -43,6 +33,8 @@ public class TempBasalPair {
* @param isPercent * @param isPercent
*/ */
public TempBasalPair(byte rateByte, int startTimeByte, boolean isPercent) { public TempBasalPair(byte rateByte, int startTimeByte, boolean isPercent) {
super();
int rateInt = ByteUtil.asUINT8(rateByte); int rateInt = ByteUtil.asUINT8(rateByte);
if (isPercent) 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) { public TempBasalPair(byte[] response) {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
@ -87,33 +72,8 @@ public class TempBasalPair {
} }
public double getInsulinRate() { public TempBasalPair(double insulinRate, boolean isPercent, int durationMinutes) {
return insulinRate; super(insulinRate, isPercent, durationMinutes);
}
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;
} }

View file

@ -20,9 +20,10 @@ import javax.inject.Inject;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; 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.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry; 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 { public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {

View file

@ -102,7 +102,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE); RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager // init rileyLinkCommunicationManager
medtronicCommunicationManager = new MedtronicCommunicationManager(context, rfspy); medtronicCommunicationManager = new MedtronicCommunicationManager(rfspy);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed"); aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
MedtronicUtil.setMedtronicService(this); MedtronicUtil.setMedtronicService(this);

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.InstanceId.instanceId 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.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -409,5 +410,6 @@ class VirtualPumpPlugin @Inject constructor(
pumpType = pumpTypeNew pumpType = pumpTypeNew
} }
override fun timeDateOrTimeZoneChanged() {} override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {}
} }

View file

@ -2,25 +2,74 @@ package info.nightscout.androidaps.receivers
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import com.google.gson.Gson
import dagger.android.DaggerBroadcastReceiver import dagger.android.DaggerBroadcastReceiver
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.PumpInterface import info.nightscout.androidaps.interfaces.PumpInterface
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.TimeChangeType
import java.util.*
import javax.inject.Inject import javax.inject.Inject
class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() { class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePluginProvider @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) { override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent) super.onReceive(context, intent)
val action = intent.action val action = intent.action
val activePump: PumpInterface = activePlugin.activePump val activePump: PumpInterface = activePlugin.activePump
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.") if (activePump == null) {
if (action != null) { aapsLogger.debug(LTag.PUMP,"TimeDateOrTZChangeReceiver::Time and/or TimeZone changed. [action={}]. Pump is null, exiting.", action)
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.") return
activePump.timeDateOrTimeZoneChanged() }
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)
}
}
} }

View file

@ -19,16 +19,25 @@ public class Round {
return newCalc; return newCalc;
} }
public static Double floorTo(Double x, Double step) { public static Double floorTo(Double x, Double step) {
if (x != 0d) { if (x != 0d) {
return Math.floor(x / step) * step; return Math.floor(x / step) * step;
} }
return 0d; return 0d;
} }
public static Double ceilTo(Double x, Double step) { public static Double ceilTo(Double x, Double step) {
if (x != 0d) { if (x != 0d) {
return Math.ceil(x / step) * step; return Math.ceil(x / step) * step;
} }
return 0d; return 0d;
} }
public static boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);
}
} }

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.utils;
public enum TimeChangeType {
TimezoneChange,
DST_Started,
DST_Ended,
ManualTimeChange
}

View file

@ -1557,7 +1557,7 @@
<string name="rileylink_scanner_scanning">Scanning</string> <string name="rileylink_scanner_scanning">Scanning</string>
<string name="rileylink_scanner_scanning_finished">Scanning finished</string> <string name="rileylink_scanner_scanning_finished">Scanning finished</string>
<string name="rileylink_scanner_scanning_error">Scanning error: %1$d</string> <string name="rileylink_scanner_scanning_error">Scanning error: %1$d</string>
<string name="common_never">Never</string>
<!-- RL Status Page --> <!-- RL Status Page -->
<string name="rileylink_settings_tab1">Settings</string> <string name="rileylink_settings_tab1">Settings</string>
@ -1710,6 +1710,7 @@
<string name="objectives_button_unstart">Clear started</string> <string name="objectives_button_unstart">Clear started</string>
<string name="timedetection">Time detection</string> <string name="timedetection">Time detection</string>
<string name="doyouwantresetstart">Do you want reset objective start? You may lose your progress.</string> <string name="doyouwantresetstart">Do you want reset objective start? You may lose your progress.</string>
<string name="time_or_timezone_change">Time and/or Timezone change on pump</string>
<string name="nopumpselected">No pump selected</string> <string name="nopumpselected">No pump selected</string>
<string name="setupwizard_units_prompt">Select units you want to display values in</string> <string name="setupwizard_units_prompt">Select units you want to display values in</string>
<string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string> <string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string>

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
/** /**