From 33d1d3e82d845e70b8733717b3d4d385b563517a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 21 Dec 2019 16:53:50 +0100 Subject: [PATCH] DanaRS time setting update for protocol #6 --- .../pump/danaRS/services/DanaRSService.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index 776f6f9272..4e56133222 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -181,6 +181,20 @@ public class DanaRSService extends Service { RxBus.INSTANCE.send(new EventInitializationChanged()); return; } + long now = System.currentTimeMillis(); + if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { + RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); + bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information()); // serial no + bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number()); + bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled + bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal + bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target + bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array()); + bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option()); // Getting user options + danaRPump.lastSettingsRead = now; + } + if (L.isEnabled(L.PUMPCOMM)) log.debug("Pump time difference: " + timeDiff + " seconds"); if (Math.abs(timeDiff) > 3) { @@ -201,9 +215,13 @@ public class DanaRSService extends Service { RxBus.INSTANCE.send(new EventInitializationChanged()); return; } else { - waitForWholeMinute(); // Dana can set only whole minute - // add 10sec to be sure we are over minute (will be cutted off anyway) - bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(new Date(DateUtil.now() + T.secs(10).msecs()))); + if (danaRPump.protocol >= 6) { + bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(new Date())); + } else { + waitForWholeMinute(); // Dana can set only whole minute + // add 10sec to be sure we are over minute (will be cutted off anyway) + bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(new Date(DateUtil.now() + T.secs(10).msecs()))); + } bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time()); timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L; if (L.isEnabled(L.PUMPCOMM)) @@ -211,20 +229,6 @@ public class DanaRSService extends Service { } } - long now = System.currentTimeMillis(); - if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) { - RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); - bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information()); // serial no - bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number()); - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled - bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target - bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array()); - bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option()); // Getting user options - danaRPump.lastSettingsRead = now; - } - loadEvents(); RxBus.INSTANCE.send(new EventDanaRNewStatus());