From e005a6172bbdfa9962faeeab392219ed5eb37f46 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 16 Aug 2017 17:26:58 +0200 Subject: [PATCH] set pump time only if needed --- .../androidaps/plugins/PumpDanaR/comm/MsgSetTime.java | 4 +++- .../plugins/PumpDanaR/comm/MsgSettingPumpTime.java | 2 +- .../PumpDanaR/services/DanaRExecutionService.java | 11 +++++++++-- .../services/DanaRKoreanExecutionService.java | 10 ++++++++-- .../PumpDanaRv2/services/DanaRv2ExecutionService.java | 11 +++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java index aa15a02709..3910d52c97 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java @@ -13,9 +13,11 @@ import info.nightscout.androidaps.Config; public class MsgSetTime extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgSetTime.class); + private static Date time; public MsgSetTime(Date time) { SetCommand(0x330a); + this.time = time; AddParamDateTime(time); } @@ -23,6 +25,6 @@ public class MsgSetTime extends MessageBase { int result = intFromBuff(bytes, 0, 1); if (Config.logDanaMessageDetail) - log.debug("Result: " + result); + log.debug("Result of setting time: " + time + " is " + result); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java index 23f0e4560f..3da1451899 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTime.java @@ -27,7 +27,7 @@ public class MsgSettingPumpTime extends MessageBase { ); if (Config.logDanaMessageDetail) - log.debug("Pump time: " + time); + log.debug("Pump time: " + time + " Phone time: " + new Date()); DanaRPump.getInstance().pumpTime = time; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index e4e32e39c3..a1d8ecff87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -326,11 +326,18 @@ public class DanaRExecutionService extends Service { //0x3201 mSerialIOThread.sendMessage(new MsgSettingMaxValues()); mSerialIOThread.sendMessage(new MsgSettingGlucose()); - mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); - mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime()); + long timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + if (Math.abs(timeDiff) > 10) { + mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime()); + timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + } danaRPump.lastSettingsRead = now; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index d803c17bda..f7ad5976b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -322,9 +322,15 @@ public class DanaRKoreanExecutionService extends Service { //0x3201 mSerialIOThread.sendMessage(new MsgSettingMaxValues()); mSerialIOThread.sendMessage(new MsgSettingGlucose()); - mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); - mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + long timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + if (Math.abs(timeDiff) > 10) { + mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime()); + timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + } danaRPump.lastSettingsRead = now; } 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 6527eeebaf..98d869e09c 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 @@ -297,11 +297,18 @@ public class DanaRv2ExecutionService extends Service { //0x3201 mSerialIOThread.sendMessage(new MsgSettingMaxValues()); mSerialIOThread.sendMessage(new MsgSettingGlucose()); - mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); - mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime()); + long timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + if (Math.abs(timeDiff) > 10) { + mSerialIOThread.sendMessage(new MsgSetTime(new Date())); + mSerialIOThread.sendMessage(new MsgSettingPumpTime()); + timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; + log.debug("Pump time difference: " + timeDiff + " seconds"); + } danaRPump.lastSettingsRead = now; }