MDT refactor pass 9

This commit is contained in:
Milos Kozak 2020-04-27 15:18:59 +02:00
parent 30e7f8ed38
commit 7e712bd612
12 changed files with 103 additions and 133 deletions

View file

@ -478,14 +478,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
case BatteryStatus:
case RemainingInsulin: {
rileyLinkMedtronicService.getMedtronicUIComm().executeCommand(refreshType.getKey().getCommandType());
rileyLinkMedtronicService.getMedtronicUIComm().executeCommand(refreshType.getKey().getCommandType(medtronicUtil.getMedtronicPumpModel()));
refreshTypesNeededToReschedule.add(refreshType.getKey());
resetTime = true;
}
break;
case Configuration: {
rileyLinkMedtronicService.getMedtronicUIComm().executeCommand(refreshType.getKey().getCommandType());
rileyLinkMedtronicService.getMedtronicUIComm().executeCommand(refreshType.getKey().getCommandType(medtronicUtil.getMedtronicPumpModel()));
resetTime = true;
}
break;
@ -1458,7 +1458,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@NonNull
private BasalProfile convertProfileToMedtronicProfile(Profile profile) {
BasalProfile basalProfile = new BasalProfile();
BasalProfile basalProfile = new BasalProfile(aapsLogger);
for (int i = 0; i < 24; i++) {
double rate = profile.getBasalTimeFromMidnight(i * 60 * 60);

View file

@ -869,7 +869,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
public boolean cancelTBR() {
return setTBR(new TempBasalPair(0.0d, false, 0));
return setTBR(new TempBasalPair(aapsLogger, 0.0d, false, 0));
}

View file

@ -79,7 +79,7 @@ public class MedtronicConverter {
}
case ReadTemporaryBasal: {
return new TempBasalPair(rawContent); // 5
return new TempBasalPair(aapsLogger, rawContent); // 5
}
case Settings_512: {
@ -105,7 +105,7 @@ public class MedtronicConverter {
private BasalProfile decodeBasalProfile(PumpType pumpType, byte[] rawContent) {
BasalProfile basalProfile = new BasalProfile(rawContent);
BasalProfile basalProfile = new BasalProfile(aapsLogger, rawContent);
return basalProfile.verify(pumpType) ? basalProfile : null;
}

View file

@ -368,7 +368,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
// LOG.debug("decodeBasalProfile: {}", entry);
BasalProfile basalProfile = new BasalProfile();
BasalProfile basalProfile = new BasalProfile(aapsLogger);
basalProfile.setRawDataFromHistory(entry.getBody());
// LOG.debug("decodeBasalProfile BasalProfile: {}", basalProfile);
@ -603,7 +603,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
}
public static void decodeTempBasal(PumpHistoryEntry tbrPreviousRecord, PumpHistoryEntry entry) {
public void decodeTempBasal(PumpHistoryEntry tbrPreviousRecord, PumpHistoryEntry entry) {
PumpHistoryEntry tbrRate = null, tbrDuration = null;
@ -619,7 +619,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
tbrRate = tbrPreviousRecord;
}
TempBasalPair tbr = new TempBasalPair(tbrRate.getHead()[0], tbrDuration.getHead()[0], (ByteUtil.asUINT8(tbrRate
TempBasalPair tbr = new TempBasalPair(aapsLogger, tbrRate.getHead()[0], tbrDuration.getHead()[0], (ByteUtil.asUINT8(tbrRate
.getDatetime()[4]) >> 3) == 0);
// System.out.println("TBR: amount=" + tbr.getInsulinRate() + ", duration=" + tbr.getDurationMinutes()

View file

@ -1,19 +1,15 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.message;
import java.util.List;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* Created by geoff on 6/2/16.
*/
public class CarelinkLongMessageBody extends MessageBody {
public static final int LONG_MESSAGE_BODY_LENGTH = 65;
private static final int LONG_MESSAGE_BODY_LENGTH = 65;
protected byte[] data;
public CarelinkLongMessageBody() {
CarelinkLongMessageBody() {
init(new byte[0]);
}
@ -22,12 +18,6 @@ public class CarelinkLongMessageBody extends MessageBody {
init(payload);
}
public CarelinkLongMessageBody(List<Byte> payload) {
init(MedtronicUtil.getInstance().createByteArray(payload));
}
@Override
public void init(byte[] rxData) {

View file

@ -161,7 +161,7 @@ public class MedtronicUITask {
private TempBasalPair getTBRSettings() {
return new TempBasalPair(getDoubleFromParameters(0), //
return new TempBasalPair(aapsLogger, getDoubleFromParameters(0), //
false, //
getIntegerFromParameters(1));
}

View file

@ -77,11 +77,11 @@ public class MedtronicHistoryData {
private final SP sp;
private final ActivePluginProvider activePlugin;
private final MedtronicUtil medtronicUtil;
private final MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
private List<PumpHistoryEntry> allHistory = null;
private List<PumpHistoryEntry> allHistory;
private List<PumpHistoryEntry> newHistory = null;
private Long lastHistoryRecordTime;
private boolean isInit = false;
private Gson gson; // cannot be initialized in constructor because of injection
@ -103,7 +103,8 @@ public class MedtronicHistoryData {
AAPSLogger aapsLogger,
SP sp,
ActivePluginProvider activePlugin,
MedtronicUtil medtronicUtil
MedtronicUtil medtronicUtil,
MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder
) {
this.allHistory = new ArrayList<>();
@ -111,6 +112,7 @@ public class MedtronicHistoryData {
this.sp = sp;
this.activePlugin = activePlugin;
this.medtronicUtil = medtronicUtil;
this.medtronicPumpHistoryDecoder = medtronicPumpHistoryDecoder;
}
private Gson gson() {
@ -441,7 +443,7 @@ public class MedtronicHistoryData {
}
}
pumpTime = MedtronicUtil.getInstance().getPumpTime();
pumpTime = medtronicUtil.getPumpTime();
// Bolus
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
@ -472,7 +474,7 @@ public class MedtronicHistoryData {
}
// 'Delivery Suspend'
List<TempBasalProcessDTO> suspends = null;
List<TempBasalProcessDTO> suspends;
try {
suspends = getSuspends();
@ -1312,7 +1314,7 @@ public class MedtronicHistoryData {
}
}
LocalDateTime oldestEntryTime = null;
LocalDateTime oldestEntryTime;
try {
@ -1377,11 +1379,11 @@ public class MedtronicHistoryData {
private PumpHistoryEntryType getTDDType() {
if (MedtronicUtil.getInstance().getMedtronicPumpModel() == null) {
if (medtronicUtil.getMedtronicPumpModel() == null) {
return PumpHistoryEntryType.EndResultTotals;
}
switch (MedtronicUtil.getInstance().getMedtronicPumpModel()) {
switch (medtronicUtil.getMedtronicPumpModel()) {
case Medtronic_515:
case Medtronic_715:
@ -1454,7 +1456,6 @@ public class MedtronicHistoryData {
public void setLastHistoryRecordTime(Long lastHistoryRecordTime) {
// this.previousLastHistoryRecordTime = this.lastHistoryRecordTime;
this.lastHistoryRecordTime = lastHistoryRecordTime;
}
@ -1477,7 +1478,7 @@ public class MedtronicHistoryData {
for (PumpHistoryEntry pumpHistoryEntry : TBRs_Input) {
if (map.containsKey(pumpHistoryEntry.DT)) {
MedtronicPumpHistoryDecoder.decodeTempBasal(map.get(pumpHistoryEntry.DT), pumpHistoryEntry);
medtronicPumpHistoryDecoder.decodeTempBasal(map.get(pumpHistoryEntry.DT), pumpHistoryEntry);
pumpHistoryEntry.setEntryType(medtronicUtil.getMedtronicPumpModel(), PumpHistoryEntryType.TempBasalCombined);
TBRs.add(pumpHistoryEntry);
map.remove(pumpHistoryEntry.DT);

View file

@ -3,13 +3,13 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import com.google.gson.annotations.Expose;
import org.joda.time.Instant;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
@ -31,7 +31,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
*/
public class BasalProfile {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
private final AAPSLogger aapsLogger;
public static final int MAX_RAW_DATA_SIZE = (48 * 3) + 1;
private static final boolean DEBUG_BASALPROFILE = false;
@ -40,18 +40,20 @@ public class BasalProfile {
private List<BasalProfileEntry> listEntries;
public BasalProfile() {
public BasalProfile(AAPSLogger aapsLogger) {
this.aapsLogger = aapsLogger;
init();
}
public BasalProfile(byte[] data) {
public BasalProfile(AAPSLogger aapsLogger, byte[] data) {
this .aapsLogger = aapsLogger;
setRawData(data);
}
// this asUINT8 should be combined with Record.asUINT8, and placed in a new util class.
protected static int readUnsignedByte(byte b) {
private static int readUnsignedByte(byte b) {
return (b < 0) ? b + 256 : b;
}
@ -64,15 +66,15 @@ public class BasalProfile {
}
public boolean setRawData(byte[] data) {
private boolean setRawData(byte[] data) {
if (data == null) {
LOG.error("setRawData: buffer is null!");
aapsLogger.error(LTag.PUMPBTCOMM,"setRawData: buffer is null!");
return false;
}
// if we have just one entry through all day it looks like just length 1
if (data.length == 1) {
data = MedtronicUtil.getInstance().createByteArray(data[0], (byte) 0, (byte) 0);
data = MedtronicUtil.createByteArray(data[0], (byte) 0, (byte) 0);
}
if (data.length == MAX_RAW_DATA_SIZE) {
@ -89,7 +91,7 @@ public class BasalProfile {
public boolean setRawDataFromHistory(byte[] data) {
if (data == null) {
LOG.error("setRawData: buffer is null!");
aapsLogger.error(LTag.PUMPBTCOMM,"setRawData: buffer is null!");
return false;
}
@ -114,13 +116,13 @@ public class BasalProfile {
public void dumpBasalProfile() {
LOG.debug("Basal Profile entries:");
aapsLogger.debug(LTag.PUMPBTCOMM,"Basal Profile entries:");
List<BasalProfileEntry> entries = getEntries();
for (int i = 0; i < entries.size(); i++) {
BasalProfileEntry entry = entries.get(i);
String startString = entry.startTime.toString("HH:mm");
// this doesn't work
LOG.debug(String.format("Entry %d, rate=%.3f (0x%02X), start=%s (0x%02X)", i + 1, entry.rate,
aapsLogger.debug(LTag.PUMPBTCOMM,String.format("Entry %d, rate=%.3f (0x%02X), start=%s (0x%02X)", i + 1, entry.rate,
entry.rate_raw, startString, entry.startTime_raw));
}
@ -167,14 +169,14 @@ public class BasalProfile {
BasalProfileEntry rval = new BasalProfileEntry();
List<BasalProfileEntry> entries = getEntries();
if (entries.size() == 0) {
LOG.warn(String.format("getEntryForTime(%s): table is empty",
aapsLogger.warn(LTag.PUMPBTCOMM,String.format("getEntryForTime(%s): table is empty",
when.toDateTime().toLocalTime().toString("HH:mm")));
return rval;
}
// Log.w(TAG,"Assuming first entry");
rval = entries.get(0);
if (entries.size() == 1) {
LOG.debug("getEntryForTime: Only one entry in profile");
aapsLogger.debug(LTag.PUMPBTCOMM,"getEntryForTime: Only one entry in profile");
return rval;
}
@ -184,17 +186,17 @@ public class BasalProfile {
while (!done) {
BasalProfileEntry entry = entries.get(i);
if (DEBUG_BASALPROFILE) {
LOG.debug(String.format("Comparing 'now'=%s to entry 'start time'=%s", when.toDateTime().toLocalTime()
aapsLogger.debug(LTag.PUMPBTCOMM,String.format("Comparing 'now'=%s to entry 'start time'=%s", when.toDateTime().toLocalTime()
.toString("HH:mm"), entry.startTime.toString("HH:mm")));
}
if (localMillis >= entry.startTime.getMillisOfDay()) {
rval = entry;
if (DEBUG_BASALPROFILE)
LOG.debug("Accepted Entry");
aapsLogger.debug(LTag.PUMPBTCOMM,"Accepted Entry");
} else {
// entry at i has later start time, keep older entry
if (DEBUG_BASALPROFILE)
LOG.debug("Rejected Entry");
aapsLogger.debug(LTag.PUMPBTCOMM,"Rejected Entry");
done = true;
}
i++;
@ -203,7 +205,7 @@ public class BasalProfile {
}
}
if (DEBUG_BASALPROFILE) {
LOG.debug(String.format("getEntryForTime(%s): Returning entry: rate=%.3f (%d), start=%s (%d)", when
aapsLogger.debug(LTag.PUMPBTCOMM,String.format("getEntryForTime(%s): Returning entry: rate=%.3f (%d), start=%s (%d)", when
.toDateTime().toLocalTime().toString("HH:mm"), rval.rate, rval.rate_raw,
rval.startTime.toString("HH:mm"), rval.startTime_raw));
}
@ -215,7 +217,7 @@ public class BasalProfile {
List<BasalProfileEntry> entries = new ArrayList<>();
if (mRawData == null || mRawData[2] == 0x3f) {
LOG.warn("Raw Data is empty.");
aapsLogger.warn(LTag.PUMPBTCOMM,"Raw Data is empty.");
return entries; // an empty list
}
boolean done = false;
@ -229,13 +231,13 @@ public class BasalProfile {
if ((mRawData[i] == 0) && (mRawData[i + 1] == 0) && (mRawData[i + 2] == 0x3f))
break;
r = MedtronicUtil.getInstance().makeUnsignedShort(mRawData[i + 1], mRawData[i]); // readUnsignedByte(mRawData[i]);
r = MedtronicUtil.makeUnsignedShort(mRawData[i + 1], mRawData[i]); // readUnsignedByte(mRawData[i]);
st = readUnsignedByte(mRawData[i + 2]);
try {
entries.add(new BasalProfileEntry(r, st));
entries.add(new BasalProfileEntry(aapsLogger, r, st));
} catch (Exception ex) {
LOG.error("Error decoding basal profile from bytes: {}", ByteUtil.shortHexString(mRawData));
aapsLogger.error(LTag.PUMPBTCOMM,"Error decoding basal profile from bytes: {}", ByteUtil.shortHexString(mRawData));
throw ex;
}
@ -264,14 +266,14 @@ public class BasalProfile {
for (BasalProfileEntry profileEntry : listEntries) {
byte[] strokes = MedtronicUtil.getInstance().getBasalStrokes(profileEntry.rate, true);
byte[] strokes = MedtronicUtil.getBasalStrokes(profileEntry.rate, true);
outData.add(profileEntry.rate_raw[0]);
outData.add(profileEntry.rate_raw[1]);
outData.add(profileEntry.startTime_raw);
}
this.setRawData(MedtronicUtil.getInstance().createByteArray(outData));
this.setRawData(MedtronicUtil.createByteArray(outData));
// return this.mRawData;
}
@ -284,10 +286,10 @@ public class BasalProfile {
try {
entries = getEntries();
} catch (Exception ex) {
LOG.error("=============================================================================");
LOG.error(" Error generating entries. Ex.: " + ex, ex);
LOG.error(" rawBasalValues: " + ByteUtil.shortHexString(this.getRawData()));
LOG.error("=============================================================================");
aapsLogger.error(LTag.PUMPBTCOMM,"=============================================================================");
aapsLogger.error(LTag.PUMPBTCOMM," Error generating entries. Ex.: " + ex, ex);
aapsLogger.error(LTag.PUMPBTCOMM," rawBasalValues: " + ByteUtil.shortHexString(this.getRawData()));
aapsLogger.error(LTag.PUMPBTCOMM,"=============================================================================");
//FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);
}

View file

@ -1,11 +1,9 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import org.joda.time.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
@ -15,24 +13,20 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
*/
public class BasalProfileEntry {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public byte[] rate_raw;
byte[] rate_raw;
public double rate;
public byte startTime_raw;
byte startTime_raw;
public LocalTime startTime; // Just a "time of day"
public BasalProfileEntry() {
rate = -9.999E6;
rate_raw = MedtronicUtil.getInstance().getByteArrayFromUnsignedShort(0xFF, true);
rate_raw = MedtronicUtil.getByteArrayFromUnsignedShort(0xFF, true);
startTime = new LocalTime(0);
startTime_raw = (byte)0xFF;
startTime_raw = (byte) 0xFF;
}
public BasalProfileEntry(double rate, int hour, int minutes) {
byte[] data = MedtronicUtil.getInstance().getBasalStrokes(rate, true);
byte[] data = MedtronicUtil.getBasalStrokes(rate, true);
rate_raw = new byte[2];
rate_raw[0] = data[1];
@ -44,47 +38,42 @@ public class BasalProfileEntry {
interval++;
}
startTime_raw = (byte)interval;
startTime_raw = (byte) interval;
startTime = new LocalTime(hour, minutes == 30 ? 30 : 0);
}
public BasalProfileEntry(int rateStrokes, int startTimeInterval) {
BasalProfileEntry(AAPSLogger aapsLogger, int rateStrokes, int startTimeInterval) {
// rateByte is insulin delivery rate, U/hr, in 0.025 U increments
// startTimeByte is time-of-day, in 30 minute increments
rate_raw = MedtronicUtil.getInstance().getByteArrayFromUnsignedShort(rateStrokes, true);
rate_raw = MedtronicUtil.getByteArrayFromUnsignedShort(rateStrokes, true);
rate = rateStrokes * 0.025;
startTime_raw = (byte)startTimeInterval;
startTime_raw = (byte) startTimeInterval;
try {
startTime = new LocalTime(startTimeInterval / 2, (startTimeInterval % 2) * 30);
} catch (Exception ex) {
LOG.error(
"Error creating BasalProfileEntry: startTimeInterval={}, startTime_raw={}, hours={}, rateStrokes={}",
startTimeInterval, startTime_raw, startTimeInterval / 2, rateStrokes);
aapsLogger.error(LTag.PUMPBTCOMM,
"Error creating BasalProfileEntry: startTimeInterval={}, startTime_raw={}, hours={}, rateStrokes={}",
startTimeInterval, startTime_raw, startTimeInterval / 2, rateStrokes);
throw ex;
}
}
public BasalProfileEntry(byte rateByte, int startTimeByte) {
BasalProfileEntry(byte rateByte, int startTimeByte) {
// rateByte is insulin delivery rate, U/hr, in 0.025 U increments
// startTimeByte is time-of-day, in 30 minute increments
rate_raw = MedtronicUtil.getInstance().getByteArrayFromUnsignedShort(rateByte, true);
rate_raw = MedtronicUtil.getByteArrayFromUnsignedShort(rateByte, true);
rate = rateByte * 0.025;
startTime_raw = (byte)startTimeByte;
startTime_raw = (byte) startTimeByte;
startTime = new LocalTime(startTimeByte / 2, (startTimeByte % 2) * 30);
}
public void setStartTime(LocalTime localTime) {
this.startTime = localTime;
}
public void setRate(double rate) {
this.rate = rate;
}
}

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
@ -19,11 +19,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
*/
public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public TempBasalPair() {
}
private final AAPSLogger aapsLogger;
/**
* This constructor is for use with PumpHistoryDecoder
@ -32,8 +28,9 @@ public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.commo
* @param startTimeByte
* @param isPercent
*/
public TempBasalPair(byte rateByte, int startTimeByte, boolean isPercent) {
public TempBasalPair(AAPSLogger aapsLogger, byte rateByte, int startTimeByte, boolean isPercent) {
super();
this.aapsLogger = aapsLogger;
int rateInt = ByteUtil.asUINT8(rateByte);
@ -46,45 +43,48 @@ public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.commo
}
public TempBasalPair(byte[] response) {
public TempBasalPair(AAPSLogger aapsLogger, byte[] response) {
super();
this.aapsLogger = aapsLogger;
if (L.isEnabled(L.PUMPCOMM))
LOG.debug("Received TempBasal response: " + ByteUtil.getHex(response));
aapsLogger.debug(LTag.PUMPBTCOMM, "Received TempBasal response: " + ByteUtil.getHex(response));
isPercent = response[0] == 1;
if (isPercent) {
insulinRate = response[1];
} else {
int strokes = MedtronicUtil.getInstance().makeUnsignedShort(response[2], response[3]);
int strokes = MedtronicUtil.makeUnsignedShort(response[2], response[3]);
insulinRate = strokes / 40.0d;
}
if (response.length<6) {
if (response.length < 6) {
durationMinutes = ByteUtil.asUINT8(response[4]);
} else {
durationMinutes = MedtronicUtil.getInstance().makeUnsignedShort(response[4], response[5]);
durationMinutes = MedtronicUtil.makeUnsignedShort(response[4], response[5]);
}
LOG.warn("TempBasalPair (with {} byte response): {}", response.length, toString());
aapsLogger.warn(LTag.PUMPBTCOMM, "TempBasalPair (with {} byte response): {}", response.length, toString());
}
public TempBasalPair(double insulinRate, boolean isPercent, int durationMinutes) {
public TempBasalPair(AAPSLogger aapsLogger, double insulinRate, boolean isPercent, int durationMinutes) {
super(insulinRate, isPercent, durationMinutes);
this.aapsLogger = aapsLogger;
}
public byte[] getAsRawData() {
List<Byte> list = new ArrayList<Byte>();
List<Byte> list = new ArrayList<>();
list.add((byte) 5);
byte[] insulinRate = MedtronicUtil.getInstance().getBasalStrokes(this.insulinRate, true);
byte timeMin = (byte) MedtronicUtil.getInstance().getIntervalFromMinutes(durationMinutes);
byte[] insulinRate = MedtronicUtil.getBasalStrokes(this.insulinRate, true);
byte timeMin = (byte) MedtronicUtil.getIntervalFromMinutes(durationMinutes);
// list.add((byte) 0); // ?
@ -107,11 +107,11 @@ public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.commo
list.add(insulinRate[1]);
return MedtronicUtil.getInstance().createByteArray(list);
return MedtronicUtil.createByteArray(list);
}
public boolean isCancelTBR() {
return (MedtronicUtil.getInstance().isSame(insulinRate, 0.0d) && durationMinutes == 0);
return (MedtronicUtil.isSame(insulinRate, 0.0d) && durationMinutes == 0);
}
@ -128,7 +128,7 @@ public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.commo
}
@Override
@NotNull @Override
public String toString() {
return "TempBasalPair [" + "Rate=" + insulinRate + ", DurationMinutes=" + durationMinutes + ", IsPercent="
+ isPercent + "]";

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.defs;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* Created by andy on 6/28/18.
*/
@ -30,9 +28,9 @@ public enum MedtronicStatusRefreshType {
}
public MedtronicCommandType getCommandType() {
public MedtronicCommandType getCommandType(MedtronicDeviceType medtronicDeviceType) {
if (this == Configuration) {
return MedtronicCommandType.getSettings(MedtronicUtil.getInstance().getMedtronicPumpModel());
return MedtronicCommandType.getSettings(medtronicDeviceType);
} else
return commandType;
}

View file

@ -66,16 +66,6 @@ public class MedtronicUtil {
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
instance = this;
}
private static MedtronicUtil instance;
// TODO: replace by injection
@Deprecated
public static MedtronicUtil getInstance() {
if (instance == null) throw new IllegalStateException("MedtronicUtil not initialized");
return instance;
}
public LocalTime getTimeFrom30MinInterval(int interval) {
@ -87,17 +77,17 @@ public class MedtronicUtil {
}
public int getIntervalFromMinutes(int minutes) {
public static int getIntervalFromMinutes(int minutes) {
return minutes / 30;
}
public int makeUnsignedShort(int b2, int b1) {
public static int makeUnsignedShort(int b2, int b1) {
int k = (b2 & 0xff) << 8 | b1 & 0xff;
return k;
}
public byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
public static byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
byte highByte = (byte) (shortValue >> 8 & 0xFF);
byte lowByte = (byte) (shortValue & 0xFF);
@ -110,12 +100,12 @@ public class MedtronicUtil {
}
public byte[] createByteArray(byte... data) {
public static byte[] createByteArray(byte... data) {
return data;
}
public byte[] createByteArray(List<Byte> data) {
public static byte[] createByteArray(List<Byte> data) {
byte[] array = new byte[data.size()];
@ -142,7 +132,7 @@ public class MedtronicUtil {
}
public byte[] getBasalStrokes(double amount, boolean returnFixedSize) {
public static byte[] getBasalStrokes(double amount, boolean returnFixedSize) {
return getStrokes(amount, 40, returnFixedSize);
}
@ -190,7 +180,7 @@ public class MedtronicUtil {
}
public byte[] getStrokes(double amount, int strokesPerUnit, boolean returnFixedSize) {
public static byte[] getStrokes(double amount, int strokesPerUnit, boolean returnFixedSize) {
int strokes = getStrokesInt(amount, strokesPerUnit);
@ -199,7 +189,7 @@ public class MedtronicUtil {
}
public int getStrokesInt(double amount, int strokesPerUnit) {
public static int getStrokesInt(double amount, int strokesPerUnit) {
int length = 1;
int scrollRate = 1;
@ -456,7 +446,7 @@ public class MedtronicUtil {
}
public boolean isSame(Double d1, Double d2) {
public static boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);