MDT refactor pass 8

This commit is contained in:
Milos Kozak 2020-04-27 14:30:38 +02:00
parent f686c81115
commit 30e7f8ed38
12 changed files with 167 additions and 210 deletions

View file

@ -98,6 +98,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private final RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final MedtronicUtil medtronicUtil; private final MedtronicUtil medtronicUtil;
private final MedtronicPumpStatus medtronicPumpStatus; private final MedtronicPumpStatus medtronicPumpStatus;
private final MedtronicHistoryData medtronicHistoryData;
protected static MedtronicPumpPlugin plugin = null; protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService rileyLinkMedtronicService; private RileyLinkMedtronicService rileyLinkMedtronicService;
@ -107,7 +108,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private boolean isRefresh = false; private boolean isRefresh = false;
private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>(); private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
private boolean isInitialized = false; private boolean isInitialized = false;
private MedtronicHistoryData medtronicHistoryData;
private PumpHistoryEntry lastPumpHistoryEntry; private PumpHistoryEntry lastPumpHistoryEntry;
public static boolean isBusy = false; public static boolean isBusy = false;
@ -128,7 +128,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
FabricPrivacy fabricPrivacy, FabricPrivacy fabricPrivacy,
RileyLinkUtil rileyLinkUtil, RileyLinkUtil rileyLinkUtil,
MedtronicUtil medtronicUtil, MedtronicUtil medtronicUtil,
MedtronicPumpStatus medtronicPumpStatus MedtronicPumpStatus medtronicPumpStatus,
MedtronicHistoryData medtronicHistoryData
) { ) {
super(new PluginDescription() // super(new PluginDescription() //
@ -147,6 +148,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
this.medtronicUtil = medtronicUtil; this.medtronicUtil = medtronicUtil;
this.sp = sp; this.sp = sp;
this.medtronicPumpStatus = medtronicPumpStatus; this.medtronicPumpStatus = medtronicPumpStatus;
this.medtronicHistoryData = medtronicHistoryData;
displayConnectionMessages = false; displayConnectionMessages = false;
@ -181,7 +183,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
} }
@Deprecated @Deprecated
@ -196,12 +197,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return "MedtronicPumpPlugin::"; return "MedtronicPumpPlugin::";
} }
public MedtronicHistoryData getMedtronicHistoryData() {
return this.medtronicHistoryData;
}
@Override @Override
public void initPumpStatusData() { public void initPumpStatusData() {
@ -1565,10 +1560,4 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
refreshCustomActionsList(); refreshCustomActionsList();
} }
@Deprecated
public MedtronicPumpStatus getMedtronicPumpStatus() {
return medtronicPumpStatus;
}
} }

View file

@ -65,6 +65,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
@Inject MedtronicPumpPlugin medtronicPumpPlugin; @Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MedtronicConverter medtronicConverter; @Inject MedtronicConverter medtronicConverter;
@Inject MedtronicUtil medtronicUtil; @Inject MedtronicUtil medtronicUtil;
@Inject MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
private final int MAX_COMMAND_TRIES = 3; private final int MAX_COMMAND_TRIES = 3;
private final int DEFAULT_TIMEOUT = 2000; private final int DEFAULT_TIMEOUT = 2000;
@ -73,13 +74,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private String errorMessage; private String errorMessage;
private boolean debugSetCommands = false; private boolean debugSetCommands = false;
private MedtronicPumpHistoryDecoder pumpHistoryDecoder;
private boolean doWakeUpBeforeCommand = true; private boolean doWakeUpBeforeCommand = true;
public MedtronicCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) { public MedtronicCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy); super(injector, rfspy);
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
medtronicPumpStatus.previousConnection = sp.getLong( medtronicPumpStatus.previousConnection = sp.getLong(
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
} }
@ -316,7 +315,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
for (int pageNumber = 0; pageNumber < 5; pageNumber++) { for (int pageNumber = 0; pageNumber < 5; pageNumber++) {
RawHistoryPage rawHistoryPage = new RawHistoryPage(); RawHistoryPage rawHistoryPage = new RawHistoryPage(aapsLogger);
// wakeUp(receiverDeviceAwakeForMinutes, false); // wakeUp(receiverDeviceAwakeForMinutes, false);
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData, PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
new GetHistoryPageCarelinkMessageBody(pageNumber)); new GetHistoryPageCarelinkMessageBody(pageNumber));
@ -440,8 +439,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
rawHistoryPage.dumpToDebug(); rawHistoryPage.dumpToDebug();
List<PumpHistoryEntry> medtronicHistoryEntries = pumpHistoryDecoder List<PumpHistoryEntry> medtronicHistoryEntries = medtronicPumpHistoryDecoder.processPageAndCreateRecords(rawHistoryPage);
.processPageAndCreateRecords(rawHistoryPage);
aapsLogger.debug(LTag.PUMPBTCOMM, "getPumpHistory: Found {} history entries.", medtronicHistoryEntries.size()); aapsLogger.debug(LTag.PUMPBTCOMM, "getPumpHistory: Found {} history entries.", medtronicHistoryEntries.size());

View file

