diff --git a/app/build.gradle b/app/build.gradle
index 48730ab005..ce1a6d29a9 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -105,7 +105,7 @@ android {
multiDexEnabled true
versionCode 1500
// dev_version: 2.3.1-dev
- version "medtronic-0.11.4-SNAPSHOT"
+ version "medtronic-0.11.5-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index 50b597b988..b04019190d 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -156,7 +156,7 @@ public class MainApp extends Application {
File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode");
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
- devBranch = BuildConfig.VERSION.contains("dev");
+ devBranch = BuildConfig.VERSION.contains("dev") || BuildConfig.DEV_VERSION.contains("dev");
sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);
@@ -271,11 +271,10 @@ public class MainApp extends Application {
private void setBTReceiver() {
// SP.putDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, null);
- SP.remove(MedtronicConst.Statistics.LastPumpHistoryEntry); // FIXME remove
+ // SP.remove(MedtronicConst.Statistics.LastPumpHistoryEntry); // FIXME remove
- // SP.putString(MedtronicConst.Prefs.PumpFrequency, "US (916 MHz)");
-
- // RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device
+ // RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device,
+ // also detected if timezone/time/date changed and send notification to any active pump driver.
btReceiver = new BroadcastReceiver() {
@Override
@@ -284,7 +283,7 @@ public class MainApp extends Application {
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
- if (action != null) {
+ if (action != null && activePump != null) {
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
@@ -294,7 +293,7 @@ public class MainApp extends Application {
break;
case BluetoothAdapter.STATE_ON: {
- if (activePump != null && "Medtronic".equals(activePump.deviceID())) {
+ if ("Medtronic".equals(activePump.deviceID())) {
Log.v("MainApp", "Bluetooth on");
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
}
@@ -302,9 +301,7 @@ public class MainApp extends Application {
break;
}
} else {
- if (activePump != null) {
- activePump.timeDateOrTimeZoneChanged();
- }
+ activePump.timeDateOrTimeZoneChanged();
}
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java.orig b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java.orig
new file mode 100644
index 0000000000..379fd268ac
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java.orig
@@ -0,0 +1,398 @@
+package info.nightscout.androidaps.plugins.pump.common.defs;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings;
+import info.nightscout.androidaps.utils.Round;
+
+
+/**
+ * Created by andy on 02/05/2018.
+ *
+ * Most of this defintions is intended for VirtualPump only, but they can be used by other plugins.
+ */
+
+public enum PumpType {
+
+ GenericAAPS("Generic AAPS", 0.1d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Percent, //
+ new DoseSettings(10, 30, 24 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), //
+
+ // Cellnovo
+
+ Cellnovo1("Cellnovo", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 24 * 60, 1d, null),
+ PumpTempBasalType.Percent,
+ new DoseSettings(5, 30, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), //
+
+ // Accu-Chek
+
+ AccuChekCombo("Accu-Chek Combo", 0.1d, null, //
+ new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
+ PumpTempBasalType.Percent,
+ new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), //
+
+ AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, //
+ new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
+ PumpTempBasalType.Percent,
+ new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), //
+
+ AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, //
+ new DoseSettings(0.05d, 15, 24 * 60, 0.05d), //
+ PumpTempBasalType.Percent,
+ new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.02d, 0.01d, null, PumpCapability.InsightCapabilities), //
+
+ AccuChekInsightBluetooth("Accu-Chek Insight", 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, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
+
+ // Animas
+ AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
+ new DoseSettings(0.05d, 30, 12 * 60, 0.05d), //
+ PumpTempBasalType.Percent, //
+ new DoseSettings(10, 30, 24 * 60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), //
+
+ AnimasPing("Animas Ping", AnimasVibe),
+
+ // Dana
+ DanaR("DanaR", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Percent, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
+ 0.04d, 0.01d, null, PumpCapability.DanaCapabilities),
+
+ DanaRKorean("DanaR Korean", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Percent, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
+ 0.1d, 0.01d, null, PumpCapability.DanaCapabilities),
+
+ DanaRS("DanaRS", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Percent, //
+ new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities),
+
+ DanaRv2("DanaRv2", DanaRS),
+
+
+ // Insulet
+ Insulet_Omnipod("Insulet Omnipod", 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),
+
+ // Medtronic
+ Medtronic_512_712("Medtronic 512/712", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Absolute, //
+<<<<<<< HEAD
+ new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.05d, 0.05d, null, PumpCapability.MedtronicCapabilities), //
+=======
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO
+>>>>>>> dev
+
+ Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
+ Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
+
+ Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Absolute, //
+<<<<<<< HEAD
+ new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.MedtronicCapabilities), //
+=======
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
+>>>>>>> dev
+
+ Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
+
+ Medtronic_640G("Medtronic 640G", 0.025d, null, //
+ new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
+ PumpTempBasalType.Absolute, //
+ new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
+ 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
+
+ // Tandem
+ TandemTSlim("Tandem t:slim", 0.01d, null, //
+ new DoseSettings(0.01d, 15, 8 * 60, 0.4d),
+ PumpTempBasalType.Percent,
+ new DoseSettings(1, 15, 8 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
+ 0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities),
+
+ TandemTFlex("Tandem t:flex", TandemTSlim), //
+ TandemTSlimG4("Tandem t:slim G4", TandemTSlim), //
+ TandemTSlimX2("Tandem t:slim X2", TandemTSlim), //
+ ;
+
+ private String description;
+ private double bolusSize;
+ private DoseStepSize specialBolusSize;
+ private DoseSettings extendedBolusSettings;
+ private PumpTempBasalType pumpTempBasalType;
+ private DoseSettings tbrSettings;
+ private PumpCapability specialBasalDurations;
+ private double baseBasalMinValue; //
+ private Double baseBasalMaxValue;
+ private double baseBasalStep; //
+ private DoseStepSize baseBasalSpecialSteps; //
+ private PumpCapability pumpCapability;
+
+ private PumpType parent;
+ private static Map mapByDescription;
+
+ static {
+ mapByDescription = new HashMap<>();
+
+ for (PumpType pumpType : values()) {
+ mapByDescription.put(pumpType.getDescription(), pumpType);
+ }
+ }
+
+
+ PumpType(String description, PumpType parent) {
+ this.description = description;
+ this.parent = parent;
+ }
+
+ PumpType(String description, PumpType parent, PumpCapability pumpCapability) {
+ this.description = description;
+ this.parent = parent;
+ this.pumpCapability = pumpCapability;
+ }
+
+ PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
+ DoseSettings extendedBolusSettings, //
+ PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
+ double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
+ this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
+ }
+
+ PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
+ DoseSettings extendedBolusSettings, //
+ PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
+ double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
+ this.description = description;
+ this.bolusSize = bolusSize;
+ this.specialBolusSize = specialBolusSize;
+ this.extendedBolusSettings = extendedBolusSettings;
+ this.pumpTempBasalType = pumpTempBasalType;
+ this.tbrSettings = tbrSettings;
+ this.specialBasalDurations = specialBasalDurations;
+ this.baseBasalMinValue = baseBasalMinValue;
+ this.baseBasalMaxValue = baseBasalMaxValue;
+ this.baseBasalStep = baseBasalStep;
+ this.baseBasalSpecialSteps = baseBasalSpecialSteps;
+ this.pumpCapability = pumpCapability;
+ }
+
+
+ public String getDescription() {
+ return description;
+ }
+
+ public PumpCapability getPumpCapability() {
+
+ if (isParentSet())
+ return this.pumpCapability == null ? parent.pumpCapability : pumpCapability;
+ else
+ return this.pumpCapability;
+ }
+
+ public double getBolusSize() {
+ return isParentSet() ? parent.bolusSize : bolusSize;
+ }
+
+
+ public DoseStepSize getSpecialBolusSize() {
+ return isParentSet() ? parent.specialBolusSize : specialBolusSize;
+ }
+
+
+ public DoseSettings getExtendedBolusSettings() {
+ return isParentSet() ? parent.extendedBolusSettings : extendedBolusSettings;
+ }
+
+
+ public PumpTempBasalType getPumpTempBasalType() {
+ return isParentSet() ? parent.pumpTempBasalType : pumpTempBasalType;
+ }
+
+
+ public DoseSettings getTbrSettings() {
+ return isParentSet() ? parent.tbrSettings : tbrSettings;
+ }
+
+
+ public double getBaseBasalMinValue() {
+ return isParentSet() ? parent.baseBasalMinValue : baseBasalMinValue;
+ }
+
+
+ public Double getBaseBasalMaxValue() {
+ return isParentSet() ? parent.baseBasalMaxValue : baseBasalMaxValue;
+ }
+
+
+ public double getBaseBasalStep() {
+ return isParentSet() ? parent.baseBasalStep : baseBasalStep;
+ }
+
+
+ public DoseStepSize getBaseBasalSpecialSteps() {
+ return isParentSet() ? parent.baseBasalSpecialSteps : baseBasalSpecialSteps;
+ }
+
+
+ public PumpType getParent() {
+ return parent;
+ }
+
+
+ private boolean isParentSet() {
+ return this.parent != null;
+ }
+
+
+ public static PumpType getByDescription(String desc) {
+ if (mapByDescription.containsKey(desc)) {
+ return mapByDescription.get(desc);
+ } else {
+ return PumpType.GenericAAPS;
+ }
+ }
+
+
+ public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) {
+
+ String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : "";
+
+ DoseSettings eb = getExtendedBolusSettings();
+ DoseSettings tbr = getTbrSettings();
+
+ String extendedNote = hasExtendedBasals ? MainApp.gs(R.string.virtualpump_pump_def_extended_note) : "";
+
+ return String.format(i18nTemplate, //
+ getStep("" + getBolusSize(), getSpecialBolusSize()), //
+ eb.getStep(), eb.getDurationStep(), eb.getMaxDuration() / 60, //
+ getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), //
+ tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit,
+ tbr.getDurationStep(), tbr.getMaxDuration() / 60, extendedNote);
+ }
+
+
+ private String getBaseBasalRange() {
+ Double maxValue = getBaseBasalMaxValue();
+
+ return maxValue == null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue;
+ }
+
+
+ private String getStep(String step, DoseStepSize stepSize) {
+ if (stepSize != null)
+ return step + " [" + stepSize.getDescription() + "] *";
+ else
+ return "" + step;
+ }
+
+
+ public boolean hasExtendedBasals() {
+ return ((getBaseBasalSpecialSteps() != null) || (getSpecialBolusSize() != null));
+ }
+
+
+ public PumpCapability getSpecialBasalDurations() {
+
+ if (isParentSet()) {
+ return parent.getSpecialBasalDurations();
+ } else {
+ return specialBasalDurations == null ? //
+ PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations;
+ }
+ }
+
+ public double determineCorrectBolusSize(double bolusAmount) {
+ if (bolusAmount == 0.0d) {
+ return bolusAmount;
+ }
+
+ double bolusStepSize = getBolusSize();
+
+ if (getSpecialBolusSize() != null) {
+ DoseStepSize specialBolusSize = getSpecialBolusSize();
+ bolusStepSize = specialBolusSize.getStepSizeForAmount(bolusAmount);
+ }
+
+ return Round.roundTo(bolusAmount, bolusStepSize);
+ }
+
+
+ public double determineCorrectBolusStepSize(double bolusAmount) {
+ DoseStepSize specialBolusSize = getSpecialBolusSize();
+ if (specialBolusSize != null)
+ return specialBolusSize.getStepSizeForAmount(bolusAmount);
+ return getBolusSize();
+ }
+
+ public double determineCorrectExtendedBolusSize(double bolusAmount) {
+ if (bolusAmount == 0.0d) {
+ return bolusAmount;
+ }
+
+ double bolusStepSize;
+
+ if (getExtendedBolusSettings() == null) { // this should be never null
+ return 0.0d;
+ }
+
+ DoseSettings extendedBolusSettings = getExtendedBolusSettings();
+
+ bolusStepSize = extendedBolusSettings.getStep();
+
+ if (bolusAmount > extendedBolusSettings.getMaxDose()) {
+ bolusAmount = extendedBolusSettings.getMaxDose();
+ }
+
+ return Round.roundTo(bolusAmount, bolusStepSize);
+ }
+
+
+ public double determineCorrectBasalSize(double basalAmount) {
+ if (basalAmount == 0.0d) {
+ return basalAmount;
+ }
+
+ double basalStepSize;
+
+ if (getBaseBasalSpecialSteps() == null) {
+ basalStepSize = getBaseBasalStep();
+ } else {
+ DoseStepSize specialBolusSize = getBaseBasalSpecialSteps();
+
+ basalStepSize = specialBolusSize.getStepSizeForAmount((double) basalAmount);
+ }
+
+ if (basalAmount > getTbrSettings().getMaxDose())
+ basalAmount = getTbrSettings().getMaxDose().doubleValue();
+
+ return Round.roundTo(basalAmount, basalStepSize);
+
+ }
+}
\ No newline at end of file
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 a58ae963e9..a412b44ee3 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
@@ -28,7 +28,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.BLECommOperationResult;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
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;
@@ -173,7 +172,7 @@ public class RFSpy {
// prepend length, and send it.
byte[] prepended = ByteUtil.concat(new byte[]{(byte) (bytes.length)}, bytes);
- LOG.debug("writeToData (raw={})", HexDump.toHexStringDisplayable(prepended));
+ LOG.debug("writeToData (raw={})", ByteUtil.getHex(prepended));
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
prepended);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java
index a42be3ce13..e75d79a79d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java
@@ -1,13 +1,5 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.Semaphore;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
@@ -19,6 +11,14 @@ import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.SystemClock;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Semaphore;
+
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@@ -30,7 +30,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operation
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.DescriptorWriteOperation;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
+import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
/**
@@ -64,14 +64,14 @@ public class RileyLinkBLE {
@Override
public void onCharacteristicChanged(final BluetoothGatt gatt,
- final BluetoothGattCharacteristic characteristic) {
+ final BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);
if (gattDebugEnabled && isLogEnabled()) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged "
- + GattAttributes.lookup(characteristic.getUuid()) + " "
- + HexDump.toHexString(characteristic.getValue()));
+ + GattAttributes.lookup(characteristic.getUuid()) + " "
+ + ByteUtil.getHex(characteristic.getValue()));
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
- LOG.debug("Response Count is " + HexDump.toHexString(characteristic.getValue()));
+ LOG.debug("Response Count is " + ByteUtil.getHex(characteristic.getValue()));
}
}
if (radioResponseCountNotified != null) {
@@ -82,14 +82,14 @@ public class RileyLinkBLE {
@Override
public void onCharacteristicRead(final BluetoothGatt gatt,
- final BluetoothGattCharacteristic characteristic, int status) {
+ final BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
final String statusMessage = getGattStatusMessage(status);
if (gattDebugEnabled && isLogEnabled()) {
- LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
+ LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
- + HexDump.toHexString(characteristic.getValue()));
+ + ByteUtil.getHex(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@@ -97,13 +97,13 @@ public class RileyLinkBLE {
@Override
public void onCharacteristicWrite(final BluetoothGatt gatt,
- final BluetoothGattCharacteristic characteristic, int status) {
+ final BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicWrite(gatt, characteristic, status);
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
if (gattDebugEnabled && isLogEnabled()) {
- LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
- + uuidString + " " + HexDump.toHexString(characteristic.getValue()));
+ LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
+ + uuidString + " " + ByteUtil.getHex(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@@ -148,16 +148,16 @@ public class RileyLinkBLE {
}
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
- (newState == BluetoothProfile.STATE_DISCONNECTING)) {
+ (newState == BluetoothProfile.STATE_DISCONNECTING)) {
// LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
// "Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
if (manualDisconnect)
close();
- LOG.warn("RileyLink Disconnected.");
+ LOG.warn("RileyLink Disconnected.");
} else {
- LOG.warn("Some other state: (status={},newState={})", status, newState);
+ LOG.warn("Some other state: (status={},newState={})", status, newState);
}
}
@@ -166,8 +166,8 @@ public class RileyLinkBLE {
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
if (gattDebugEnabled && isLogEnabled()) {
- LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
- + getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
+ LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
+ + getGattStatusMessage(status) + " written: " + ByteUtil.getHex(descriptor.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
}
@@ -245,7 +245,7 @@ public class RileyLinkBLE {
} else {
mIsConnected = false;
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError,
- RileyLinkError.DeviceIsNotRileyLink);
+ RileyLinkError.DeviceIsNotRileyLink);
}
} else {
@@ -353,7 +353,7 @@ public class RileyLinkBLE {
public boolean enableNotifications() {
BLECommOperationResult result = setNotification_blocking(UUID.fromString(GattAttributes.SERVICE_RADIO), //
- UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
+ UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
if (result.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
LOG.error("Error setting response count notification");
return false;
@@ -430,7 +430,7 @@ public class RileyLinkBLE {
// TODO: 11/07/2016 UI update for user
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
- .getCharacteristic(charaUUID);
+ .getCharacteristic(charaUUID);
// Tell Android that we want the notifications
bluetoothConnectionGatt.setCharacteristicNotification(chara, true);
List list = chara.getDescriptors();
@@ -443,7 +443,7 @@ public class RileyLinkBLE {
BluetoothGattDescriptor descr = list.get(0);
// Tell the remote device to send the notifications
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr,
- BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
+ BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT;
@@ -490,7 +490,7 @@ public class RileyLinkBLE {
// TODO: 11/07/2016 UI update for user
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
- .getCharacteristic(charaUUID);
+ .getCharacteristic(charaUUID);
mCurrentOperation = new CharacteristicWriteOperation(bluetoothConnectionGatt, chara, value);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
@@ -526,7 +526,7 @@ public class RileyLinkBLE {
rval.resultCode = BLECommOperationResult.RESULT_BUSY;
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
- charaUUID);
+ charaUUID);
mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
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 7a081af1e8..d310378e9b 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
@@ -434,4 +434,5 @@ public class ByteUtil {
return outArray;
}
+
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/FabricUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/FabricUtil.java
deleted file mode 100644
index eb07d79582..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/FabricUtil.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package info.nightscout.androidaps.plugins.pump.common.utils;
-
-import java.util.Map;
-
-import com.crashlytics.android.answers.AnswersEvent;
-import com.crashlytics.android.answers.CustomEvent;
-import com.google.common.base.Splitter;
-
-import info.nightscout.androidaps.BuildConfig;
-
-/**
- * Created by andy on 10/26/18.
- */
-
-public class FabricUtil {
-
- public static void createEvent(String eventName, Map map) {
-
- CustomEvent customEvent = new CustomEvent("MedtronicDecode4b6bError") //
- .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) //
- .putCustomAttribute("version", BuildConfig.VERSION);
-
- int attributes = 2;
- boolean interrupted = false;
-
- if (map != null) {
- for (Map.Entry entry : map.entrySet()) {
-
- int part = 1;
-
- if (interrupted)
- break;
-
- for (final String token : Splitter.fixedLength(AnswersEvent.MAX_STRING_LENGTH).split(entry.getValue())) {
-
- if (attributes == AnswersEvent.MAX_NUM_ATTRIBUTES) {
- interrupted = true;
- break;
- }
-
- customEvent.putCustomAttribute(entry.getKey() + "_" + part, token);
- attributes++;
- }
- }
- }
-
- // FIXME andy!!!
- // FabricPrivacy.getInstance().logCustom(customEvent);
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/HexDump.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/HexDump.java
deleted file mode 100644
index 12ce8869e6..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/HexDump.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package info.nightscout.androidaps.plugins.pump.common.utils;
-
-import java.util.List;
-
-/**
- * Clone of Android's HexDump class, for use in debugging. Cosmetic changes
- * only.
- */
-public class HexDump {
-
- private final static char[] HEX_DIGITS = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
-
- public static String dumpHexString(byte[] array) {
- return dumpHexString(array, 0, array.length);
- }
-
-
- public static String dumpHexString(byte[] array, int offset, int length) {
- StringBuilder result = new StringBuilder();
-
- byte[] line = new byte[16];
- int lineIndex = 0;
-
- result.append("\n0x");
- result.append(toHexString(offset));
-
- for (int i = offset; i < offset + length; i++) {
- if (lineIndex == 16) {
- result.append(" ");
-
- for (int j = 0; j < 16; j++) {
- if (line[j] > ' ' && line[j] < '~') {
- result.append(new String(line, j, 1));
- } else {
- result.append(".");
- }
- }
-
- result.append("\n0x");
- result.append(toHexString(i));
- lineIndex = 0;
- }
-
- byte b = array[i];
- result.append(" ");
- result.append(HEX_DIGITS[(b >>> 4) & 0x0F]);
- result.append(HEX_DIGITS[b & 0x0F]);
-
- line[lineIndex++] = b;
- }
-
- if (lineIndex != 16) {
- int count = (16 - lineIndex) * 3;
- count++;
- for (int i = 0; i < count; i++) {
- result.append(" ");
- }
-
- for (int i = 0; i < lineIndex; i++) {
- if (line[i] > ' ' && line[i] < '~') {
- result.append(new String(line, i, 1));
- } else {
- result.append(".");
- }
- }
- }
-
- return result.toString();
- }
-
-
- public static String toHexString(byte b) {
- return toHexString(toByteArray(b));
- }
-
-
- public static String toHexString(byte[] array) {
- return toHexString(array, 0, array.length);
- }
-
-
- public static String toHexString(byte[] array, int offset, int length) {
- char[] buf = new char[length * 2];
-
- int bufIndex = 0;
- for (int i = offset; i < offset + length; i++) {
- byte b = array[i];
- buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
- buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
- }
-
- return new String(buf);
- }
-
-
- public static String toHexStringDisplayable(byte[] arr) {
- StringBuilder sb = new StringBuilder();
-
- if (arr == null) {
- sb.append("Null array");
- } else {
-
- if (arr.length == 0) {
- sb.append("Zero-length array");
- } else {
-
- for (byte element : arr) {
- sb.append(getCorrectHexValue(element));
- sb.append(" ");
- }
- }
- }
-
- return sb.toString();
- }
-
-
- public static String toHexStringDisplayable(List data) {
- StringBuilder sb = new StringBuilder();
-
- for (byte element : data) {
- sb.append(getCorrectHexValue(element));
- sb.append(" ");
- }
-
- return sb.toString();
- }
-
-
- public static String getCorrectHexValue(byte inp) {
- String hx = Integer.toHexString((char)inp);
- hx = hx.toUpperCase();
-
- if (hx.length() == 0)
- return "00";
- else if (hx.length() == 1)
- return "0" + hx;
- else if (hx.length() == 2)
- return hx;
- else if (hx.length() == 4)
- return hx.substring(2);
- else {
- System.out.println("HEX ERROR !!!!!!!!!!!!!!!!");
- }
-
- // System.out.print(Integer.toHexString((char)arr[i]) + " ");
-
- return null;
- }
-
-
- public static String toHexString(int i) {
- return toHexString(toByteArray(i));
- }
-
-
- public static String toHexString(short i) {
- return toHexString(toByteArray(i));
- }
-
-
- public static byte[] toByteArray(byte b) {
- byte[] array = new byte[1];
- array[0] = b;
- return array;
- }
-
-
- public static byte[] toByteArray(int i) {
- byte[] array = new byte[4];
-
- array[3] = (byte)(i & 0xFF);
- array[2] = (byte)((i >> 8) & 0xFF);
- array[1] = (byte)((i >> 16) & 0xFF);
- array[0] = (byte)((i >> 24) & 0xFF);
-
- return array;
- }
-
-
- public static byte[] toByteArray(short i) {
- byte[] array = new byte[2];
-
- array[1] = (byte)(i & 0xFF);
- array[0] = (byte)((i >> 8) & 0xFF);
-
- return array;
- }
-
-
- private static int toByte(char c) {
- if (c >= '0' && c <= '9')
- return (c - '0');
- if (c >= 'A' && c <= 'F')
- return (c - 'A' + 10);
- if (c >= 'a' && c <= 'f')
- return (c - 'a' + 10);
-
- throw new RuntimeException("Invalid hex char '" + c + "'");
- }
-
-
- public static byte[] hexStringToByteArray(String hexString) {
- int length = hexString.length();
- byte[] buffer = new byte[length / 2];
-
- for (int i = 0; i < length; i += 2) {
- buffer[i / 2] = (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i + 1)));
- }
-
- return buffer;
- }
-
-}
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 0673e2b228..3bedf84211 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
@@ -9,6 +9,7 @@ import java.util.List;
/**
* Created by geoff on 4/28/15.
+ * modified by Andy
*/
public class StringUtil {
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 5c628fa489..7578deb872 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
@@ -26,7 +26,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
@@ -51,7 +50,7 @@ import info.nightscout.androidaps.utils.SP;
/**
* Original file created by geoff on 5/30/16.
- *
+ *
* Split into 2 implementations, so that we can split it by target device. - Andy
* This was mostly rewritten from Original version, and lots of commands and
* functionality added.
@@ -645,7 +644,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (contents != null) {
if (contents.length >= expectedLength) {
- LOG.trace("{}: Content: {}", method, HexDump.toHexStringDisplayable(contents));
+ LOG.trace("{}: Content: {}", method, ByteUtil.getHex(contents));
return null;
} else {
@@ -897,7 +896,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (debugSetCommands)
LOG.debug("{}: Body - {}", commandType.getCommandDescription(),
- HexDump.toHexStringDisplayable(body));
+ ByteUtil.getHex(body));
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(body));
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java
index d28d2c1f5a..3243076b01 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverter.java
@@ -10,7 +10,6 @@ import java.util.Map;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO;
@@ -42,7 +41,7 @@ public class MedtronicConverter {
}
if (isLogEnabled())
- LOG.debug("Raw response before convert: " + HexDump.toHexStringDisplayable(rawContent));
+ LOG.debug("Raw response before convert: " + ByteUtil.getHex(rawContent));
this.pumpModel = MedtronicUtil.getMedtronicPumpModel();
@@ -95,7 +94,7 @@ public class MedtronicConverter {
}
-
+
private BasalProfile decodeBasalProfile(byte[] rawContent) {
BasalProfile basalProfile = new BasalProfile(rawContent);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.java
index d596e52612..3f9ce19a6e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.java
@@ -11,13 +11,12 @@ import java.util.Map;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
/**
* 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}
*/
@@ -198,21 +197,21 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head != null) {
sb.append(", head=");
- sb.append(HexDump.toHexStringDisplayable(this.head));
+ sb.append(ByteUtil.getHex(this.head));
}
if (datetime != null) {
sb.append(", datetime=");
- sb.append(HexDump.toHexStringDisplayable(this.datetime));
+ sb.append(ByteUtil.getHex(this.datetime));
}
if (body != null) {
sb.append(", body=");
- sb.append(HexDump.toHexStringDisplayable(this.body));
+ sb.append(ByteUtil.getHex(this.body));
}
sb.append(", rawData=");
- sb.append(HexDump.toHexStringDisplayable(this.rawData));
+ sb.append(ByteUtil.getHex(this.rawData));
sb.append("]");
// sb.append(" DT: ");
@@ -298,7 +297,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head == null) {
return "Unidentified record. ";
} else {
- return "HistoryRecord: head=[" + HexDump.toHexStringDisplayable(this.head) + "]";
+ return "HistoryRecord: head=[" + ByteUtil.getHex(this.head) + "]";
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java
index ea8def9c35..9c1972e16e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java
@@ -12,7 +12,6 @@ import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDecodeStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
@@ -27,7 +26,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* 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}
*/
@@ -117,8 +116,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder
* Author: Andy {andy.rozman@gmail.com}
*/
@@ -69,7 +69,7 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry {
public String getToStringStart() {
return "PumpHistoryRecord [type=" + StringUtil.getStringInLength(entryType.name(), 20) + " ["
+ StringUtil.getStringInLength("" + getOpCode(), 3) + ", 0x"
- + HexDump.getCorrectHexValue((byte) getOpCode()) + "]";
+ + ByteUtil.getHex((byte) getOpCode()) + "]";
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/MessageBody.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/MessageBody.java
index 4b0bb5cd50..2bebaf7da9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/MessageBody.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/MessageBody.java
@@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.message;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
+import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
/**
* Created by geoff on 5/29/16.
@@ -25,7 +25,7 @@ public class MessageBody {
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append(" [txData=");
- sb.append(HexDump.toHexStringDisplayable(getTxData()));
+ sb.append(ByteUtil.getHex(getTxData()));
sb.append("]");
return sb.toString();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java
index 5a7017659f..b23c2a336a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/message/PumpMessage.java
@@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
/**
@@ -170,7 +169,7 @@ public class PumpMessage implements RLMessage {
if (showData) {
sb.append(", rawResponse=");
- sb.append(HexDump.toHexStringDisplayable(getRawContent()));
+ sb.append(ByteUtil.getHex(getRawContent()));
}
sb.append("]");
@@ -186,7 +185,7 @@ public class PumpMessage implements RLMessage {
sb.append(packetType == null ? "null" : packetType.name());
sb.append(", address=(");
- sb.append(HexDump.toHexStringDisplayable(this.address));
+ sb.append(ByteUtil.getHex(this.address));
sb.append("), commandType=");
sb.append(commandType == null ? "null" : commandType.name());
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java
index 5e71b457ed..254ab782dc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java
@@ -52,7 +52,6 @@ import info.nightscout.androidaps.utils.SP;
/**
* Created by andy on 10/12/18.
*/
-// TODO clean up this class (remove/comment logs)
public class MedtronicHistoryData {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
@@ -248,8 +247,9 @@ public class MedtronicHistoryData {
this.sort(this.allHistory);
- LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
- allHistory.size(), removeList.size(), newHistory.size());
+ if (isLogEnabled())
+ LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
+ allHistory.size(), removeList.size(), newHistory.size());
} else {
LOG.error("Since we couldn't determine date, we don't clean full history. This is just workaround.");
}
@@ -273,14 +273,18 @@ public class MedtronicHistoryData {
return (col == null || col.isEmpty());
}
+ private boolean isCollectionNotEmpty(List col) {
+ return (col != null && !col.isEmpty());
+ }
+
public boolean isPumpSuspended() {
- List items = getDataForSuspends(false);
+ List items = getDataForPumpSuspends();
showLogs("isPumpSuspended: ", MedtronicUtil.gsonInstance.toJson(items));
- if (!isCollectionEmpty(items)) {
+ if (isCollectionNotEmpty(items)) {
PumpHistoryEntryType pumpHistoryEntryType = items.get(0).getEntryType();
@@ -290,7 +294,8 @@ public class MedtronicHistoryData {
pumpHistoryEntryType == PumpHistoryEntryType.Resume || //
pumpHistoryEntryType == PumpHistoryEntryType.Prime);
- LOG.debug("isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
+ if (isLogEnabled())
+ LOG.debug("isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
return isSuspended;
} else
@@ -299,20 +304,15 @@ public class MedtronicHistoryData {
}
- private List getDataForSuspends(boolean forHistory) {
+ private List getDataForPumpSuspends() {
List newAndAll = new ArrayList<>();
- if (!isCollectionEmpty(this.allHistory)) {
-
- if (forHistory) {
- // TODO we filter all history ang get last 2
- } else {
- newAndAll.addAll(this.allHistory);
- }
+ if (isCollectionNotEmpty(this.allHistory)) {
+ newAndAll.addAll(this.allHistory);
}
- if (!isCollectionEmpty(this.newHistory)) {
+ if (isCollectionNotEmpty(this.newHistory)) {
for (PumpHistoryEntry pumpHistoryEntry : newHistory) {
if (!newAndAll.contains(pumpHistoryEntry)) {
@@ -336,10 +336,7 @@ public class MedtronicHistoryData {
PumpHistoryEntryType.NoDeliveryAlarm, //
PumpHistoryEntryType.BasalProfileStart);
- if (!forHistory) {
- newAndAll2 = filterPumpSuspend(newAndAll2, 10); // just last 10 (of relevant), for history we already
- // filtered
- }
+ newAndAll2 = filterPumpSuspend(newAndAll2, 10);
return newAndAll2;
}
@@ -369,10 +366,16 @@ public class MedtronicHistoryData {
// TDD
List tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
- LOG.debug("ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds));
+ if (isLogEnabled())
+ LOG.debug("ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds));
- if (!isCollectionEmpty(tdds)) {
- processTDDs(tdds);
+ if (isCollectionNotEmpty(tdds)) {
+ try {
+ processTDDs(tdds);
+ } catch (Exception ex) {
+ LOG.error("ProcessHistoryData: Error processing TDD entries: " + ex.getMessage(), ex);
+ throw ex;
+ }
}
pumpTime = MedtronicUtil.getPumpTime();
@@ -380,26 +383,30 @@ public class MedtronicHistoryData {
// Bolus
List treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
- LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
+ if (isLogEnabled())
+ LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
if (treatments.size() > 0) {
try {
processBolusEntries(treatments);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing Bolus entries: " + ex.getMessage(), ex);
+ throw ex;
}
}
// TBR
List tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
- LOG.debug("ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
+ if (isLogEnabled())
+ LOG.debug("ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
if (tbrs.size() > 0) {
try {
processTBREntries(tbrs);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing TBR entries: " + ex.getMessage(), ex);
+ throw ex;
}
}
@@ -410,16 +417,19 @@ public class MedtronicHistoryData {
suspends = getSuspends();
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error getting Suspend entries: " + ex.getMessage(), ex);
+ throw ex;
}
- LOG.debug("ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
- gson.toJson(suspends));
+ if (isLogEnabled())
+ LOG.debug("ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
+ gson.toJson(suspends));
- if (suspends != null && suspends.size() > 0) {
+ if (isCollectionNotEmpty(suspends)) {
try {
processSuspends(suspends);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing Suspends entries: " + ex.getMessage(), ex);
+ throw ex;
}
}
}
@@ -543,8 +553,9 @@ public class MedtronicHistoryData {
List extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.TBR);
- LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
- gson.toJson(entriesFromHistory));
+ if (isLogEnabled())
+ LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
+ gson.toJson(entriesFromHistory));
TempBasalProcessDTO processDTO = null;
@@ -579,11 +590,10 @@ public class MedtronicHistoryData {
if (processDTO != null) {
processList.add(processDTO);
- processDTO = null;
}
- if (!isCollectionEmpty(processList)) {
+ if (isCollectionNotEmpty(processList)) {
for (TempBasalProcessDTO tempBasalProcessDTO : processList) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java
index 5002b9502f..d4e8aae909 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java
@@ -12,7 +12,6 @@ import java.util.List;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.FabricUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
@@ -286,7 +285,7 @@ public class BasalProfile {
LOG.error(" rawBasalValues: " + ByteUtil.getHex(this.getRawData()));
LOG.error("=============================================================================");
- FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);
+ //FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);
}
if (entries == null || entries.size() == 0) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java
index 73d63dac9f..93419e1872 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java
@@ -5,16 +5,16 @@ import android.content.Intent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import org.joda.time.LocalTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.joda.time.LocalTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
@@ -26,9 +26,7 @@ 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.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
-import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
-
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
@@ -95,8 +93,8 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
- byte highByte = (byte)(shortValue >> 8 & 0xFF);
- byte lowByte = (byte)(shortValue & 0xFF);
+ byte highByte = (byte) (shortValue >> 8 & 0xFF);
+ byte lowByte = (byte) (shortValue & 0xFF);
if (highByte > 0) {
return createByteArray(highByte, lowByte);
@@ -130,7 +128,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static double decodeBasalInsulin(int i) {
- return (double)i / 40.0d;
+ return (double) i / 40.0d;
}
@@ -173,7 +171,7 @@ public class MedtronicUtil extends RileyLinkUtil {
scrollRate = 1;
}
- int strokes = (int)(amount * ((strokesPerUnit * 1.0d) / (scrollRate * 1.0d))) * scrollRate;
+ int strokes = (int) (amount * ((strokesPerUnit * 1.0d) / (scrollRate * 1.0d))) * scrollRate;
byte[] body = ByteUtil.fromHexString(String.format("%02x%0" + (2 * length) + "x", length, strokes));
@@ -183,7 +181,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] createCommandBody(byte[] input) {
- return ByteUtil.concat((byte)input.length, input);
+ return ByteUtil.concat((byte) input.length, input);
}
@@ -211,7 +209,7 @@ public class MedtronicUtil extends RileyLinkUtil {
scrollRate = 2;
}
- int strokes = (int)(amount * (strokesPerUnit / (scrollRate * 1.0d)));
+ int strokes = (int) (amount * (strokesPerUnit / (scrollRate * 1.0d)));
strokes *= scrollRate;
@@ -222,18 +220,18 @@ public class MedtronicUtil extends RileyLinkUtil {
public static void sendNotification(MedtronicNotificationType notificationType) {
Notification notification = new Notification( //
- notificationType.getNotificationType(), //
- MainApp.gs(notificationType.getResourceId()), //
- notificationType.getNotificationUrgency());
+ notificationType.getNotificationType(), //
+ MainApp.gs(notificationType.getResourceId()), //
+ notificationType.getNotificationUrgency());
MainApp.bus().post(new EventNewNotification(notification));
}
public static void sendNotification(MedtronicNotificationType notificationType, Object... parameters) {
Notification notification = new Notification( //
- notificationType.getNotificationType(), //
- MainApp.gs(notificationType.getResourceId(), parameters), //
- notificationType.getNotificationUrgency());
+ notificationType.getNotificationType(), //
+ MainApp.gs(notificationType.getResourceId(), parameters), //
+ notificationType.getNotificationUrgency());
MainApp.bus().post(new EventNewNotification(notification));
}
@@ -249,21 +247,21 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] buildCommandPayload(MedtronicCommandType commandType, byte[] parameters) {
- return buildCommandPayload((byte)commandType.commandCode, parameters);
+ return buildCommandPayload((byte) commandType.commandCode, parameters);
}
public static byte[] buildCommandPayload(byte commandType, byte[] parameters) {
// A7 31 65 51 C0 00 52
- byte commandLength = (byte)(parameters == null ? 2 : 2 + parameters.length);
+ byte commandLength = (byte) (parameters == null ? 2 : 2 + parameters.length);
ByteBuffer sendPayloadBuffer = ByteBuffer.allocate(ENVELOPE_SIZE + commandLength); // + CRC_SIZE
sendPayloadBuffer.order(ByteOrder.BIG_ENDIAN);
byte[] serialNumberBCD = RileyLinkUtil.getRileyLinkServiceData().pumpIDBytes;
- sendPayloadBuffer.put((byte)0xA7);
+ sendPayloadBuffer.put((byte) 0xA7);
sendPayloadBuffer.put(serialNumberBCD[0]);
sendPayloadBuffer.put(serialNumberBCD[1]);
sendPayloadBuffer.put(serialNumberBCD[2]);
@@ -271,9 +269,9 @@ public class MedtronicUtil extends RileyLinkUtil {
sendPayloadBuffer.put(commandType);
if (parameters == null) {
- sendPayloadBuffer.put((byte)0x00);
+ sendPayloadBuffer.put((byte) 0x00);
} else {
- sendPayloadBuffer.put((byte)parameters.length); // size
+ sendPayloadBuffer.put((byte) parameters.length); // size
for (byte val : parameters) {
sendPayloadBuffer.put(val);
@@ -283,7 +281,7 @@ public class MedtronicUtil extends RileyLinkUtil {
byte[] payload = sendPayloadBuffer.array();
if (L.isEnabled(L.PUMPCOMM))
- LOG.info(HexDump.toHexStringDisplayable(payload));
+ LOG.debug("buildCommandPayload [{}]", ByteUtil.getHex(payload));
// int crc = computeCRC8WithPolynomial(payload, 0, payload.length - 1);
@@ -323,7 +321,7 @@ public class MedtronicUtil extends RileyLinkUtil {
List frameData = ByteUtil.getListFromByteArray(substring);
if (isEmptyFrame(frameData)) {
- byte b = (byte)frame;
+ byte b = (byte) frame;
// b |= 0x80;
b |= 0b1000_0000;
// b |= doneBit;
@@ -336,7 +334,7 @@ public class MedtronicUtil extends RileyLinkUtil {
done = true;
} else {
- frameData.add(0, (byte)frame);
+ frameData.add(0, (byte) frame);
}
// System.out.println("Subarray: " + ByteUtil.getCompactString(substring));
@@ -355,7 +353,7 @@ public class MedtronicUtil extends RileyLinkUtil {
if (!lastFrame) {
List frameData = new ArrayList<>();
- byte b = (byte)frame;
+ byte b = (byte) frame;
b |= 0b1000_0000;
// b |= doneBit;
@@ -377,7 +375,7 @@ public class MedtronicUtil extends RileyLinkUtil {
int missing = BIG_FRAME_LENGTH - frameData.size();
for (int i = 0; i < missing; i++) {
- frameData.add((byte)0x00);
+ frameData.add((byte) 0x00);
}
}
@@ -434,7 +432,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static MedtronicCommunicationManager getMedtronicCommunicationManager() {
- return (MedtronicCommunicationManager)RileyLinkUtil.rileyLinkCommunicationManager;
+ return (MedtronicCommunicationManager) RileyLinkUtil.rileyLinkCommunicationManager;
}