From 72eae6e6b82623cb70d17c357f5e86e91f276ebd Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 7 Feb 2019 22:41:05 +0000 Subject: [PATCH] - refactored commands, removed version out of it - finished Medtronic History Dialog (middle button) - refactored Set/Get Basal functionality --- .../hw/rileylink/RileyLinkUtil.java | 15 +- .../PumpCommon/hw/rileylink/ble/RFSpy.java | 15 +- .../hw/rileylink/ble/command/GetVersion.java | 5 +- .../ble/command/RileyLinkCommand.java | 7 +- .../rileylink/ble/command/SendAndListen.java | 17 +- ...Encoding.java => SetHardwareEncoding.java} | 9 +- .../hw/rileylink/ble/command/SetPreamble.java | 10 +- .../rileylink/ble/command/UpdateRegister.java | 5 +- .../ble/defs/RileyLinkCommandType.java | 4 +- .../dialog/RileyLinkStatusHistory.java | 250 +++++++++++++----- .../PumpMedtronic/MedtronicPumpPlugin.java | 9 + .../comm/history/MedtronicHistoryEntry.java | 2 +- .../pump/MedtronicPumpHistoryDecoder.java | 49 +++- .../comm/history/pump/PumpHistoryEntry.java | 23 +- .../history/pump/PumpHistoryEntryGroup.java | 11 + .../history/pump/PumpHistoryEntryType.java | 230 +++++++--------- .../comm/history/pump/PumpHistoryResult.java | 44 ++- .../data/MedtronicHistoryData.java | 48 ++-- .../PumpMedtronic/data/dto/BasalProfile.java | 26 ++ .../PumpMedtronic/data/dto/BolusDTO.java | 11 + .../PumpMedtronic/data/dto/TempBasalPair.java | 4 +- .../dialog/MedtronicHistoryActivity.java | 155 ++++++----- .../res/layout/medtronic_history_activity.xml | 3 +- .../res/layout/medtronic_history_item.xml | 34 +++ .../res/layout/rileylink_status_history.xml | 16 +- .../layout/rileylink_status_history_item.xml | 2 +- app/src/main/res/values/strings.xml | 1 + .../MedtronicPumpHistoryDecoderUTest.java | 19 ++ .../data/dto/BasalProfileUTest.java | 25 ++ 29 files changed, 696 insertions(+), 353 deletions(-) rename app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/{SetSoftwareEncoding.java => SetHardwareEncoding.java} (62%) create mode 100644 app/src/main/res/layout/medtronic_history_item.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java index e41da27883..987bd682f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkB import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.encoding.Encoding4b6b; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.encoding.Encoding4b6bGeoff; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkEncodingType; +import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkTargetFrequency; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.BleAdvertisedData; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.RLHistoryItem; @@ -32,7 +33,6 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.S import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.ServiceTransport; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTask; import info.nightscout.androidaps.plugins.PumpCommon.ui.RileyLinkSelectPreference; -import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType; import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange; /** @@ -52,7 +52,7 @@ public class RileyLinkUtil { // private static MedtronicPumpStatus medtronicPumpStatus; private static RileyLinkService rileyLinkService; // private static RileyLinkIPCConnection rileyLinkIPCConnection; - private static MedtronicDeviceType medtronicPumpModel; + // private static MedtronicDeviceType medtronicPumpModel; // BAD dependencies in Classes: RileyLinkService private static RileyLinkTargetFrequency rileyLinkTargetFrequency; @@ -62,6 +62,7 @@ public class RileyLinkUtil { private static RileyLinkEncodingType encoding; private static RileyLinkSelectPreference rileyLinkSelectPreference; private static Encoding4b6b encoding4b6b; + private static RileyLinkFirmwareVersion firmwareVersion; public static void setContext(Context contextIn) { @@ -329,4 +330,14 @@ public class RileyLinkUtil { public static Encoding4b6b getEncoding4b6b() { return RileyLinkUtil.encoding4b6b; } + + + public static void setFirmwareVersion(RileyLinkFirmwareVersion firmwareVersion) { + RileyLinkUtil.firmwareVersion = firmwareVersion; + } + + + public static RileyLinkFirmwareVersion getFirmwareVersion() { + return firmwareVersion; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/RFSpy.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/RFSpy.java index d17edd9589..259885c01b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/RFSpy.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/RFSpy.java @@ -10,8 +10,8 @@ import android.os.SystemClock; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.RileyLinkCommand; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.SendAndListen; +import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.SetHardwareEncoding; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.SetPreamble; -import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.SetSoftwareEncoding; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.UpdateRegister; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.RFSpyResponse; @@ -83,6 +83,7 @@ public class RFSpy { public void initializeRileyLink() { bleVersion = getVersion(); firmwareVersion = getFirmwareVersion(); + RileyLinkUtil.setFirmwareVersion(firmwareVersion); } @@ -286,16 +287,15 @@ public class RFSpy { int sendDelay = repeatCount * delay_ms; int receiveDelay = timeout_ms * (retryCount + 1); - SendAndListen command = new SendAndListen(firmwareVersion, sendChannel, repeatCount, delay_ms, listenChannel, - timeout_ms, retryCount, extendPreamble_ms, pkt); + SendAndListen command = new SendAndListen(sendChannel, repeatCount, delay_ms, listenChannel, timeout_ms, + retryCount, extendPreamble_ms, pkt); return writeToData(command, sendDelay + receiveDelay + EXPECTED_MAX_BLUETOOTH_LATENCY_MS); } public RFSpyResponse updateRegister(CC111XRegister reg, int val) { - RFSpyResponse resp = writeToData(new UpdateRegister(firmwareVersion, reg, (byte)val), - EXPECTED_MAX_BLUETOOTH_LATENCY_MS); + RFSpyResponse resp = writeToData(new UpdateRegister(reg, (byte)val), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); return resp; } @@ -397,7 +397,7 @@ public class RFSpy { private RFSpyResponse setPreamble(int preamble) { RFSpyResponse resp = null; try { - resp = writeToData(new SetPreamble(firmwareVersion, preamble), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); + resp = writeToData(new SetPreamble(preamble), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); } catch (Exception e) { e.toString(); } @@ -406,8 +406,7 @@ public class RFSpy { private RFSpyResponse setSoftwareEncoding(RileyLinkEncodingType encoding) { - RFSpyResponse resp = writeToData(new SetSoftwareEncoding(firmwareVersion, encoding), - EXPECTED_MAX_BLUETOOTH_LATENCY_MS); + RFSpyResponse resp = writeToData(new SetHardwareEncoding(encoding), EXPECTED_MAX_BLUETOOTH_LATENCY_MS); return resp; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/GetVersion.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/GetVersion.java index 0416af4737..517af297bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/GetVersion.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/GetVersion.java @@ -1,12 +1,11 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; -import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; public class GetVersion extends RileyLinkCommand { - public GetVersion(RileyLinkFirmwareVersion version) { - super(version); + public GetVersion() { + super(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/RileyLinkCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/RileyLinkCommand.java index b8c2853de1..1658655478 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/RileyLinkCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/RileyLinkCommand.java @@ -1,15 +1,10 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; -import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; public abstract class RileyLinkCommand { - protected RileyLinkFirmwareVersion version; - - - public RileyLinkCommand(RileyLinkFirmwareVersion version) { - this.version = version; + public RileyLinkCommand() { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java index b68722870f..4fa86e3884 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command; import java.nio.ByteBuffer; import java.util.ArrayList; +import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.RadioPacket; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; @@ -20,21 +21,20 @@ public class SendAndListen extends RileyLinkCommand { private RadioPacket packetToSend; - public SendAndListen(RileyLinkFirmwareVersion version, byte sendChannel, byte repeatCount, - byte delayBetweenPackets_ms, byte listenChannel, int timeout_ms, byte retryCount, RadioPacket packetToSend + public SendAndListen(byte sendChannel, byte repeatCount, byte delayBetweenPackets_ms, byte listenChannel, + int timeout_ms, byte retryCount, RadioPacket packetToSend ) { - this(version, sendChannel, repeatCount, delayBetweenPackets_ms, listenChannel, timeout_ms, retryCount, null, + this(sendChannel, repeatCount, delayBetweenPackets_ms, listenChannel, timeout_ms, retryCount, null, packetToSend); } - public SendAndListen(RileyLinkFirmwareVersion version, byte sendChannel, byte repeatCount, - int delayBetweenPackets_ms, byte listenChannel, int timeout_ms, byte retryCount, - Integer preambleExtension_ms, RadioPacket packetToSend + public SendAndListen(byte sendChannel, byte repeatCount, int delayBetweenPackets_ms, byte listenChannel, + int timeout_ms, byte retryCount, Integer preambleExtension_ms, RadioPacket packetToSend ) { - super(version); + super(); this.sendChannel = sendChannel; this.repeatCount = repeatCount; this.delayBetweenPackets_ms = delayBetweenPackets_ms; @@ -55,7 +55,8 @@ public class SendAndListen extends RileyLinkCommand { @Override public byte[] getRaw() { - boolean isPacketV2 = this.version.isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher); + boolean isPacketV2 = RileyLinkUtil.getFirmwareVersion().isSameVersion( + RileyLinkFirmwareVersion.Version2AndHigher); ArrayList bytes = new ArrayList(); bytes.add(this.getCommandType().code); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetSoftwareEncoding.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetHardwareEncoding.java similarity index 62% rename from app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetSoftwareEncoding.java rename to app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetHardwareEncoding.java index 718d00b1cc..2aa9ec62da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetSoftwareEncoding.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetHardwareEncoding.java @@ -2,22 +2,21 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkEncodingType; -import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; -public class SetSoftwareEncoding extends RileyLinkCommand { +public class SetHardwareEncoding extends RileyLinkCommand { private final RileyLinkEncodingType encoding; - public SetSoftwareEncoding(RileyLinkFirmwareVersion version, RileyLinkEncodingType encoding) { - super(version); + public SetHardwareEncoding(RileyLinkEncodingType encoding) { + super(); this.encoding = encoding; } @Override public RileyLinkCommandType getCommandType() { - return RileyLinkCommandType.SetSWEncoding; + return RileyLinkCommandType.SetHardwareEncoding; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetPreamble.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetPreamble.java index d3bcde6bd6..2c2f53fcbe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetPreamble.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SetPreamble.java @@ -4,6 +4,7 @@ import java.nio.ByteBuffer; import org.apache.commons.lang3.NotImplementedException; +import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; @@ -12,10 +13,11 @@ public class SetPreamble extends RileyLinkCommand { private int preamble; - public SetPreamble(RileyLinkFirmwareVersion version, int preamble) throws Exception { - super(version); - if (!this.version.isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher)) { // this command was not supported - // before 2.0 + public SetPreamble(int preamble) throws Exception { + super(); + + // this command was not supported before 2.0 + if (!RileyLinkUtil.getFirmwareVersion().isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher)) { throw new NotImplementedException("Old firmware does not support SetPreamble command"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/UpdateRegister.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/UpdateRegister.java index 4817e79a08..900a6e0041 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/UpdateRegister.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/UpdateRegister.java @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.CC111XRegister; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; -import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; public class UpdateRegister extends RileyLinkCommand { @@ -10,8 +9,8 @@ public class UpdateRegister extends RileyLinkCommand { byte registerValue; - public UpdateRegister(RileyLinkFirmwareVersion version, CC111XRegister register, byte registerValue) { - super(version); + public UpdateRegister(CC111XRegister register, byte registerValue) { + super(); this.register = register; this.registerValue = registerValue; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkCommandType.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkCommandType.java index 4dc45a40aa..daa4335f48 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkCommandType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkCommandType.java @@ -14,9 +14,9 @@ public enum RileyLinkCommandType { UpdateRegister(6), // Reset(7), // Led(8), - ReadRegister(8), + ReadRegister(9), SetModeRegisters(10), - SetSWEncoding(11), + SetHardwareEncoding(11), SetPreamble(12), ResetRadioConfig(13), GetStatistics(14), ; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusHistory.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusHistory.java index 4f323b0b9c..dff8d98625 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusHistory.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusHistory.java @@ -5,11 +5,11 @@ import java.util.List; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListView; import android.widget.TextView; import info.nightscout.androidaps.R; @@ -26,16 +26,31 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState; public class RileyLinkStatusHistory extends Fragment implements RefreshableInterface { // @BindView(R.id.rileylink_history_list) - ListView listView; + // ListView listView; - RileyLinkHistoryListAdapter adapter; + RecyclerView recyclerView; + RecyclerViewAdapter recyclerViewAdapter; + + // RileyLinkHistoryListAdapter adapter; + + LinearLayoutManager llm; + List filteredHistoryList = new ArrayList<>(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.rileylink_status_history, container, false); - adapter = new RileyLinkHistoryListAdapter(); + // adapter = new RileyLinkHistoryListAdapter(); + + recyclerView = (RecyclerView)rootView.findViewById(R.id.rileylink_history_list); + + recyclerView.setHasFixedSize(true); + llm = new LinearLayoutManager(getActivity().getApplicationContext()); + recyclerView.setLayoutManager(llm); + + recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList); + recyclerView.setAdapter(recyclerViewAdapter); return rootView; } @@ -45,9 +60,9 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter public void onStart() { super.onStart(); - this.listView = (ListView)getActivity().findViewById(R.id.rileylink_history_list); + // this.listView = (ListView)getActivity().findViewById(R.id.rileylink_history_list); - listView.setAdapter(adapter); + // listView.setAdapter(adapter); refreshData(); } @@ -55,49 +70,38 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter @Override public void refreshData() { - adapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory()); + recyclerViewAdapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory()); } - static class ViewHolder { + // static class ViewHolder { + // + // TextView itemTime; + // TextView itemSource; + // TextView itemDescription; + // } - TextView itemTime; - TextView itemSource; - TextView itemDescription; - } + public static class RecyclerViewAdapter extends RecyclerView.Adapter { - private class RileyLinkHistoryListAdapter extends BaseAdapter { - - private List historyItemList; - private LayoutInflater mInflator; + List historyList; - public RileyLinkHistoryListAdapter() { - super(); - historyItemList = new ArrayList<>(); - mInflator = RileyLinkStatusHistory.this.getLayoutInflater(); + RecyclerViewAdapter(List historyList) { + this.historyList = historyList; } - public void addItem(RLHistoryItem item) { - if (!historyItemList.contains(item)) { - historyItemList.add(item); - notifyDataSetChanged(); - } - } - - - public RLHistoryItem getHistoryItem(int position) { - return historyItemList.get(position); + public void setHistoryList(List historyList) { + this.historyList = historyList; } public void addItemsAndClean(List items) { - this.historyItemList.clear(); + this.historyList.clear(); for (RLHistoryItem item : items) { - if (!historyItemList.contains(item) && isValidItem(item)) { - historyItemList.add(item); + if (!historyList.contains(item) && isValidItem(item)) { + historyList.add(item); } } @@ -121,52 +125,156 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter } - public void clear() { - historyItemList.clear(); - notifyDataSetChanged(); + @Override + public RecyclerViewAdapter.HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rileylink_status_history_item, // + viewGroup, false); + return new RecyclerViewAdapter.HistoryViewHolder(v); } @Override - public int getCount() { - return historyItemList.size(); - } + public void onBindViewHolder(RecyclerViewAdapter.HistoryViewHolder holder, int position) { + RLHistoryItem item = historyList.get(position); - - @Override - public Object getItem(int i) { - return historyItemList.get(i); - } - - - @Override - public long getItemId(int i) { - return i; - } - - - @Override - public View getView(int i, View view, ViewGroup viewGroup) { - RileyLinkStatusHistory.ViewHolder viewHolder; - // General ListView optimization code. - if (view == null) { - view = mInflator.inflate(R.layout.rileylink_status_history_item, null); - viewHolder = new RileyLinkStatusHistory.ViewHolder(); - viewHolder.itemTime = (TextView)view.findViewById(R.id.rileylink_history_time); - viewHolder.itemSource = (TextView)view.findViewById(R.id.rileylink_history_source); - viewHolder.itemDescription = (TextView)view.findViewById(R.id.rileylink_history_description); - view.setTag(viewHolder); - } else { - viewHolder = (RileyLinkStatusHistory.ViewHolder)view.getTag(); + if (item != null) { + holder.timeView.setText(StringUtil.toDateTimeString(item.getDateTime())); + holder.typeView.setText(item.getSource().getDesc()); + holder.valueView.setText(item.getDescription()); } + } - RLHistoryItem item = historyItemList.get(i); - viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime())); - viewHolder.itemSource.setText(item.getSource().getDesc()); // for now - viewHolder.itemDescription.setText(item.getDescription()); - return view; + @Override + public int getItemCount() { + return historyList.size(); + } + + + @Override + public void onAttachedToRecyclerView(RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + } + + static class HistoryViewHolder extends RecyclerView.ViewHolder { + + TextView timeView; + TextView typeView; + TextView valueView; + + + HistoryViewHolder(View itemView) { + super(itemView); + + timeView = (TextView)itemView.findViewById(R.id.rileylink_history_time); + typeView = (TextView)itemView.findViewById(R.id.rileylink_history_source); + valueView = (TextView)itemView.findViewById(R.id.rileylink_history_description); + } } } + // private class RileyLinkHistoryListAdapter extends BaseAdapter { + // + // private List historyItemList; + // private LayoutInflater mInflator; + // + // + // public RileyLinkHistoryListAdapter() { + // super(); + // historyItemList = new ArrayList<>(); + // mInflator = RileyLinkStatusHistory.this.getLayoutInflater(); + // } + // + // + // public void addItem(RLHistoryItem item) { + // if (!historyItemList.contains(item)) { + // historyItemList.add(item); + // notifyDataSetChanged(); + // } + // } + // + // + // public RLHistoryItem getHistoryItem(int position) { + // return historyItemList.get(position); + // } + // + // + // public void addItemsAndClean(List items) { + // this.historyItemList.clear(); + // + // for (RLHistoryItem item : items) { + // + // if (!historyItemList.contains(item) && isValidItem(item)) { + // historyItemList.add(item); + // } + // } + // + // notifyDataSetChanged(); + // } + // + // + // private boolean isValidItem(RLHistoryItem item) { + // + // PumpDeviceState pumpState = item.getPumpDeviceState(); + // + // if ((pumpState != null) && // + // (pumpState == PumpDeviceState.Sleeping || // + // pumpState == PumpDeviceState.Active || // + // pumpState == PumpDeviceState.WakingUp // + // )) + // return false; + // + // return true; + // + // } + // + // + // public void clear() { + // historyItemList.clear(); + // notifyDataSetChanged(); + // } + // + // + // @Override + // public int getCount() { + // return historyItemList.size(); + // } + // + // + // @Override + // public Object getItem(int i) { + // return historyItemList.get(i); + // } + // + // + // @Override + // public long getItemId(int i) { + // return i; + // } + // + // + // @Override + // public View getView(int i, View view, ViewGroup viewGroup) { + // RileyLinkStatusHistory.ViewHolder viewHolder; + // // General ListView optimization code. + // if (view == null) { + // view = mInflator.inflate(R.layout.rileylink_status_history_item, null); + // viewHolder = new RileyLinkStatusHistory.ViewHolder(); + // viewHolder.itemTime = (TextView)view.findViewById(R.id.rileylink_history_time); + // viewHolder.itemSource = (TextView)view.findViewById(R.id.rileylink_history_source); + // viewHolder.itemDescription = (TextView)view.findViewById(R.id.rileylink_history_description); + // view.setTag(viewHolder); + // } else { + // viewHolder = (RileyLinkStatusHistory.ViewHolder)view.getTag(); + // } + // + // RLHistoryItem item = historyItemList.get(i); + // viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime())); + // viewHolder.itemSource.setText(item.getSource().getDesc()); // for now + // viewHolder.itemDescription.setText(item.getDescription()); + // + // return view; + // } + // } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java index 6df393995d..bc33ab0835 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java @@ -1092,11 +1092,17 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // targetDate = lastPumpHistoryEntry.atechDateTime; } + LOG.debug("HST: Target Date: {}", targetDate); + MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData, lastPumpHistoryEntry, targetDate); + LOG.debug("HST: After task"); + PumpHistoryResult historyResult = (PumpHistoryResult)responseTask2.returnData; + LOG.debug("HST: History Result: {}", historyResult.toString()); + PumpHistoryEntry latestEntry = historyResult.getLatestEntry(); if (isLoggingEnabled()) @@ -1108,6 +1114,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter this.lastPumpHistoryEntry = latestEntry; SP.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime); + LOG.debug("HST: History: valid={}, unprocessed={}", historyResult.validEntries.size(), + historyResult.unprocessedEntries.size()); + this.medtronicHistoryData.addNewHistory(historyResult); this.medtronicHistoryData.filterNewEntries(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java index 439b696fcd..3712d5932a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java @@ -97,7 +97,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte public String getDateTimeString() { - return this.DT; + return this.DT == null ? "Unknown" : this.DT; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index 6ba852ef20..fc31e48a30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import org.joda.time.LocalDateTime; @@ -489,16 +490,25 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { System.out.println("" + totals.toString()); + // FIXME displayable + return RecordDecodeStatus.WIP; } private RecordDecodeStatus decodeBasalProfile(PumpHistoryEntry entry) { - BasalProfile basalProfile = new BasalProfile(entry.getBody()); + // LOG.debug("decodeBasalProfile: {}", entry); + + BasalProfile basalProfile = new BasalProfile(); + basalProfile.setRawDataFromHistory(entry.getBody()); + + // LOG.debug("decodeBasalProfile BasalProfile: {}", basalProfile); entry.addDecodedData("Object", basalProfile); + // FIXME displayable ?? + return RecordDecodeStatus.OK; } @@ -526,14 +536,17 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // writeData(PumpBaseType.Event, PumpEventType.DateTimeChanged, timeChange, entry.getATechDate()); + entry.setDisplayableValue(entry.getDateTimeString()); + this.changeTimeRecord = null; } - // FIXME private void decodeBatteryActivity(PumpHistoryEntry entry) { // this.writeData(PumpBaseType.Event, entry.getHead()[0] == 0 ? PumpEventType.BatteryRemoved : // PumpEventType.BatteryReplaced, entry.getATechDate()); + + entry.setDisplayableValue(entry.getHead()[0] == 0 ? "Battery Removed" : "Battery Replaced"); } @@ -543,12 +556,18 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { (int)entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025f; entry.addDecodedData("Totals", totals); + entry.setDisplayableValue(getFormattedValue(totals, 3)); // this.writeData(PumpBaseType.Report, PumpReport.InsulinTotalDay, getFormattedFloat(totals, 2), // entry.getATechDate()); } + private String getFormattedValue(float value, int decimals) { + return String.format(Locale.ENGLISH, "%." + decimals + "f", value); + } + + // FIXME private RecordDecodeStatus decodeBasalProfileStart(PumpHistoryEntry entry) { byte[] body = entry.getBody(); @@ -570,6 +589,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // writeData(PumpBaseType.Basal, PumpBasalType.ValueChange, getFormattedFloat(rate, 3), // entry.getATechDate()); entry.addDecodedData("Value", getFormattedFloat(rate, 3)); + entry.setDisplayableValue(getFormattedFloat(rate, 3)); return RecordDecodeStatus.OK; } @@ -617,7 +637,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { dto.atechDateTime = entry.atechDateTime; entry.addDecodedData("Object", dto); - // entry.setHistoryEntryDetails(dto); + entry.setDisplayableValue(dto.toString()); // this.writeData(PumpBaseType.Event, PumpEventType.BolusWizard, dto.getValue(), entry.getATechDate()); @@ -626,9 +646,15 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // FIXME private void decodeLowReservoir(PumpHistoryEntry entry) { - float amount = (getUnsignedInt(entry.getHead()[0]) * 1.0f / 10.0f); + float amount = (getUnsignedInt(entry.getHead()[0]) * 1.0f / 10.0f) * 2; + + // LOG.debug("LowReservoir: rawData={}", entry.getRawData()); + + // LOG.debug("LowReservoir: {}, object={}", entry.getHead()[0], entry); // this.writeData(PumpBaseType.Event, PumpEventType.ReservoirLowDesc, getFormattedFloat(amount, 1), // entry.getATechDate()); + entry.setDisplayableValue(getFormattedValue(amount, 1)); + } @@ -640,6 +666,9 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { entry.addDecodedData("Amount", amount); entry.addDecodedData("FixedAmount", fixed); + entry.setDisplayableValue("Amount=" + getFormattedValue(amount, 2) + ", Fixed Amount=" + + getFormattedValue(fixed, 2)); + // amount = (double) (asUINT8(data[4]) << 2) / 40.0; // programmedAmount = (double) (asUINT8(data[2]) << 2) / 40.0; // primeType = programmedAmount == 0 ? "manual" : "fixed"; @@ -700,6 +729,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { } entry.addDecodedData("Object", bolus); + entry.setDisplayableValue(bolus.getDisplayableValue()); bolusHistory.put(dateTime, bolus); @@ -745,12 +775,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // ); entry.addDecodedData("Object", tbr); + entry.setDisplayableValue(tbr.getDescription()); - entry.addDecodedData("Rate 1: ", tbrRate.getHead()[0] * 0.025); - entry.addDecodedData("Rate 2: ", ByteUtil.asUINT8(tbrRate.getHead()[0]) * 0.025d); - entry.addDecodedData("Rate 1.b: ", tbrRate.getHead()[0]); - entry.addDecodedData("Rate 2.b: ", ByteUtil.asUINT8(tbrRate.getHead()[0])); - entry.addDecodedData("Rate 3: ", (ByteUtil.asUINT8(tbrRate.getHead()[0])) / 40.0d); + // entry.addDecodedData("Rate 1: ", tbrRate.getHead()[0] * 0.025); + // entry.addDecodedData("Rate 2: ", ByteUtil.asUINT8(tbrRate.getHead()[0]) * 0.025d); + // entry.addDecodedData("Rate 1.b: ", tbrRate.getHead()[0]); + // entry.addDecodedData("Rate 2.b: ", ByteUtil.asUINT8(tbrRate.getHead()[0])); + // entry.addDecodedData("Rate 3: ", (ByteUtil.asUINT8(tbrRate.getHead()[0])) / 40.0d); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntry.java index bd966fda2b..f2a319ecce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntry.java @@ -131,19 +131,30 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry { // } public boolean isAfter(long atechDateTime) { - return atechDateTime > this.atechDateTime; + return atechDateTime < this.atechDateTime; } - public static class Comparator implements java.util.Comparator { - @Override - public int compare(PumpHistoryEntry o1, PumpHistoryEntry o2) { - return (int)(o2.atechDateTime - o1.atechDateTime); - } + public void setDisplayableValue(String displayableValue) { + this.displayableValue = displayableValue; } public String getDisplayableValue() { return displayableValue; } + + public static class Comparator implements java.util.Comparator { + + @Override + public int compare(PumpHistoryEntry o1, PumpHistoryEntry o2) { + int data = (int)(o2.atechDateTime - o1.atechDateTime); + + if (data != 0) + return data; + + return o2.getEntryType().getCode() - o1.getEntryType().getCode(); + } + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryGroup.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryGroup.java index 1d980144df..4fe98a4e01 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryGroup.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryGroup.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; /** @@ -26,12 +27,17 @@ public enum PumpHistoryEntryGroup { private int resourceId; private String translated; + public static boolean doNotTranslate = false; + private static List list; static { list = new ArrayList<>(); for (PumpHistoryEntryGroup pumpHistoryEntryGroup : values()) { + if (doNotTranslate) { + pumpHistoryEntryGroup.translated = MainApp.gs(pumpHistoryEntryGroup.resourceId); + } list.add(pumpHistoryEntryGroup); } } @@ -53,6 +59,11 @@ public enum PumpHistoryEntryGroup { } + public String getTranslated() { + return translated; + } + + public String toString() { return this.translated; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java index 88f397e281..bf9de101aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java @@ -42,123 +42,127 @@ public enum PumpHistoryEntryType // implements CodeEnum Prime(0x03, "Prime", PumpHistoryEntryGroup.Prime, 5, 5, 0), // - /**/EventUnknown_MM522_0x05((byte)0x05, PumpHistoryEntryGroup.Unknown, 2, 5, 28), // - NoDeliveryAlarm(0x06, "NoDelivery", PumpHistoryEntryGroup.Alarm, 4, 5, 0), // - EndResultTotals(0x07, "ResultTotals", PumpHistoryEntryGroup.Statistic, 5, 2, 0), // V1: 5/5/41 V2: 5,2,3 V3, 5,2,0 - // V5: 7/10(523) - ChangeBasalProfile_OldProfile(0x08, PumpHistoryEntryGroup.Basal, 2, 5, 145), // // V1: 2,5,42 V2:2,5,145; V4: V5 - ChangeBasalProfile_NewProfile(0x09, PumpHistoryEntryGroup.Basal, 2, 5, 145), // - /**/EventUnknown_MM512_0x10(0x10, PumpHistoryEntryGroup.Unknown), // 29, 5, 0 + /**/EventUnknown_MM522_0x05((byte)0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), // + NoDeliveryAlarm(0x06, "No Delivery", PumpHistoryEntryGroup.Alarm, 4, 5, 0), // + EndResultTotals(0x07, "End Result Totals", PumpHistoryEntryGroup.Statistic, 5, 2, 0), // V1: 5/5/41 V2: 5,2,3 V3, + // 5,2,0 + // V1: 2,5,42; V2:2,5,145; V5: 7/10(523) + ChangeBasalProfile_OldProfile(0x08, "Change Basal Profile (Old)", PumpHistoryEntryGroup.Basal, 2, 5, 145), + ChangeBasalProfile_NewProfile(0x09, "Change Basal Profile (New)", PumpHistoryEntryGroup.Basal, 2, 5, 145), // + /**/EventUnknown_MM512_0x10(0x10, "Unknown Event 0x10", PumpHistoryEntryGroup.Unknown), // 29, 5, 0 CalBGForPH(0x0a, "BG Capture", PumpHistoryEntryGroup.Glucose), // - SensorAlert(0x0b, "SensorAlert", PumpHistoryEntryGroup.Alarm, 3, 5, 0), // Ian08 - ClearAlarm(0x0c, "ClearAlarm", PumpHistoryEntryGroup.Alarm, 2, 5, 0), // 2,5,4 + SensorAlert(0x0b, "Sensor Alert", PumpHistoryEntryGroup.Alarm, 3, 5, 0), // Ian08 + ClearAlarm(0x0c, "Clear Alarm", PumpHistoryEntryGroup.Alarm, 2, 5, 0), // 2,5,4 // Andy0d(0x0d, "Unknown", 2, 5, 0), ChangeBasalPattern(0x14, "Change Basal Pattern", PumpHistoryEntryGroup.Basal), // - TempBasalDuration(0x16, "TempBasalDuration", PumpHistoryEntryGroup.Basal), // - ChangeTime(0x17, "ChangeTime", PumpHistoryEntryGroup.Configuration), // - NewTimeSet(0x18, "NewTimeSet", PumpHistoryEntryGroup.Notification), // + TempBasalDuration(0x16, "TBR Duration", PumpHistoryEntryGroup.Basal), // + ChangeTime(0x17, "Change Time", PumpHistoryEntryGroup.Configuration), // + NewTimeSet(0x18, "New Time Set", PumpHistoryEntryGroup.Notification), // LowBattery(0x19, "LowBattery", PumpHistoryEntryGroup.Notification), // BatteryChange(0x1a, "Battery Change", PumpHistoryEntryGroup.Notification), // - SetAutoOff(0x1b, "SetAutoOff", PumpHistoryEntryGroup.Configuration), // + SetAutoOff(0x1b, "Set Auto Off", PumpHistoryEntryGroup.Configuration), // PumpSuspend(0x1e, "Pump Suspend", PumpHistoryEntryGroup.Basal), // PumpResume(0x1f, "Pump Resume", PumpHistoryEntryGroup.Basal), // - SelfTest(0x20, "SelfTest", PumpHistoryEntryGroup.Statistic), // + SelfTest(0x20, "Self Test", PumpHistoryEntryGroup.Statistic), // Rewind(0x21, "Rewind", PumpHistoryEntryGroup.Prime), // - ClearSettings(0x22, "ClearSettings", PumpHistoryEntryGroup.Configuration), // 8? - ChangeChildBlockEnable(0x23, "ChangeChildBlockEnable", PumpHistoryEntryGroup.Configuration), // 8? - ChangeMaxBolus(0x24, PumpHistoryEntryGroup.Configuration), // 8? - /**/EventUnknown_MM522_0x25(0x25, PumpHistoryEntryGroup.Unknown), // 8? - ToggleRemote(0x26, "EnableDisableRemote", PumpHistoryEntryGroup.Configuration, 2, 5, 14), // 2, 5, 14 V6:2,5,14 - ChangeRemoteId(0x27, "ChangeRemoteID", PumpHistoryEntryGroup.Configuration), // ?? + ClearSettings(0x22, "Clear Settings", PumpHistoryEntryGroup.Configuration), // 8? + ChangeChildBlockEnable(0x23, "Change Child Block Enable", PumpHistoryEntryGroup.Configuration), // 8? + ChangeMaxBolus(0x24, "Change Max Bolus", PumpHistoryEntryGroup.Configuration), // 8? + /**/EventUnknown_MM522_0x25(0x25, "Unknown Event 0x25", PumpHistoryEntryGroup.Unknown), // 8? + ToggleRemote(0x26, "Enable/Disable Remote", PumpHistoryEntryGroup.Configuration, 2, 5, 14), // 2, 5, 14 V6:2,5,14 + ChangeRemoteId(0x27, "Change Remote ID", PumpHistoryEntryGroup.Configuration), // ?? - ChangeMaxBasal(0x2c, PumpHistoryEntryGroup.Configuration), // - BolusWizardEnabled(0x2d, PumpHistoryEntryGroup.Configuration), // V3 ? - /**/EventUnknown_MM512_0x2e(0x2e, PumpHistoryEntryGroup.Unknown), // - /**/BolusWizard512(0x2f, PumpHistoryEntryGroup.Configuration), // - UnabsorbedInsulin512(0x30, PumpHistoryEntryGroup.Statistic), // - ChangeBGReminderOffset(0x31, PumpHistoryEntryGroup.Configuration), // - ChangeAlarmClockTime(0x32, PumpHistoryEntryGroup.Configuration), // - TempBasalRate(0x33, "Temp Basal Rate", PumpHistoryEntryGroup.Basal, 2, 5, 1), // - LowReservoir(0x34, PumpHistoryEntryGroup.Notification), // + ChangeMaxBasal(0x2c, "Change Max Basal", PumpHistoryEntryGroup.Configuration), // + BolusWizardEnabled(0x2d, "Bolus Wizard Enabled", PumpHistoryEntryGroup.Configuration), // V3 ? + /**/EventUnknown_MM512_0x2e(0x2e, "Unknown Event 0x2e", PumpHistoryEntryGroup.Unknown), // + /**/BolusWizard512(0x2f, "Bolus Wizard (512)", PumpHistoryEntryGroup.Configuration), // + UnabsorbedInsulin512(0x30, "Unabsorbed Insulin (512)", PumpHistoryEntryGroup.Statistic), // + ChangeBGReminderOffset(0x31, "Change BG Reminder Offset", PumpHistoryEntryGroup.Configuration), // + ChangeAlarmClockTime(0x32, "Change Alarm Clock Time", PumpHistoryEntryGroup.Configuration), // + TempBasalRate(0x33, "TBR Rate", PumpHistoryEntryGroup.Basal, 2, 5, 1), // + LowReservoir(0x34, "Low Reservoir", PumpHistoryEntryGroup.Notification), // ChangeAlarmClock(0x35, "Change Alarm Clock", PumpHistoryEntryGroup.Configuration), // - ChangeMeterId(0x36, PumpHistoryEntryGroup.Configuration), // - /**/EventUnknown_MM512_0x37(0x37, PumpHistoryEntryGroup.Unknown), // V:MM512 - /**/EventUnknown_MM512_0x38(0x38, PumpHistoryEntryGroup.Unknown), // - BGReceived512(0x39, PumpHistoryEntryGroup.Glucose), // - SensorStatus(0x3b, PumpHistoryEntryGroup.Glucose), // - ChangeParadigmID(0x3c, PumpHistoryEntryGroup.Configuration, 2, 5, 14), // V3 ? V6: 2,5,14 + ChangeMeterId(0x36, "Change Meter ID", PumpHistoryEntryGroup.Configuration), // + /**/EventUnknown_MM512_0x37(0x37, "Unknown Event 0x37", PumpHistoryEntryGroup.Unknown), // V:MM512 + /**/EventUnknown_MM512_0x38(0x38, "Unknown Event 0x38", PumpHistoryEntryGroup.Unknown), // + BGReceived512(0x39, "BG Received (512)", PumpHistoryEntryGroup.Glucose), // + SensorStatus(0x3b, "Sensor Status", PumpHistoryEntryGroup.Glucose), // + ChangeParadigmID(0x3c, "Change Paradigm ID", PumpHistoryEntryGroup.Configuration, 2, 5, 14), // V3 ? V6: 2,5,14 BGReceived(0x3f, "BG Received", PumpHistoryEntryGroup.Glucose, 2, 5, 3), // Ian3F - JournalEntryMealMarker(0x40, PumpHistoryEntryGroup.Bolus, 2, 5, 2), // - JournalEntryExerciseMarker(0x41, PumpHistoryEntryGroup.Bolus, 2, 5, 1), // ?? JournalEntryExerciseMarkerPumpEvent - JournalEntryInsulinMarker(0x42, PumpHistoryEntryGroup.Bolus, 2, 5, 1), // ?? InsulinMarkerEvent - JournalEntryOtherMarker(0x43, PumpHistoryEntryGroup.Bolus), // - EnableSensorAutoCal(0x44, PumpHistoryEntryGroup.Glucose), // - /**/EventUnknown_MM522_0x45(0x45, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x46(0x46, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x47(0x47, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x48(0x48, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x49(0x49, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x4a(0x4a, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x4b(0x4b, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_MM522_0x4c(0x4c, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - /**/EventUnknown_0x4d(0x4d, PumpHistoryEntryGroup.Unknown), // V5: 512: 7, 522: 8 ????NS - /**/EventUnknown_MM512_0x4e(0x4e, PumpHistoryEntryGroup.Unknown), // /**/ - ChangeBolusWizardSetup(0x4f, PumpHistoryEntryGroup.Configuration, 2, 5, 32), // - ChangeSensorSetup2(0x50, PumpHistoryEntryGroup.Configuration, 2, 5, 30), // Ian50 - /**/Sensor51(0x51, PumpHistoryEntryGroup.Unknown), // - /**/Sensor52(0x52, PumpHistoryEntryGroup.Unknown), // - ChangeSensorAlarmSilenceConfig(0x53, PumpHistoryEntryGroup.Configuration, 2, 5, 1), // 8 - - // ChangeSensorAlarmSilenceConfig - /**/Sensor54(0x54, PumpHistoryEntryGroup.Unknown), // Ian54 - /**/Sensor55(0x55, PumpHistoryEntryGroup.Unknown), // - ChangeSensorRateOfChangeAlertSetup(0x56, PumpHistoryEntryGroup.Configuration, 2, 5, 5), // 12 - // ChangeSensorRateOfChangeAlertSetup - ChangeBolusScrollStepSize(0x57, PumpHistoryEntryGroup.Configuration), // + JournalEntryMealMarker(0x40, "Meal Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 2), // + JournalEntryExerciseMarker(0x41, "Exercise Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 1), // ?? + // JournalEntryExerciseMarkerPumpEvent + JournalEntryInsulinMarker(0x42, "Insulin Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 1), // ?? InsulinMarkerEvent + JournalEntryOtherMarker(0x43, "Other Marker", PumpHistoryEntryGroup.Bolus), // + EnableSensorAutoCal(0x44, "Enable Sensor AutoCal", PumpHistoryEntryGroup.Glucose), // + /**/EventUnknown_MM522_0x45(0x45, "Unknown Event 0x45", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x46(0x46, "Unknown Event 0x46", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x47(0x47, "Unknown Event 0x47", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x48(0x48, "Unknown Event 0x48", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x49(0x49, "Unknown Event 0x49", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x4a(0x4a, "Unknown Event 0x4a", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x4b(0x4b, "Unknown Event 0x4b", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_MM522_0x4c(0x4c, "Unknown Event 0x4c", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + /**/EventUnknown_0x4d(0x4d, "Unknown Event 0x4d", PumpHistoryEntryGroup.Unknown), // V5: 512: 7, 522: 8 ????NS + /**/EventUnknown_MM512_0x4e(0x4e, "Unknown Event 0x4e", PumpHistoryEntryGroup.Unknown), // /**/ + ChangeBolusWizardSetup(0x4f, "Bolus Wizard Setup", PumpHistoryEntryGroup.Configuration, 2, 5, 32), // + ChangeSensorSetup2(0x50, "Sensor Setup2", PumpHistoryEntryGroup.Configuration, 2, 5, 30), // Ian50 + /**/Sensor51(0x51, "Unknown Event 0x51", PumpHistoryEntryGroup.Unknown), // + /**/Sensor52(0x52, "Unknown Event 0x52", PumpHistoryEntryGroup.Unknown), // + ChangeSensorAlarmSilenceConfig(0x53, "Sensor Alarm Silence Config", PumpHistoryEntryGroup.Configuration, 2, 5, 1), // 8 + // - + // ChangeSensorAlarmSilenceConfig + /**/Sensor54(0x54, "Unknown Event 0x54", PumpHistoryEntryGroup.Unknown), // Ian54 + /**/Sensor55(0x55, "Unknown Event 0x55", PumpHistoryEntryGroup.Unknown), // + ChangeSensorRateOfChangeAlertSetup(0x56, "Sensor Rate Of Change Alert Setup", PumpHistoryEntryGroup.Configuration, 2, 5, 5), // 12 + // ChangeSensorRateOfChangeAlertSetup + ChangeBolusScrollStepSize(0x57, "Change Bolus Scroll Step Size", PumpHistoryEntryGroup.Configuration), // // V4 // Andy58(0x58, "Unknown", 13, 5, 0), // TO DO is this one really there ??? - BolusWizardChange(0x5a, "BolusWizard", PumpHistoryEntryGroup.Configuration, 2, 5, 117), // V2: 522+[B=143] - BolusWizardBolusEstimate(0x5b, "BolusWizardBolusEstimate", PumpHistoryEntryGroup.Configuration, 2, 5, 13), // 15 // - UnabsorbedInsulin(0x5c, "UnabsorbedInsulinBolus", PumpHistoryEntryGroup.Statistic, 5, 0, 0), // head[1] -> body - // length - SaveSettings(0x5d, PumpHistoryEntryGroup.Configuration), // - ChangeVariableBolus(0x5e, PumpHistoryEntryGroup.Configuration), // - ChangeAudioBolus(0x5f, "EasyBolusEnabled", PumpHistoryEntryGroup.Configuration), // V3 ? - ChangeBGReminderEnable(0x60, PumpHistoryEntryGroup.Configuration), // questionable60 - ChangeAlarmClockEnable(0x61, PumpHistoryEntryGroup.Configuration), // - ChangeTempBasalType((byte)0x62, PumpHistoryEntryGroup.Configuration), // ChangeTempBasalTypePumpEvent - ChangeAlarmNotifyMode(0x63, PumpHistoryEntryGroup.Configuration), // - ChangeTimeFormat(0x64, PumpHistoryEntryGroup.Configuration), // - ChangeReservoirWarningTime((byte)0x65, PumpHistoryEntryGroup.Configuration), // - ChangeBolusReminderEnable(0x66, PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 - ChangeBolusReminderTime((byte)0x67, PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 - DeleteBolusReminderTime((byte)0x68, PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 - BolusReminder(0x69, PumpHistoryEntryGroup.Configuration, 2, 5, 0), // Ian69 + BolusWizardChange(0x5a, "Bolus Wizard Change", PumpHistoryEntryGroup.Configuration, 2, 5, 117), // V2: 522+[B=143] + BolusWizardBolusEstimate(0x5b, "Bolus Wizard Estimate", PumpHistoryEntryGroup.Configuration, 2, 5, 13), // 15 // + UnabsorbedInsulin(0x5c, "Unabsorbed Insulin", PumpHistoryEntryGroup.Statistic, 5, 0, 0), // head[1] -> body + // length + SaveSettings(0x5d, "Save Settings", PumpHistoryEntryGroup.Configuration), // + ChangeVariableBolus(0x5e, "Change Variable Bolus", PumpHistoryEntryGroup.Configuration), // + ChangeAudioBolus(0x5f, "Easy Bolus Enabled", PumpHistoryEntryGroup.Configuration), // V3 ? + ChangeBGReminderEnable(0x60, "BG Reminder Enable", PumpHistoryEntryGroup.Configuration), // questionable60 + ChangeAlarmClockEnable(0x61, "Alarm Clock Enable", PumpHistoryEntryGroup.Configuration), // + ChangeTempBasalType((byte)0x62, "Change Basal Type", PumpHistoryEntryGroup.Configuration), // ChangeTempBasalTypePumpEvent + ChangeAlarmNotifyMode(0x63, "Change Alarm Notify Mode", PumpHistoryEntryGroup.Configuration), // + ChangeTimeFormat(0x64, "Change Time Format", PumpHistoryEntryGroup.Configuration), // + ChangeReservoirWarningTime((byte)0x65, "Change Reservoir Warning Time", PumpHistoryEntryGroup.Configuration), // + ChangeBolusReminderEnable(0x66, "Change Bolus Reminder Enable", PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 + ChangeBolusReminderTime((byte)0x67, "Change Bolus Reminder Time", PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 + DeleteBolusReminderTime((byte)0x68, "Delete Bolus Reminder Time", PumpHistoryEntryGroup.Configuration, 2, 5, 2), // 9 + BolusReminder(0x69, "Bolus Reminder", PumpHistoryEntryGroup.Configuration, 2, 5, 0), // Ian69 DeleteAlarmClockTime(0x6a, "Delete Alarm Clock Time", PumpHistoryEntryGroup.Configuration, 2, 5, 7), // 14 - DailyTotals515(0x6c, "Daily Totals 515", PumpHistoryEntryGroup.Statistic, 0, 0, 36), // - DailyTotals522(0x6d, "Daily Totals 522", PumpHistoryEntryGroup.Statistic, 1, 2, 41), // // hack1(0x6d, "hack1", 46, - // 5, 0), // 1,2,41 - DailyTotals523(0x6e, "Daily Totals 523", PumpHistoryEntryGroup.Statistic, 1, 2, 49), // 1102014-03-17T00:00:00 - ChangeCarbUnits((byte)0x6f, PumpHistoryEntryGroup.Configuration), // - /**/EventUnknown_MM522_0x70((byte)0x70, PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + DailyTotals515(0x6c, "Daily Totals (515)", PumpHistoryEntryGroup.Statistic, 0, 0, 36), // + DailyTotals522(0x6d, "Daily Totals (522)", PumpHistoryEntryGroup.Statistic, 1, 2, 41), // // hack1(0x6d, "hack1", + // 46, + // 5, 0), // 1,2,41 + DailyTotals523(0x6e, "Daily Totals (523)", PumpHistoryEntryGroup.Statistic, 1, 2, 49), // 1102014-03-17T00:00:00 + ChangeCarbUnits((byte)0x6f, "Change Carb Units", PumpHistoryEntryGroup.Configuration), // + /**/EventUnknown_MM522_0x70((byte)0x70, "Unknown Event 0x70", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // - BasalProfileStart(0x7b, PumpHistoryEntryGroup.Basal, 2, 5, 3), // // 722 - ChangeWatchdogEnable((byte)0x7c, PumpHistoryEntryGroup.Configuration), // - ChangeOtherDeviceID((byte)0x7d, PumpHistoryEntryGroup.Configuration, 2, 5, 30), // + BasalProfileStart(0x7b, "Basal Profile Start", PumpHistoryEntryGroup.Basal, 2, 5, 3), // // 722 + ChangeWatchdogEnable((byte)0x7c, "Change Watchdog Enable", PumpHistoryEntryGroup.Configuration), // + ChangeOtherDeviceID((byte)0x7d, "Change Other Device ID", PumpHistoryEntryGroup.Configuration, 2, 5, 30), // - ChangeWatchdogMarriageProfile(0x81, PumpHistoryEntryGroup.Configuration, 2, 5, 5), // 12 - DeleteOtherDeviceID(0x82, PumpHistoryEntryGroup.Configuration, 2, 5, 5), // - ChangeCaptureEventEnable(0x83, PumpHistoryEntryGroup.Configuration), // + ChangeWatchdogMarriageProfile(0x81, "Change Watchdog Marriage Profile", PumpHistoryEntryGroup.Configuration, 2, 5, 5), // 12 + DeleteOtherDeviceID(0x82, "Delete Other Device ID", PumpHistoryEntryGroup.Configuration, 2, 5, 5), // + ChangeCaptureEventEnable(0x83, "Change Capture Event Enable", PumpHistoryEntryGroup.Configuration), // - /**/EventUnknown_MM512_0x88(0x88, PumpHistoryEntryGroup.Unknown), // + /**/EventUnknown_MM512_0x88(0x88, "Unknown Event 0x88", PumpHistoryEntryGroup.Unknown), // - /**/EventUnknown_MM512_0x94(0x94, PumpHistoryEntryGroup.Unknown), // + /**/EventUnknown_MM512_0x94(0x94, "Unknown Event 0x94", PumpHistoryEntryGroup.Unknown), // // IanA8(0xA8, "xx", 10, 5, 0), // // Andy90(0x90, "Unknown", 7, 5, 0), @@ -169,14 +173,14 @@ public enum PumpHistoryEntryType // implements CodeEnum // head[1], // body[49] op[0x6e] - /**/EventUnknown_MM522_0xE8(0xe8, PumpHistoryEntryGroup.Unknown, 2, 5, 25), // + /**/EventUnknown_MM522_0xE8(0xe8, "Unknown Event 0xE8", PumpHistoryEntryGroup.Unknown, 2, 5, 25), // - ReadOtherDevicesIDs(0xf0, "", PumpHistoryEntryGroup.Configuration), // ? - ReadCaptureEventEnabled(0xf1, PumpHistoryEntryGroup.Configuration), // ? - ChangeCaptureEventEnable2(0xf2, PumpHistoryEntryGroup.Configuration), // ? - ReadOtherDevicesStatus(0xf3, PumpHistoryEntryGroup.Configuration), // ? + ReadOtherDevicesIDs(0xf0, "Read Other Devices IDs", PumpHistoryEntryGroup.Configuration), // ? + ReadCaptureEventEnabled(0xf1, "Read Capture Event Enabled", PumpHistoryEntryGroup.Configuration), // ? + ChangeCaptureEventEnable2(0xf2, "Change Capture Event Enable2", PumpHistoryEntryGroup.Configuration), // ? + ReadOtherDevicesStatus(0xf3, "Read Other Devices Status", PumpHistoryEntryGroup.Configuration), // ? - TempBasalCombined(0xfe, "TempBasalCombined", PumpHistoryEntryGroup.Basal), // + TempBasalCombined(0xfe, "TBR", PumpHistoryEntryGroup.Basal), // UnknownBasePacket(0xff, "Unknown Base Packet", PumpHistoryEntryGroup.Unknown); private static Map opCodeMap = new HashMap(); @@ -204,51 +208,21 @@ public enum PumpHistoryEntryType // implements CodeEnum private PumpHistoryEntryGroup group = PumpHistoryEntryGroup.Unknown; - // @Deprecated - // PumpHistoryEntryType(int opCode, String name) { - // this(opCode, name, 2, 5, 0); - // } - PumpHistoryEntryType(int opCode, String name, PumpHistoryEntryGroup group) { this(opCode, name, group, 2, 5, 0); } - // @Deprecated - // PumpHistoryEntryType(int opCode) { - // this(opCode, null, null, 2, 5, 0); - // } - PumpHistoryEntryType(int opCode, PumpHistoryEntryGroup group) { this(opCode, null, group, 2, 5, 0); } - // @Deprecated - // PumpHistoryEntryType(int opCode, int head, int date, int body) { - // this(opCode, null, null, head, date, body); - // } - PumpHistoryEntryType(int opCode, PumpHistoryEntryGroup group, int head, int date, int body) { this(opCode, null, group, head, date, body); } - // @Deprecated - // PumpHistoryEntryType(int opCode, String name, int head, DateFormat dateFormat, int body) { - // this(opCode, name, head, dateFormat.getLength(), body); - // } - - // @Deprecated - // PumpHistoryEntryType(int opCode, String name, int head, int date, int body) { - // this.opCode = (byte)opCode; - // this.description = name; - // this.headLength = head; - // this.dateLength = date; - // this.bodyLength = body; - // this.totalLength = (head + date + body); - // } - PumpHistoryEntryType(int opCode, String name, PumpHistoryEntryGroup group, int head, int date, int body) { this.opCode = (byte)opCode; this.description = name; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java index cabb588f0e..409c45eec3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java @@ -25,7 +25,7 @@ public class PumpHistoryResult { private PumpHistoryEntry searchEntry = null; private Long searchDate = null; private SearchType searchType = SearchType.None; - private List unprocessedEntries; + public List unprocessedEntries; public List validEntries; @@ -60,32 +60,41 @@ public class PumpHistoryResult { switch (searchType) { case None: + LOG.debug("PE. None search"); + // clearOrPrepareList(); this.validEntries.addAll(this.unprocessedEntries); - // this.unprocessedEntries = null; + // this.unprocessedEntries + // = null; break; case LastEntry: { - if (this.validEntries == null) - this.validEntries = new ArrayList<>(); + LOG.debug("PE. Last entry search"); + + // clearOrPrepareList(); Collections.sort(this.unprocessedEntries, new PumpHistoryEntry.Comparator()); - LOG.debug("PumpHistoryResult. Search entry date: " + searchEntry.atechDateTime); + LOG.debug("PE. PumpHistoryResult. Search entry date: " + searchEntry.atechDateTime); + + Long date = searchEntry.atechDateTime; for (PumpHistoryEntry unprocessedEntry : unprocessedEntries) { if (unprocessedEntry.equals(searchEntry)) { + LOG.debug("PE. Item found {}.", unprocessedEntry); searchFinished = true; break; } + LOG.debug("PE. Entry {} added.", unprocessedEntry); this.validEntries.add(unprocessedEntry); } } break; case Date: { - if (this.validEntries == null) - this.validEntries = new ArrayList<>(); + LOG.debug("PE. Date search"); + + // clearOrPrepareList(); for (PumpHistoryEntry unprocessedEntry : unprocessedEntries) { if (unprocessedEntry.isAfter(this.searchDate)) { @@ -106,6 +115,27 @@ public class PumpHistoryResult { } // switch + LOG.debug("PE. Valid Entries: {}", validEntries); + } + + + private void clearOrPrepareList() { + if (this.validEntries == null) + this.validEntries = new ArrayList<>(); + else + this.validEntries.clear(); + } + + + public String toString() { + return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size() + // + ", valid=" + validEntries.size() + // + ", searchEntry=" + searchEntry + // + ", searchDate=" + searchDate + // + ", searchType=" + searchType + // + ", searchFinished=" + searchFinished + // + "]"; + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java index 192cd4227a..34a6f3292f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java @@ -54,6 +54,7 @@ public class MedtronicHistoryData { * @param result PumpHistoryResult instance */ public void addNewHistory(PumpHistoryResult result) { + this.newHistory = result.getValidEntries(); showLogs("List of history (before filtering): ", MedtronicPumpPlugin.gsonInstance.toJson(this.newHistory)); @@ -86,24 +87,28 @@ public class MedtronicHistoryData { for (PumpHistoryEntry pumpHistoryEntry : newHistory) { - PumpHistoryEntryType type = pumpHistoryEntry.getEntryType(); + if (!this.allHistory.contains(pumpHistoryEntry)) { - // if (PumpHistoryEntryType.isAAPSRelevantEntry(type)) { + PumpHistoryEntryType type = pumpHistoryEntry.getEntryType(); - if (type == PumpHistoryEntryType.TempBasalRate || type == PumpHistoryEntryType.TempBasalDuration) { - TBRs.add(pumpHistoryEntry); - } else { + // if (PumpHistoryEntryType.isAAPSRelevantEntry(type)) { - if (type == PumpHistoryEntryType.EndResultTotals) { - if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime)) { + if (type == PumpHistoryEntryType.TempBasalRate || type == PumpHistoryEntryType.TempBasalDuration) { + TBRs.add(pumpHistoryEntry); + } else { + + if (type == PumpHistoryEntryType.EndResultTotals) { + if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime)) { + newHistory2.add(pumpHistoryEntry); + } + } else { newHistory2.add(pumpHistoryEntry); } - } else { - newHistory2.add(pumpHistoryEntry); - } + } + // } } - // } + } TBRs = processTBRs(TBRs); @@ -130,7 +135,7 @@ public class MedtronicHistoryData { if (filteredListByLastRecord.size() == 0) return; - List outList = new ArrayList<>(); + // List outList = new ArrayList<>(); // if (allHistory.size() > OLD_HISTORY_SIZE) { // for (int i = 0; i < OLD_HISTORY_SIZE; i++) { @@ -144,14 +149,21 @@ public class MedtronicHistoryData { LOG.debug("All History records (before): " + allHistory.size()); - outList.addAll(this.allHistory); - outList.addAll(filteredListByLastRecord); + for (PumpHistoryEntry pumpHistoryEntry : filteredListByLastRecord) { - this.allHistory.clear(); + if (!this.allHistory.contains(pumpHistoryEntry)) { + this.allHistory.add(pumpHistoryEntry); + } + } - this.allHistory.addAll(outList); - - this.sort(this.allHistory); + // outList.addAll(this.allHistory); + // outList.addAll(filteredListByLastRecord); + // + // this.allHistory.clear(); + // + // this.allHistory.addAll(outList); + // + // this.sort(this.allHistory); LOG.debug("All History records (after): " + allHistory.size()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfile.java index 5ccffbf035..49c9c73f1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfile.java @@ -87,6 +87,32 @@ public class BasalProfile { } + public boolean setRawDataFromHistory(byte[] data) { + if (data == null) { + LOG.error("setRawData: buffer is null!"); + return false; + } + + mRawData = new byte[MAX_RAW_DATA_SIZE]; + int item = 0; + + for (int i = 0; i < data.length - 2; i += 3) { + + if ((data[i] == 0) && (data[i + 1] == 0) && (data[i + 2] == 0)) { + mRawData[i] = 0; + mRawData[i + 1] = 0; + mRawData[i + 2] = 0; + } + + mRawData[i] = data[i + 1]; + mRawData[i + 1] = data[i + 2]; + mRawData[i + 2] = data[i]; + } + + return true; + } + + public void dumpBasalProfile() { LOG.debug("Basal Profile entries:"); List entries = getEntries(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BolusDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BolusDTO.java index 1ca8bafbff..dae31ee455 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BolusDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BolusDTO.java @@ -120,6 +120,17 @@ public class BolusDTO extends PumpTimeStampedRecord { } + public String getDisplayableValue() { + String value = getValue(); + + value = value.replace("AMOUNT_SQUARE=", "Amount Square: "); + value = value.replace("AMOUNT=", "Amount: "); + value = value.replace("DURATION=", "Duration: "); + + return value; + } + + public Float getImmediateAmount() { return immediateAmount; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/TempBasalPair.java index 519944f44d..fb08a9dddb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/TempBasalPair.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/TempBasalPair.java @@ -146,9 +146,9 @@ public class TempBasalPair { public String getDescription() { if (isPercent) { - return String.format(Locale.ENGLISH, "Rate=%.0f%%, Duration=%d min", insulinRate, durationMinutes); + return String.format(Locale.ENGLISH, "Rate: %.0f%%, Duration: %d min", insulinRate, durationMinutes); } else { - return String.format(Locale.ENGLISH, "Rate=%.3f U, Duration=%d min", insulinRate, durationMinutes); + return String.format(Locale.ENGLISH, "Rate: %.3f U, Duration: %d min", insulinRate, durationMinutes); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/dialog/MedtronicHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/dialog/MedtronicHistoryActivity.java index 44ce8c375b..1711ca211e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/dialog/MedtronicHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/dialog/MedtronicHistoryActivity.java @@ -10,7 +10,7 @@ import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; -import android.support.v7.widget.CardView; +import android.os.SystemClock; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -23,11 +23,7 @@ import android.widget.TextView; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHistoryEntry; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHistoryEntryGroup; @@ -38,44 +34,28 @@ public class MedtronicHistoryActivity extends Activity { private Handler mHandler; - static Profile profile = null; + // static Profile profile = null; Spinner historyTypeSpinner; TextView statusView; - // Button reloadButton; - // Button syncButton; RecyclerView recyclerView; LinearLayoutManager llm; - static PumpHistoryEntryGroup showingType = PumpHistoryEntryGroup.All; - // List fullHistoryList = null; + static TypeList showingType = null; + static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All; List filteredHistoryList = new ArrayList<>(); + RecyclerViewAdapter recyclerViewAdapter; + boolean manualChange = false; + + List typeListFull; - // public static class TypeList { - // - // public byte type; - // String name; - // - // - // TypeList(byte type, String name) { - // this.type = type; - // this.name = name; - // } - // - // - // @Override - // public String toString() { - // return name; - // } - // } public MedtronicHistoryActivity() { super(); HandlerThread mHandlerThread = new HandlerThread(MedtronicHistoryActivity.class.getSimpleName()); mHandlerThread.start(); - // this.fullHistoryList = MedtronicPumpPlugin.getPlugin().getMedtronicHistoryData().getAllHistory(); - filterHistory(this.showingType); + filterHistory(PumpHistoryEntryGroup.All); this.mHandler = new Handler(mHandlerThread.getLooper()); } @@ -99,6 +79,11 @@ public class MedtronicHistoryActivity extends Activity { } } + if (this.recyclerViewAdapter != null) { + this.recyclerViewAdapter.setHistoryList(this.filteredHistoryList); + this.recyclerViewAdapter.notifyDataSetChanged(); + } + LOG.debug("Items on filtered list: {}", filteredHistoryList.size()); } @@ -107,7 +92,23 @@ public class MedtronicHistoryActivity extends Activity { protected void onResume() { super.onResume(); MainApp.bus().register(this); - filterHistory(showingType); + filterHistory(selectedGroup); + setHistoryTypeSpinner(); + } + + + private void setHistoryTypeSpinner() { + this.manualChange = true; + + for (int i = 0; i < typeListFull.size(); i++) { + if (typeListFull.get(i).entryGroup == selectedGroup) { + historyTypeSpinner.setSelection(i); + break; + } + } + + SystemClock.sleep(200); + this.manualChange = false; } @@ -125,58 +126,75 @@ public class MedtronicHistoryActivity extends Activity { historyTypeSpinner = (Spinner)findViewById(R.id.medtronic_historytype); statusView = (TextView)findViewById(R.id.medtronic_historystatus); - // reloadButton = (Button)findViewById(R.id.medtronic_historyreload); - // syncButton = (Button)findViewById(R.id.medtronic_historysync); recyclerView = (RecyclerView)findViewById(R.id.medtronic_history_recyclerview); recyclerView.setHasFixedSize(true); llm = new LinearLayoutManager(this); recyclerView.setLayoutManager(llm); - RecyclerViewAdapter adapter = new RecyclerViewAdapter(filteredHistoryList); - recyclerView.setAdapter(adapter); + recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList); + recyclerView.setAdapter(recyclerViewAdapter); statusView.setVisibility(View.GONE); - boolean isKorean = DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP); - boolean isRS = DanaRSPlugin.getPlugin().isEnabled(PluginType.PUMP); + typeListFull = getTypeList(PumpHistoryEntryGroup.getList()); - // Types - - // ArrayList typeList = new ArrayList<>(); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ALARM, MainApp.gs(R.string.danar_history_alarm))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BASALHOUR, MainApp.gs(R.string.danar_history_basalhours))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BOLUS, MainApp.gs(R.string.danar_history_bolus))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_CARBO, MainApp.gs(R.string.danar_history_carbohydrates))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_DAILY, MainApp.gs(R.string.danar_history_dailyinsulin))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_GLUCOSE, MainApp.gs(R.string.danar_history_glucose))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ERROR, MainApp.gs(R.string.danar_history_errors))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_PRIME, MainApp.gs(R.string.danar_history_prime))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_REFILL, MainApp.gs(R.string.danar_history_refill))); - // typeList.add(new TypeList(RecordTypes.RECORD_TYPE_SUSPEND, MainApp.gs(R.string.danar_history_syspend))); - - ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, R.layout.spinner_centered, - PumpHistoryEntryGroup.getList()); + ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, R.layout.spinner_centered, typeListFull); historyTypeSpinner.setAdapter(spinnerAdapter); historyTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - PumpHistoryEntryGroup selected = (PumpHistoryEntryGroup)historyTypeSpinner.getSelectedItem(); + if (manualChange) + return; + TypeList selected = (TypeList)historyTypeSpinner.getSelectedItem(); showingType = selected; - filterHistory(selected); + selectedGroup = selected.entryGroup; + filterHistory(selectedGroup); } @Override public void onNothingSelected(AdapterView parent) { - filterHistory(showingType); + if (manualChange) + return; + filterHistory(PumpHistoryEntryGroup.All); } }); } + + private List getTypeList(List list) { + + ArrayList typeList = new ArrayList<>(); + + for (PumpHistoryEntryGroup pumpHistoryEntryGroup : list) { + typeList.add(new TypeList(pumpHistoryEntryGroup)); + } + + return typeList; + } + + public static class TypeList { + + PumpHistoryEntryGroup entryGroup; + String name; + + + TypeList(PumpHistoryEntryGroup entryGroup) { + this.entryGroup = entryGroup; + this.name = entryGroup.getTranslated(); + } + + + @Override + public String toString() { + return name; + } + } + public static class RecyclerViewAdapter extends RecyclerView.Adapter { List historyList; @@ -187,9 +205,19 @@ public class MedtronicHistoryActivity extends Activity { } + public void setHistoryList(List historyList) { + // this.historyList.clear(); + // this.historyList.addAll(historyList); + + this.historyList = historyList; + + // this.notifyDataSetChanged(); + } + + @Override public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rileylink_status_history_item, // + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.medtronic_history_item, // viewGroup, false); return new HistoryViewHolder(v); } @@ -199,9 +227,11 @@ public class MedtronicHistoryActivity extends Activity { public void onBindViewHolder(HistoryViewHolder holder, int position) { PumpHistoryEntry record = historyList.get(position); - holder.timeView.setText(record.getDateTimeString()); - holder.typeView.setText(record.getEntryType().getDescription()); - holder.valueView.setText(record.getDisplayableValue()); + if (record != null) { + holder.timeView.setText(record.getDateTimeString()); + holder.typeView.setText(record.getEntryType().getDescription()); + holder.valueView.setText(record.getDisplayableValue()); + } } @@ -218,7 +248,6 @@ public class MedtronicHistoryActivity extends Activity { static class HistoryViewHolder extends RecyclerView.ViewHolder { - CardView cv; TextView timeView; TextView typeView; TextView valueView; @@ -227,9 +256,9 @@ public class MedtronicHistoryActivity extends Activity { HistoryViewHolder(View itemView) { super(itemView); // cv = (CardView)itemView.findViewById(R.id.rileylink_history_item); - timeView = (TextView)itemView.findViewById(R.id.rileylink_history_time); - typeView = (TextView)itemView.findViewById(R.id.rileylink_history_source); - valueView = (TextView)itemView.findViewById(R.id.rileylink_history_description); + timeView = (TextView)itemView.findViewById(R.id.medtronic_history_time); + typeView = (TextView)itemView.findViewById(R.id.medtronic_history_source); + valueView = (TextView)itemView.findViewById(R.id.medtronic_history_description); } } } diff --git a/app/src/main/res/layout/medtronic_history_activity.xml b/app/src/main/res/layout/medtronic_history_activity.xml index 4ff543ecbe..74fb1f41cf 100644 --- a/app/src/main/res/layout/medtronic_history_activity.xml +++ b/app/src/main/res/layout/medtronic_history_activity.xml @@ -37,7 +37,7 @@ android:layout_weight="1" android:background="@drawable/pillborder" android:gravity="center_horizontal" - android:text="DanaR History" /> + android:text="@string/medtronic_pump_history" /> @@ -54,7 +54,6 @@ android:id="@+id/medtronic_history_recyclerview" android:layout_width="match_parent" android:layout_height="fill_parent" - android:layout_below="@+id/medtronic_historystatus" /> diff --git a/app/src/main/res/layout/medtronic_history_item.xml b/app/src/main/res/layout/medtronic_history_item.xml new file mode 100644 index 0000000000..07bb72eb6a --- /dev/null +++ b/app/src/main/res/layout/medtronic_history_item.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/rileylink_status_history.xml b/app/src/main/res/layout/rileylink_status_history.xml index d95fc9f42f..1817ec01e1 100644 --- a/app/src/main/res/layout/rileylink_status_history.xml +++ b/app/src/main/res/layout/rileylink_status_history.xml @@ -10,12 +10,20 @@ android:layout_height="match_parent" android:orientation="vertical"> - + + + android:layout_width="match_parent" + android:layout_height="fill_parent" + android:layout_below="@+id/rileylink_historystatus" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/rileylink_status_history_item.xml b/app/src/main/res/layout/rileylink_status_history_item.xml index 5df538f781..ebfcfecac9 100644 --- a/app/src/main/res/layout/rileylink_status_history_item.xml +++ b/app/src/main/res/layout/rileylink_status_history_item.xml @@ -3,7 +3,7 @@ android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp" - android:id="@+id/rileylink_history_item" + android:id="@+id/rileylink_status_history_item" android:paddingLeft="20dp"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d37d27f6d0..eb35228580 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1331,6 +1331,7 @@ Statistics Unknowns All + Medtronic Pump History diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java index 1521c21071..02c98d1224 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java @@ -47,6 +47,25 @@ public class MedtronicPumpHistoryDecoderUTest { } + // @Test + public void decodeLowAmount() { + byte[] data = new byte[] { 52, -12, 22, -81, 46, 3, 19 }; + + PumpHistoryEntryGroup.doNotTranslate = true; + PumpHistoryEntryType entryType = PumpHistoryEntryType.getByCode(52); + + PumpHistoryEntry phe = new PumpHistoryEntry(); + phe.setEntryType(entryType); + phe.setData(ByteUtil.getListFromByteArray(data), false); + + decoder.decodeRecord(phe); + + System.out.println("Record: " + phe); + System.out.println("Record: " + phe.getDisplayableValue()); + + } + + // @Test public void decodeDailyTotals522() { // PumpHistoryRecord [type=DailyTotals522 [109, 0x6D], DT: 01.11.2018 00:00:00, length=1,2,41(44), data={Raw diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfileUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfileUTest.java index 0f3ae9c4ce..036efeb1fb 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfileUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/BasalProfileUTest.java @@ -143,4 +143,29 @@ public class BasalProfileUTest { } + + @Test + public void testProfileFromHistory() { + MedtronicUtil.setPumpStatus(new MedtronicPumpStatus(new PumpDescription())); + MedtronicUtil.getPumpStatus().pumpType = PumpType.Medtronic_522_722; + + byte[] data = { + 0, 72, 0, 2, 64, 0, 4, 56, 0, 6, 58, 0, 8, 58, 0, 10, 58, 0, 12, 50, 0, 14, 50, 0, 16, 38, 0, 18, 38, 0, + 20, 46, 0, 22, 46, 0, 24, 50, 0, 26, 38, 0, 28, 38, 0, 30, 38, 0, 32, 26, 0, 34, 26, 0, 36, 26, 0, 38, 26, + 0, 40, 26, 0, 42, 20, 0, 44, 20, 0, 46, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + BasalProfile basalProfile = new BasalProfile(); + basalProfile.setRawDataFromHistory(data); + + Double[] profilesByHour = basalProfile.getProfilesByHour(); + + System.out.println("Basals by hour: " + + (profilesByHour == null ? "null" : BasalProfile.getProfilesByHourToString(profilesByHour))); + + // 1.800 1.600 1.400 1.450 1.450 1.450 1.250 1.250 0.950 0.950 1.150 1.150 1.250 0.950 0.950 0.950 0.650 0.650 + // 0.650 0.650 0.650 0.500 0.500 0.500 + } + }