@ -1,32 +1,32 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history; package info.nightscout.androidaps.plugins.pump.medtronic.comm.history;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import info.nightscout.androidaps.logging.L; import javax.inject.Inject;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; 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.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/** /**
* 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}
*/ */
public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> implements MedtronicHistoryDecoderInterface<T> { public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> implements MedtronicHistoryDecoderInterface<T> {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); @Inject AAPSLogger aapsLogger;
@Inject MedtronicUtil medtronicUtil;
protected ByteUtil bitUtils; protected ByteUtil bitUtils;
@ -34,7 +34,6 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
protected boolean statisticsEnabled = true; protected boolean statisticsEnabled = true;
protected Map<Integer, Integer> unknownOpCodes; protected Map<Integer, Integer> unknownOpCodes;
protected Map<RecordDecodeStatus, Map<String, String>> mapStatistics; protected Map<RecordDecodeStatus, Map<String, String>> mapStatistics;
protected MedtronicDeviceType deviceType;
public MedtronicHistoryDecoder() { public MedtronicHistoryDecoder() {
@ -62,8 +61,8 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
// return byteList; // return byteList;
// } // }
if (MedtronicUtil.getInstance().getMedtronicPumpModel() == null) { if (medtronicUtil.getMedtronicPumpModel() == null) {
LOG.error("Device Type is not defined."); aapsLogger.error(LTag.PUMPBTCOMM, "Device Type is not defined.");
return byteList; return byteList;
} }
@ -86,17 +85,16 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
if (!statisticsEnabled) if (!statisticsEnabled)
return; return;
unknownOpCodes = new HashMap<Integer, Integer>(); unknownOpCodes = new HashMap<>();
mapStatistics = new HashMap<RecordDecodeStatus, Map<String, String>>(); mapStatistics = new HashMap<>();
for (RecordDecodeStatus stat : RecordDecodeStatus.values()) { for (RecordDecodeStatus stat : RecordDecodeStatus.values()) {
mapStatistics.put(stat, new HashMap<String, String>()); mapStatistics.put(stat, new HashMap<>());
} }
} }
protected void addToStatistics(MedtronicHistoryEntryInterface pumpHistoryEntry, RecordDecodeStatus status, protected void addToStatistics(MedtronicHistoryEntryInterface pumpHistoryEntry, RecordDecodeStatus status, Integer opCode) {
Integer opCode) {
if (!statisticsEnabled) if (!statisticsEnabled)
return; return;
@ -120,11 +118,10 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
StringUtil.appendToStringBuilder(sb, "" + unknownEntry.getKey(), ", "); StringUtil.appendToStringBuilder(sb, "" + unknownEntry.getKey(), ", ");
} }
if (isLogEnabled()) aapsLogger.error(LTag.PUMPBTCOMM, "STATISTICS OF PUMP DECODE");
LOG.debug("STATISTICS OF PUMP DECODE");
if (unknownOpCodes.size() > 0) { if (unknownOpCodes.size() > 0) {
LOG.warn("Unknown Op Codes: {}", sb.toString()); aapsLogger.warn(LTag.PUMPBTCOMM, "Unknown Op Codes: {}", sb.toString());
} }
for (Map.Entry<RecordDecodeStatus, Map<String, String>> entry : mapStatistics.entrySet()) { for (Map.Entry<RecordDecodeStatus, Map<String, String>> entry : mapStatistics.entrySet()) {
@ -140,12 +137,9 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
String spaces = StringUtils.repeat(" ", 14 - entry.getKey().name().length()); String spaces = StringUtils.repeat(" ", 14 - entry.getKey().name().length());
if (isLogEnabled()) aapsLogger.error(LTag.PUMPBTCOMM, " {}{} - {}. Elements: {}", entry.getKey().name(), spaces, entry.getValue().size(), sb.toString());
LOG.debug(" {}{} - {}. Elements: {}", entry.getKey().name(), spaces, entry.getValue().size(),
sb.toString());
} else { } else {
if (isLogEnabled()) aapsLogger.error(LTag.PUMPBTCOMM, " {} - {}", entry.getKey().name(), entry.getValue().size());
LOG.debug(" {} - {}", entry.getKey().name(), entry.getValue().size());
} }
} }
} }
@ -184,9 +178,4 @@ public abstract class MedtronicHistoryDecoder<T extends MedtronicHistoryEntry> i
return records; return records;
} }
protected boolean isLogEnabled() {
return L.isEnabled(L.PUMPCOMM);
}
} }

View file

@ -2,11 +2,8 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history;
import java.util.Arrays; import java.util.Arrays;
import org.slf4j.Logger; import info.nightscout.androidaps.logging.AAPSLogger;
import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.CRC; import info.nightscout.androidaps.plugins.pump.common.utils.CRC;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
@ -16,12 +13,13 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
*/ */
public class RawHistoryPage { public class RawHistoryPage {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM); private final AAPSLogger aapsLogger;
private byte[] data = new byte[0]; private byte[] data = new byte[0];
public RawHistoryPage() { public RawHistoryPage(AAPSLogger aapsLogger) {
this.aapsLogger = aapsLogger;
} }
@ -35,7 +33,7 @@ public class RawHistoryPage {
} }
public byte[] getOnlyData() { byte[] getOnlyData() {
return Arrays.copyOfRange(data, 0, 1022); return Arrays.copyOfRange(data, 0, 1022);
} }
@ -55,11 +53,11 @@ public class RawHistoryPage {
int crcStored = ByteUtil.toInt(data[1022], data[1023]); int crcStored = ByteUtil.toInt(data[1022], data[1023]);
if (crcCalculated != crcStored) { if (crcCalculated != crcStored) {
LOG.error("Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored, aapsLogger.error(LTag.PUMPBTCOMM, "Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored,
crcCalculated); crcCalculated);
} else { } else {
if (MedtronicUtil.getInstance().isLowLevelDebug()) if (MedtronicUtil.isLowLevelDebug())
LOG.debug("CRC ok."); aapsLogger.debug(LTag.PUMPBTCOMM, "CRC ok.");
} }
return crcCalculated == crcStored; return crcCalculated == crcStored;
@ -70,7 +68,7 @@ public class RawHistoryPage {
int linesize = 80; int linesize = 80;
int offset = 0; int offset = 0;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
while (offset < data.length) { while (offset < data.length) {
int bytesToLog = linesize; int bytesToLog = linesize;
@ -83,7 +81,6 @@ public class RawHistoryPage {
offset += linesize; offset += linesize;
} }
LOG.debug("History Page Data:\n{}", sb.toString()); aapsLogger.debug(LTag.PUMPBTCOMM, "History Page Data:\n{}", sb.toString());
} }
} }

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDeco
/** /**
* 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}
*/ */
@ -209,7 +209,6 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
entry.setDateTime(dateTime, getIndex); entry.setDateTime(dateTime, getIndex);
} }
if (isLogEnabled())
LOG.debug("Record: {}", entry); LOG.debug("Record: {}", entry);
} }

View file

