From 05dcb58f0a2d4470afde4934df2ab01bf06ded26 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 28 Oct 2018 11:24:59 +0100 Subject: [PATCH] check for future timestamp while loading history (RS,Rv2) --- .../DanaRS_Packet_APS_History_Events.java | 6 ++++ .../PumpDanaRv2/comm/MsgHistoryEvents_v2.java | 35 +++++++++++-------- .../services/DanaRv2ExecutionService.java | 14 +++----- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java index dd3e5398c9..98e08a7ee3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java @@ -45,6 +45,12 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { public DanaRS_Packet_APS_History_Events(long from) { this(); GregorianCalendar cal = new GregorianCalendar(); + + if (from > DateUtil.now()) { + log.debug("Asked to load from the future"); + from = 0; + } + if (from != 0) cal.setTimeInMillis(from); else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java index b12116e1a0..32ac8862ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java @@ -26,23 +26,30 @@ public class MsgHistoryEvents_v2 extends MessageBase { public static long lastEventTimeLoaded = 0; - public MsgHistoryEvents_v2(long from) { - SetCommand(0xE003); - GregorianCalendar gfrom = new GregorianCalendar(); - gfrom.setTimeInMillis(from); - AddParamDate(gfrom); - done = false; - if (L.isEnabled(L.PUMPCOMM)) - log.debug("New message"); + public MsgHistoryEvents_v2() { + this(0); } - public MsgHistoryEvents_v2() { + public MsgHistoryEvents_v2(long from) { SetCommand(0xE003); - AddParamByte((byte) 0); - AddParamByte((byte) 1); - AddParamByte((byte) 1); - AddParamByte((byte) 0); - AddParamByte((byte) 0); + + if (from > DateUtil.now()) { + log.debug("Asked to load from the future"); + from = 0; + } + + if (from == 0) { + AddParamByte((byte) 0); + AddParamByte((byte) 1); + AddParamByte((byte) 1); + AddParamByte((byte) 0); + AddParamByte((byte) 0); + } else { + GregorianCalendar gfrom = new GregorianCalendar(); + gfrom.setTimeInMillis(from); + AddParamDate(gfrom); + } + done = false; if (L.isEnabled(L.PUMPCOMM)) log.debug("New message"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index bcb6c66c60..f51f846978 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -465,16 +465,10 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return new PumpEnactResult().success(false); SystemClock.sleep(300); - MsgHistoryEvents_v2 msg; - if (lastHistoryFetched == 0) { - msg = new MsgHistoryEvents_v2(); - if (L.isEnabled(L.PUMP)) - log.debug("Loading complete event history"); - } else { - msg = new MsgHistoryEvents_v2(lastHistoryFetched); - if (L.isEnabled(L.PUMP)) - log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched)); - } + MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched); + if (L.isEnabled(L.PUMP)) + log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched)); + mSerialIOThread.sendMessage(msg); while (!msg.done && mRfcommSocket.isConnected()) { SystemClock.sleep(100);