@ -1,16 +1,14 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump; package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import android.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import info.nightscout.androidaps.logging.L; import javax.inject.Inject;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import javax.inject.Singleton;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; 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.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder;
@ -27,21 +25,26 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/** /**
* 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}
*/ */
@Singleton
public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHistoryEntry> { public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHistoryEntry> {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); private final AAPSLogger aapsLogger;
private final MedtronicUtil medtronicUtil;
private PumpHistoryEntry tbrPreviousRecord; private PumpHistoryEntry tbrPreviousRecord;
private PumpHistoryEntry changeTimeRecord; private PumpHistoryEntry changeTimeRecord;
private MedtronicDeviceType deviceType;
private static final String TAG = "MdtPumpHistoryDecoder";
@Inject
public MedtronicPumpHistoryDecoder() { public MedtronicPumpHistoryDecoder(
AAPSLogger aapsLogger,
MedtronicUtil medtronicUtil
) {
this.aapsLogger = aapsLogger;
this.medtronicUtil = medtronicUtil;
} }
@ -50,15 +53,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
int counter = 0; int counter = 0;
int record = 0; int record = 0;
boolean incompletePacket = false; boolean incompletePacket;
deviceType = MedtronicUtil.getInstance().getMedtronicPumpModel();
List<PumpHistoryEntry> outList = new ArrayList<PumpHistoryEntry>(); List<PumpHistoryEntry> outList = new ArrayList<>();
String skipped = null; String skipped = null;
int elementStart = 0;
if (dataClear.size() == 0) { if (dataClear.size() == 0) {
Log.e(TAG, "Empty page."); aapsLogger.error(LTag.PUMPBTCOMM, "Empty page.");
return outList; return outList;
} }
@ -76,7 +77,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
continue; continue;
} else { } else {
if (skipped != null) { if (skipped != null) {
Log.w(TAG, " ... Skipped " + skipped); aapsLogger.warn(LTag.PUMPBTCOMM, " ... Skipped " + skipped);
skipped = null; skipped = null;
} }
} }
@ -84,7 +85,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
PumpHistoryEntryType entryType = PumpHistoryEntryType.getByCode(opCode); PumpHistoryEntryType entryType = PumpHistoryEntryType.getByCode(opCode);
PumpHistoryEntry pe = new PumpHistoryEntry(); PumpHistoryEntry pe = new PumpHistoryEntry();
pe.setEntryType(entryType); pe.setEntryType(medtronicUtil.getMedtronicPumpModel(), entryType);
pe.setOffset(counter); pe.setOffset(counter);
counter++; counter++;
@ -93,7 +94,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
break; break;
} }
List<Byte> listRawData = new ArrayList<Byte>(); List<Byte> listRawData = new ArrayList<>();
listRawData.add((byte) opCode); listRawData.add((byte) opCode);
if (entryType == PumpHistoryEntryType.UnabsorbedInsulin if (entryType == PumpHistoryEntryType.UnabsorbedInsulin
@ -105,20 +106,20 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
int els = getUnsignedInt(elements); int els = getUnsignedInt(elements);
for (int k = 0; k < (els - 2); k++) { for (int k = 0; k < (els - 2); k++) {
listRawData.add((byte) dataClear.get(counter)); listRawData.add(dataClear.get(counter));
counter++; counter++;
} }
special = true; special = true;
} else { } else {
for (int j = 0; j < (entryType.getTotalLength() - 1); j++) { for (int j = 0; j < (entryType.getTotalLength(medtronicUtil.getMedtronicPumpModel()) - 1); j++) {
try { try {
listRawData.add(dataClear.get(counter)); listRawData.add(dataClear.get(counter));
counter++; counter++;
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("OpCode: " + ByteUtil.shortHexString((byte) opCode) + ", Invalid package: " aapsLogger.error(LTag.PUMPBTCOMM, "OpCode: " + ByteUtil.shortHexString((byte) opCode) + ", Invalid package: "
+ ByteUtil.getHex(listRawData)); + ByteUtil.getHex(listRawData));
// throw ex; // throw ex;
incompletePacket = true; incompletePacket = true;
@ -133,14 +134,14 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
} }
if (entryType == PumpHistoryEntryType.None) { if (entryType == PumpHistoryEntryType.None) {
LOG.error("Error in code. We should have not come into this branch."); aapsLogger.error(LTag.PUMPBTCOMM, "Error in code. We should have not come into this branch.");
} else { } else {
if (pe.getEntryType() == PumpHistoryEntryType.UnknownBasePacket) { if (pe.getEntryType() == PumpHistoryEntryType.UnknownBasePacket) {
pe.setOpCode(opCode); pe.setOpCode(opCode);
} }
if (entryType.getHeadLength() == 0) if (entryType.getHeadLength(medtronicUtil.getMedtronicPumpModel()) == 0)
special = true; special = true;
pe.setData(listRawData, special); pe.setData(listRawData, special);
@ -150,7 +151,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
if ((decoded == RecordDecodeStatus.OK) || (decoded == RecordDecodeStatus.Ignored)) { if ((decoded == RecordDecodeStatus.OK) || (decoded == RecordDecodeStatus.Ignored)) {
//Log.i(TAG, "#" + record + " " + decoded.getDescription() + " " + pe); //Log.i(TAG, "#" + record + " " + decoded.getDescription() + " " + pe);
} else { } else {
Log.w(TAG, "#" + record + " " + decoded.getDescription() + " " + pe); aapsLogger.warn(LTag.PUMPBTCOMM, "#" + record + " " + decoded.getDescription() + " " + pe);
} }
addToStatistics(pe, decoded, null); addToStatistics(pe, decoded, null);
@ -173,13 +174,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
try { try {
return decodeRecord(record, false); return decodeRecord(record, false);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error(" Error decoding: type={}, ex={}", record.getEntryType().name(), ex.getMessage(), ex); aapsLogger.error(LTag.PUMPBTCOMM, " Error decoding: type={}, ex={}", record.getEntryType().name(), ex.getMessage(), ex);
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
} }
} }
public RecordDecodeStatus decodeRecord(PumpHistoryEntry entry, boolean x) { private RecordDecodeStatus decodeRecord(PumpHistoryEntry entry, boolean x) {
if (entry.getDateTimeLength() > 0) { if (entry.getDateTimeLength() > 0) {
decodeDateTime(entry); decodeDateTime(entry);
@ -260,7 +261,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
case EventUnknown_0x4d: case EventUnknown_0x4d:
case EventUnknown_MM522_0x25: case EventUnknown_MM522_0x25:
case EventUnknown_MM522_0x05: case EventUnknown_MM522_0x05:
LOG.debug(" -- ignored Unknown Pump Entry: " + entry); aapsLogger.debug(LTag.PUMPBTCOMM, " -- ignored Unknown Pump Entry: " + entry);
return RecordDecodeStatus.Ignored; return RecordDecodeStatus.Ignored;
case UnabsorbedInsulin: case UnabsorbedInsulin:
@ -340,7 +341,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
default: { default: {
LOG.debug("Not supported: " + entry.getEntryType()); aapsLogger.debug(LTag.PUMPBTCOMM, "Not supported: " + entry.getEntryType());
return RecordDecodeStatus.NotSupported; return RecordDecodeStatus.NotSupported;
} }
@ -396,7 +397,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
} }
public static String getFormattedValue(float value, int decimals) { private static String getFormattedValue(float value, int decimals) {
return String.format(Locale.ENGLISH, "%." + decimals + "f", value); return String.format(Locale.ENGLISH, "%." + decimals + "f", value);
} }
@ -408,16 +409,14 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
Float rate = null; Float rate = null;
int index = entry.getHead()[0]; int index = entry.getHead()[0];
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getInstance().getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(medtronicUtil.getMedtronicPumpModel(), MedtronicDeviceType.Medtronic_523andHigher)) {
MedtronicDeviceType.Medtronic_523andHigher)) {
rate = body[1] * 0.025f; rate = body[1] * 0.025f;
} }
//LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index, body); //LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index, body);
if (rate == null) { if (rate == null) {
LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index, aapsLogger.warn(LTag.PUMPBTCOMM, "Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index, body);
body);
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
} else { } else {
entry.addDecodedData("Value", getFormattedFloat(rate, 3)); entry.addDecodedData("Value", getFormattedFloat(rate, 3));
@ -435,8 +434,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
float bolusStrokes = 10.0f; float bolusStrokes = 10.0f;
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getInstance().getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(medtronicUtil.getMedtronicPumpModel(), MedtronicDeviceType.Medtronic_523andHigher)) {
MedtronicDeviceType.Medtronic_523andHigher)) {
// https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102 // https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102
bolusStrokes = 40.0f; bolusStrokes = 40.0f;
@ -447,19 +445,19 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
// carb_ratio (?) = (((self.body[2] & 0x07) << 8) + self.body[3]) / // carb_ratio (?) = (((self.body[2] & 0x07) << 8) + self.body[3]) /
// 10.0s // 10.0s
dto.insulinSensitivity = new Float(body[4]); dto.insulinSensitivity = new Float(body[4]);
dto.bgTargetLow = (int)body[5]; dto.bgTargetLow = (int) body[5];
dto.bgTargetHigh = (int)body[14]; dto.bgTargetHigh = (int) body[14];
dto.correctionEstimate = (((body[9] & 0x38) << 5) + body[6]) / bolusStrokes; dto.correctionEstimate = (((body[9] & 0x38) << 5) + body[6]) / bolusStrokes;
dto.foodEstimate = ((body[7] << 8) + body[8]) / bolusStrokes; dto.foodEstimate = ((body[7] << 8) + body[8]) / bolusStrokes;
dto.unabsorbedInsulin = ((body[10] << 8) + body[11]) / bolusStrokes; dto.unabsorbedInsulin = ((body[10] << 8) + body[11]) / bolusStrokes;
dto.bolusTotal = ((body[12] << 8) + body[13]) / bolusStrokes; dto.bolusTotal = ((body[12] << 8) + body[13]) / bolusStrokes;
} else { } else {
dto.bloodGlucose = (((body[1] & 0x0F) << 8) | entry.getHead()[0]); dto.bloodGlucose = (((body[1] & 0x0F) << 8) | entry.getHead()[0]);
dto.carbs = (int)body[0]; dto.carbs = (int) body[0];
dto.carbRatio = Float.valueOf(body[2]); dto.carbRatio = Float.valueOf(body[2]);
dto.insulinSensitivity = new Float(body[3]); dto.insulinSensitivity = new Float(body[3]);
dto.bgTargetLow = (int)body[4]; dto.bgTargetLow = (int) body[4];
dto.bgTargetHigh = (int)body[12]; dto.bgTargetHigh = (int) body[12];
dto.bolusTotal = body[11] / bolusStrokes; dto.bolusTotal = body[11] / bolusStrokes;
dto.foodEstimate = body[6] / bolusStrokes; dto.foodEstimate = body[6] / bolusStrokes;
dto.unabsorbedInsulin = body[9] / bolusStrokes; dto.unabsorbedInsulin = body[9] / bolusStrokes;
@ -490,7 +488,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
dto.carbs = (body[1] & 0xC) << 6 | body[0]; // (int)body[0]; dto.carbs = (body[1] & 0xC) << 6 | body[0]; // (int)body[0];
dto.carbRatio = Float.valueOf(body[2]); dto.carbRatio = Float.valueOf(body[2]);
dto.insulinSensitivity = new Float(body[3]); dto.insulinSensitivity = new Float(body[3]);
dto.bgTargetLow = (int)body[4]; dto.bgTargetLow = (int) body[4];
dto.foodEstimate = body[6] / 10.0f; dto.foodEstimate = body[6] / 10.0f;
dto.correctionEstimate = (body[7] + (body[5] & 0x0F)) / bolusStrokes; dto.correctionEstimate = (body[7] + (body[5] & 0x0F)) / bolusStrokes;
dto.unabsorbedInsulin = body[9] / bolusStrokes; dto.unabsorbedInsulin = body[9] / bolusStrokes;
@ -570,8 +568,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
byte[] data = entry.getHead(); byte[] data = entry.getHead();
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getInstance().getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(medtronicUtil.getMedtronicPumpModel(), MedtronicDeviceType.Medtronic_523andHigher)) {
MedtronicDeviceType.Medtronic_523andHigher)) {
bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0d); bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0d);
bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0d); bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0d);
bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0d); bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0d);
@ -639,7 +636,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
byte[] dt = entry.getDatetime(); byte[] dt = entry.getDatetime();
if (dt == null) { if (dt == null) {
LOG.warn("DateTime not set."); aapsLogger.warn(LTag.PUMPBTCOMM, "DateTime not set.");
} }
if (entry.getDateTimeLength() == 5) { if (entry.getDateTimeLength() == 5) {
@ -673,7 +670,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
//LOG.debug("DT: {} {} {}", year, month, dayOfMonth); //LOG.debug("DT: {} {} {}", year, month, dayOfMonth);
if (dayOfMonth == 32) { if (dayOfMonth == 32) {
LOG.warn("Entry: Day 32 {} = [{}] {}", entry.getEntryType().name(), aapsLogger.warn(LTag.PUMPBTCOMM, "Entry: Day 32 {} = [{}] {}", entry.getEntryType().name(),
ByteUtil.getHex(entry.getRawData()), entry); ByteUtil.getHex(entry.getRawData()), entry);
} }
@ -686,7 +683,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds)); entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds));
} else { } else {
LOG.warn("Unknown datetime format: " + entry.getDateTimeLength()); aapsLogger.warn(LTag.PUMPBTCOMM, "Unknown datetime format: " + entry.getDateTimeLength());
} }
} }

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects; import java.util.Objects;
@ -11,6 +10,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; 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.medtronic.comm.history.MedtronicHistoryEntry; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
/** /**
* 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
@ -35,12 +35,12 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry {
} }
public void setEntryType(PumpHistoryEntryType entryType) { public void setEntryType(MedtronicDeviceType medtronicDeviceType, PumpHistoryEntryType entryType) {
this.entryType = entryType; this.entryType = entryType;
this.sizes[0] = entryType.getHeadLength(); this.sizes[0] = entryType.getHeadLength(medtronicDeviceType);
this.sizes[1] = entryType.getDateLength(); this.sizes[1] = entryType.getDateLength();
this.sizes[2] = entryType.getBodyLength(); this.sizes[2] = entryType.getBodyLength(medtronicDeviceType);
if (this.entryType != null && this.atechDateTime != null) if (this.entryType != null && this.atechDateTime != null)
setPumpId(); setPumpId();

View file

@ -7,12 +7,11 @@ import java.util.Map;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup; 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;
/** /**
* 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}
*/ */
@ -289,9 +288,9 @@ public enum PumpHistoryEntryType // implements CodeEnum
} }
public int getTotalLength() { public int getTotalLength(MedtronicDeviceType medtronicDeviceType) {
if (hasSpecialRules()) { if (hasSpecialRules()) {
return getHeadLength() + getBodyLength() + getDateLength(); return getHeadLength(medtronicDeviceType) + getBodyLength(medtronicDeviceType) + getDateLength();
} else { } else {
return totalLength; return totalLength;
} }
@ -305,7 +304,7 @@ public enum PumpHistoryEntryType // implements CodeEnum
void addSpecialRuleHead(SpecialRule rule) { void addSpecialRuleHead(SpecialRule rule) {
if (isEmpty(specialRulesHead)) { if (isEmpty(specialRulesHead)) {
specialRulesHead = new ArrayList<SpecialRule>(); specialRulesHead = new ArrayList<>();
} }
specialRulesHead.add(rule); specialRulesHead.add(rule);
@ -315,7 +314,7 @@ public enum PumpHistoryEntryType // implements CodeEnum
void addSpecialRuleBody(SpecialRule rule) { void addSpecialRuleBody(SpecialRule rule) {
if (isEmpty(specialRulesBody)) { if (isEmpty(specialRulesBody)) {
specialRulesBody = new ArrayList<SpecialRule>(); specialRulesBody = new ArrayList<>();
} }
specialRulesBody.add(rule); specialRulesBody.add(rule);
@ -333,10 +332,10 @@ public enum PumpHistoryEntryType // implements CodeEnum
} }
public int getHeadLength() { public int getHeadLength(MedtronicDeviceType medtronicDeviceType) {
if (hasSpecialRules) { if (hasSpecialRules) {
if (isNotEmpty(specialRulesHead)) { if (isNotEmpty(specialRulesHead)) {
return determineSizeByRule(headLength, specialRulesHead); return determineSizeByRule(medtronicDeviceType, headLength, specialRulesHead);
} else { } else {
return headLength; return headLength;
} }
@ -351,10 +350,10 @@ public enum PumpHistoryEntryType // implements CodeEnum
} }
public int getBodyLength() { public int getBodyLength(MedtronicDeviceType medtronicDeviceType) {
if (hasSpecialRules) { if (hasSpecialRules) {
if (isNotEmpty(specialRulesBody)) { if (isNotEmpty(specialRulesBody)) {
return determineSizeByRule(bodyLength, specialRulesBody); return determineSizeByRule(medtronicDeviceType, bodyLength, specialRulesBody);
} else { } else {
return bodyLength; return bodyLength;
} }
@ -376,11 +375,11 @@ public enum PumpHistoryEntryType // implements CodeEnum
// byte[] dh = { 2, 3 }; // byte[] dh = { 2, 3 };
private int determineSizeByRule(int defaultValue, List<SpecialRule> rules) { private int determineSizeByRule(MedtronicDeviceType medtronicDeviceType, int defaultValue, List<SpecialRule> rules) {
int size = defaultValue; int size = defaultValue;
for (SpecialRule rule : rules) { for (SpecialRule rule : rules) {
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getInstance().getMedtronicPumpModel(), rule.deviceType)) { if (MedtronicDeviceType.isSameDevice(medtronicDeviceType, rule.deviceType)) {
size = rule.size; size = rule.size;
break; break;
} }
@ -395,29 +394,6 @@ public enum PumpHistoryEntryType // implements CodeEnum
return group; return group;
} }
enum DateFormat {
None(0), //
LongDate(5), //
ShortDate(2);
private int length;
DateFormat(int length) {
this.length = length;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
}
public static class SpecialRule { public static class SpecialRule {
MedtronicDeviceType deviceType; MedtronicDeviceType deviceType;

View file

@ -18,10 +18,12 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.DbObjectBase; import info.nightscout.androidaps.db.DbObjectBase;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
@ -68,11 +70,13 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code // All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
@Singleton
public class MedtronicHistoryData { public class MedtronicHistoryData {
private AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private SP sp; private final SP sp;
private ActivePluginProvider activePlugin; private final ActivePluginProvider activePlugin;
private final MedtronicUtil medtronicUtil;
private List<PumpHistoryEntry> allHistory = null; private List<PumpHistoryEntry> allHistory = null;
private List<PumpHistoryEntry> newHistory = null; private List<PumpHistoryEntry> newHistory = null;
@ -80,10 +84,9 @@ public class MedtronicHistoryData {
private Long lastHistoryRecordTime; private Long lastHistoryRecordTime;
private boolean isInit = false; private boolean isInit = false;
private Gson gson; private Gson gson; // cannot be initialized in constructor because of injection
private Gson gsonCore; private Gson gsonCore; // cannot be initialized in constructor because of injection
private DatabaseHelper databaseHelper = MainApp.getDbHelper();
private ClockDTO pumpTime; private ClockDTO pumpTime;
private long lastIdUsed = 0; private long lastIdUsed = 0;
@ -95,17 +98,30 @@ public class MedtronicHistoryData {
*/ */
public static boolean doubleBolusDebug = false; public static boolean doubleBolusDebug = false;
@Inject
public MedtronicHistoryData(AAPSLogger aapsLogger, SP sp, ActivePluginProvider activePlugin) { public MedtronicHistoryData(
AAPSLogger aapsLogger,
SP sp,
ActivePluginProvider activePlugin,
MedtronicUtil medtronicUtil
) {
this.allHistory = new ArrayList<>(); this.allHistory = new ArrayList<>();
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
this.gsonCore = new GsonBuilder().create();
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.sp = sp; this.sp = sp;
this.activePlugin = activePlugin; this.activePlugin = activePlugin;
this.medtronicUtil = medtronicUtil;
} }
private Gson gson() {
if (gson == null) gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
return gson;
}
private Gson gsonCore() {
if (gsonCore == null) gsonCore = new GsonBuilder().create();
return gsonCore;
}
/** /**
* Add New History entries * Add New History entries
@ -127,7 +143,7 @@ public class MedtronicHistoryData {
this.newHistory = newEntries; this.newHistory = newEntries;
showLogs("List of history (before filtering): [" + this.newHistory.size() + "]", gson.toJson(this.newHistory)); showLogs("List of history (before filtering): [" + this.newHistory.size() + "]", gson().toJson(this.newHistory));
} }
@ -201,7 +217,7 @@ public class MedtronicHistoryData {
aapsLogger.debug(LTag.PUMP, "New History entries found: {}", this.newHistory.size()); aapsLogger.debug(LTag.PUMP, "New History entries found: {}", this.newHistory.size());
showLogs("List of history (after filtering): [" + this.newHistory.size() + "]", gson.toJson(this.newHistory)); showLogs("List of history (after filtering): [" + this.newHistory.size() + "]", gson().toJson(this.newHistory));
} }
@ -314,7 +330,7 @@ public class MedtronicHistoryData {
List<PumpHistoryEntry> items = getDataForPumpSuspends(); List<PumpHistoryEntry> items = getDataForPumpSuspends();
showLogs("isPumpSuspended: ", gson.toJson(items)); showLogs("isPumpSuspended: ", gson().toJson(items));
if (isCollectionNotEmpty(items)) { if (isCollectionNotEmpty(items)) {
@ -400,7 +416,7 @@ public class MedtronicHistoryData {
// Prime (for reseting autosense) // Prime (for reseting autosense)
List<PumpHistoryEntry> primeRecords = getFilteredItems(PumpHistoryEntryType.Prime); List<PumpHistoryEntry> primeRecords = getFilteredItems(PumpHistoryEntryType.Prime);
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Prime [count={}, items={}]", primeRecords.size(), gson.toJson(primeRecords)); aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Prime [count={}, items={}]", primeRecords.size(), gson().toJson(primeRecords));
if (isCollectionNotEmpty(primeRecords)) { if (isCollectionNotEmpty(primeRecords)) {
try { try {
@ -414,7 +430,7 @@ public class MedtronicHistoryData {
// TDD // TDD
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType()); List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds)); aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson().toJson(tdds));
if (isCollectionNotEmpty(tdds)) { if (isCollectionNotEmpty(tdds)) {
try { try {
@ -430,7 +446,7 @@ public class MedtronicHistoryData {
// Bolus // Bolus
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus); List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments)); aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson().toJson(treatments));
if (treatments.size() > 0) { if (treatments.size() > 0) {
try { try {
@ -444,7 +460,7 @@ public class MedtronicHistoryData {
// TBR // TBR
List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined); List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs)); aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson().toJson(tbrs));
if (tbrs.size() > 0) { if (tbrs.size() > 0) {
try { try {
@ -466,7 +482,7 @@ public class MedtronicHistoryData {
} }
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(), aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
gson.toJson(suspends)); gson().toJson(suspends));
if (isCollectionNotEmpty(suspends)) { if (isCollectionNotEmpty(suspends)) {
try { try {
@ -532,9 +548,9 @@ public class MedtronicHistoryData {
List<PumpHistoryEntry> tdds = filterTDDs(tddsIn); List<PumpHistoryEntry> tdds = filterTDDs(tddsIn);
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gson.toJson(tdds)); aapsLogger.debug(LTag.PUMP, getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gson().toJson(tdds));
List<TDD> tddsDb = databaseHelper.getTDDsForLastXDays(3); List<TDD> tddsDb = MainApp.getDbHelper().getTDDsForLastXDays(3);
for (PumpHistoryEntry tdd : tdds) { for (PumpHistoryEntry tdd : tdds) {
@ -550,7 +566,7 @@ public class MedtronicHistoryData {
aapsLogger.debug(LTag.PUMP, "TDD Add: {}", tddNew); aapsLogger.debug(LTag.PUMP, "TDD Add: {}", tddNew);
databaseHelper.createOrUpdateTDD(tddNew); MainApp.getDbHelper().createOrUpdateTDD(tddNew);
} else { } else {
@ -559,7 +575,7 @@ public class MedtronicHistoryData {
aapsLogger.debug(LTag.PUMP, "TDD Edit: {}", tddDbEntry); aapsLogger.debug(LTag.PUMP, "TDD Edit: {}", tddDbEntry);
databaseHelper.createOrUpdateTDD(tddDbEntry); MainApp.getDbHelper().createOrUpdateTDD(tddDbEntry);
} }
} }
} }
@ -591,8 +607,8 @@ public class MedtronicHistoryData {
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus); List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
if (doubleBolusDebug) if (doubleBolusDebug)
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList), aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (before filter): {}, FromDb={}", gson().toJson(entryList),
gsonCore.toJson(entriesFromHistory)); gsonCore().toJson(entriesFromHistory));
filterOutAlreadyAddedEntries(entryList, entriesFromHistory); filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
@ -605,8 +621,8 @@ public class MedtronicHistoryData {
filterOutNonInsulinEntries(entriesFromHistory); filterOutNonInsulinEntries(entriesFromHistory);
if (doubleBolusDebug) if (doubleBolusDebug)
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList), aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (after filter): {}, FromDb={}", gson().toJson(entryList),
gsonCore.toJson(entriesFromHistory)); gsonCore().toJson(entriesFromHistory));
if (isCollectionEmpty(entriesFromHistory)) { if (isCollectionEmpty(entriesFromHistory)) {
for (PumpHistoryEntry treatment : entryList) { for (PumpHistoryEntry treatment : entryList) {
@ -669,8 +685,8 @@ public class MedtronicHistoryData {
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR); List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR);
aapsLogger.debug(LTag.PUMP, ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList), aapsLogger.debug(LTag.PUMP, ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson().toJson(entryList),
gson.toJson(entriesFromHistory)); gson().toJson(entriesFromHistory));
TempBasalProcessDTO processDTO = null; TempBasalProcessDTO processDTO = null;
@ -720,7 +736,7 @@ public class MedtronicHistoryData {
tempBasal.durationInMinutes = tempBasalProcessDTO.getDuration(); tempBasal.durationInMinutes = tempBasalProcessDTO.getDuration();
databaseHelper.createOrUpdate(tempBasal); MainApp.getDbHelper().createOrUpdate(tempBasal);
aapsLogger.debug(LTag.PUMP, "Edit " + ProcessHistoryRecord.TBR.getDescription() + " - (entryFromDb={}) ", tempBasal); aapsLogger.debug(LTag.PUMP, "Edit " + ProcessHistoryRecord.TBR.getDescription() + " - (entryFromDb={}) ", tempBasal);
} else { } else {
@ -768,7 +784,7 @@ public class MedtronicHistoryData {
} }
} }
TemporaryBasal tempBasal = databaseHelper.findTempBasalByPumpId(pumpId); TemporaryBasal tempBasal = MainApp.getDbHelper().findTempBasalByPumpId(pumpId);
return tempBasal; return tempBasal;
} }
@ -789,7 +805,7 @@ public class MedtronicHistoryData {
//proposedTime += (this.pumpTime.timeDifference * 1000); //proposedTime += (this.pumpTime.timeDifference * 1000);
if (doubleBolusDebug) if (doubleBolusDebug)
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson.toJson(entriesFromHistory)); aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson().toJson(entriesFromHistory));
if (entriesFromHistory.size() == 0) { if (entriesFromHistory.size() == 0) {
if (doubleBolusDebug) if (doubleBolusDebug)
@ -843,10 +859,10 @@ public class MedtronicHistoryData {
if (min == 0 && sec == 10 && outList.size() > 1) { if (min == 0 && sec == 10 && outList.size() > 1) {
aapsLogger.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})", aapsLogger.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
min, sec, outList.size(), gson.toJson(outList)); min, sec, outList.size(), gson().toJson(outList));
if (doubleBolusDebug) if (doubleBolusDebug)
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})", aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
min, sec, outList.size(), gson.toJson(outList)); min, sec, outList.size(), gson().toJson(outList));
} }
} }
} }
@ -859,7 +875,7 @@ public class MedtronicHistoryData {
if (processHistoryRecord == ProcessHistoryRecord.Bolus) { if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
return activePlugin.getActiveTreatments().getTreatmentsFromHistoryAfterTimestamp(startTimestamp); return activePlugin.getActiveTreatments().getTreatmentsFromHistoryAfterTimestamp(startTimestamp);
} else { } else {
return databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true); return MainApp.getDbHelper().getTemporaryBasalsDataFromTime(startTimestamp, true);
} }
} }
@ -896,8 +912,8 @@ public class MedtronicHistoryData {
if (doubleBolusDebug) if (doubleBolusDebug)
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}", aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
gson.toJson(removeTreatmentsFromPH), gson().toJson(removeTreatmentsFromPH),
gsonCore.toJson(removeTreatmentsFromHistory)); gsonCore().toJson(removeTreatmentsFromHistory));
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory); treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
} }
@ -1017,7 +1033,7 @@ public class MedtronicHistoryData {
treatment.setLinkedObject(temporaryBasalDb); treatment.setLinkedObject(temporaryBasalDb);
databaseHelper.createOrUpdate(temporaryBasalDb); MainApp.getDbHelper().createOrUpdate(temporaryBasalDb);
aapsLogger.debug(LTag.PUMP, operation + " - [date={},pumpId={}, rate={} {}, duration={}]", // aapsLogger.debug(LTag.PUMP, operation + " - [date={},pumpId={}, rate={} {}, duration={}]", //
temporaryBasalDb.date, // temporaryBasalDb.date, //
@ -1033,7 +1049,7 @@ public class MedtronicHistoryData {
for (TempBasalProcessDTO tempBasalProcess : tempBasalProcessList) { for (TempBasalProcessDTO tempBasalProcess : tempBasalProcessList) {
TemporaryBasal tempBasal = databaseHelper.findTempBasalByPumpId(tempBasalProcess.itemOne.getPumpId()); TemporaryBasal tempBasal = MainApp.getDbHelper().findTempBasalByPumpId(tempBasalProcess.itemOne.getPumpId());
if (tempBasal == null) { if (tempBasal == null) {
// add // add
@ -1049,7 +1065,7 @@ public class MedtronicHistoryData {
tempBasalProcess.itemOne.setLinkedObject(tempBasal); tempBasalProcess.itemOne.setLinkedObject(tempBasal);
tempBasalProcess.itemTwo.setLinkedObject(tempBasal); tempBasalProcess.itemTwo.setLinkedObject(tempBasal);
databaseHelper.createOrUpdate(tempBasal); MainApp.getDbHelper().createOrUpdate(tempBasal);
} }
} }
@ -1196,11 +1212,11 @@ public class MedtronicHistoryData {
if (!finishedItems) { if (!finishedItems) {
showLogs("NoDeliveryRewindPrimeRecords: Not finished Items: ", gson.toJson(tempData)); showLogs("NoDeliveryRewindPrimeRecords: Not finished Items: ", gson().toJson(tempData));
return outList; return outList;
} }
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData)); showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson().toJson(tempData));
List<PumpHistoryEntry> items = getFilteredItems(tempData, // List<PumpHistoryEntry> items = getFilteredItems(tempData, //
PumpHistoryEntryType.Prime PumpHistoryEntryType.Prime
@ -1392,7 +1408,7 @@ public class MedtronicHistoryData {
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile); List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson.toJson(filteredItems)); aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson().toJson(filteredItems));
return (filteredItems.size() > 0); return (filteredItems.size() > 0);
} }
@ -1462,7 +1478,7 @@ public class MedtronicHistoryData {
for (PumpHistoryEntry pumpHistoryEntry : TBRs_Input) { for (PumpHistoryEntry pumpHistoryEntry : TBRs_Input) {
if (map.containsKey(pumpHistoryEntry.DT)) { if (map.containsKey(pumpHistoryEntry.DT)) {
MedtronicPumpHistoryDecoder.decodeTempBasal(map.get(pumpHistoryEntry.DT), pumpHistoryEntry); MedtronicPumpHistoryDecoder.decodeTempBasal(map.get(pumpHistoryEntry.DT), pumpHistoryEntry);
pumpHistoryEntry.setEntryType(PumpHistoryEntryType.TempBasalCombined); pumpHistoryEntry.setEntryType(medtronicUtil.getMedtronicPumpModel(), PumpHistoryEntryType.TempBasalCombined);
TBRs.add(pumpHistoryEntry); TBRs.add(pumpHistoryEntry);
map.remove(pumpHistoryEntry.DT); map.remove(pumpHistoryEntry.DT);
} else { } else {

View file

@ -23,11 +23,13 @@ import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup; 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.data.MedtronicHistoryData;
public class MedtronicHistoryActivity extends NoSplashAppCompatActivity { public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
@Inject MedtronicPumpPlugin medtronicPumpPlugin; @Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MedtronicHistoryData medtronicHistoryData;
Spinner historyTypeSpinner; Spinner historyTypeSpinner;
TextView statusView; TextView statusView;
@ -49,7 +51,7 @@ public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
this.filteredHistoryList.clear(); this.filteredHistoryList.clear();
List<PumpHistoryEntry> list = new ArrayList<>(); List<PumpHistoryEntry> list = new ArrayList<>();
list.addAll(medtronicPumpPlugin.getMedtronicHistoryData().getAllHistory()); list.addAll(medtronicHistoryData.getAllHistory());
//LOG.debug("Items on full list: {}", list.size()); //LOG.debug("Items on full list: {}", list.size());

View file

@ -41,7 +41,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class MedtronicUtil { public class MedtronicUtil {
private int ENVELOPE_SIZE = 4; // 0xA7 S1 S2 S3 CMD PARAM_COUNT [PARAMS] private int ENVELOPE_SIZE = 4; // 0xA7 S1 S2 S3 CMD PARAM_COUNT [PARAMS]
private boolean lowLevelDebug = true; private static boolean lowLevelDebug = true;
private PumpDeviceState pumpDeviceState; private PumpDeviceState pumpDeviceState;
private MedtronicDeviceType medtronicPumpModel; private MedtronicDeviceType medtronicPumpModel;
private MedtronicCommandType currentCommand; private MedtronicCommandType currentCommand;
@ -396,16 +396,10 @@ public class MedtronicUtil {
} }
public boolean isLowLevelDebug() { public static boolean isLowLevelDebug() {
return lowLevelDebug; return lowLevelDebug;
} }
public void setLowLevelDebug(boolean lowLevelDebug) {
this.lowLevelDebug = lowLevelDebug;
}
public PumpDeviceState getPumpDeviceState() { public PumpDeviceState getPumpDeviceState() {
return pumpDeviceState; return pumpDeviceState;
} }

View file

@ -21,7 +21,7 @@ import static org.mockito.Mockito.when;
* Created by andy on 3/10/19. * Created by andy on 3/10/19.
*/ */
public class MedtronicHistoryDataUTest { public class MedtronicHistoryDataUTest {
/*
//TestLogger LOGGER = TestLoggerFactory.getTestLogger(MedtronicHistoryDataUTest.class); //TestLogger LOGGER = TestLoggerFactory.getTestLogger(MedtronicHistoryDataUTest.class);
byte[] historyPageData = ByteUtil byte[] historyPageData = ByteUtil
@ -123,5 +123,5 @@ public class MedtronicHistoryDataUTest {
} }
} }
*/
} }