From cb4330ddcd7124d8508c7acc2ed5f19f236eb17e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 13 Dec 2016 22:10:13 +0100 Subject: [PATCH] notify when pump settings is wrong --- .../androidaps/plugins/DanaR/DanaRPlugin.java | 10 +++++++++- .../plugins/DanaR/Services/ExecutionService.java | 2 +- .../plugins/DanaR/comm/MsgInitConnStatusBolus.java | 9 +++++++++ .../plugins/DanaRKorean/DanaRKoreanPlugin.java | 10 +++++++++- .../plugins/DanaRKorean/DanaRKoreanPump.java | 1 + .../DanaRKorean/Services/ExecutionService.java | 2 +- .../DanaRKorean/comm/MsgInitConnStatusBasic.java | 13 +++++++++++-- .../DanaRKorean/comm/MsgInitConnStatusBolus.java | 9 +++++++++ .../plugins/DanaRKorean/comm/MsgSettingMeal.java | 9 +++++++++ .../androidaps/plugins/Overview/Notification.java | 4 ++++ app/src/main/res/values/strings.xml | 4 ++++ 11 files changed, 67 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index a94ae44e8c..553c34e87b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -37,6 +37,8 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService; import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerPlugin; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -195,7 +197,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public boolean isInitialized() { - return getDanaRPump().lastConnection.getTime() > 0; + return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled; } // Pump interface @@ -220,6 +222,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (sExecutionService == null) { log.error("setNewBasalProfile sExecutionService is null"); return; + } + if (!isInitialized()) { + log.error("setNewBasalProfile not initialized"); + Notification notification = new Notification(Notification.NOT_INITIALIZED, MainApp.sResources.getString(R.string.canceledPumpNotInitialized), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + return; } if (!sExecutionService.updateBasalsInPump(profile)) ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.failedupdatebasalprofile)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index 338431f841..12407c7549 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -310,7 +310,7 @@ public class ExecutionService extends Service { } Date now = new Date(); - if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime()) { + if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !((DanaRPlugin)MainApp.getSpecificPlugin(DanaRPlugin.class)).isInitialized()) { mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingMeal()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusBolus.java index 75d20f5ccd..b65bd8a7c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusBolus.java @@ -4,8 +4,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaR.DanaRPump; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; /** * Created by mike on 28.05.2016. @@ -35,5 +39,10 @@ public class MsgInitConnStatusBolus extends MessageBase { log.debug("Bolus increment: " + pump.bolusStep); log.debug("Bolus max: " + pump.maxBolus); } + + if (!pump.isExtendedBolusEnabled) { + Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.sResources.getString(R.string.danar_enableextendedbolus), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java index 831909cfab..0c9d93426f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java @@ -37,6 +37,8 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService; import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerPlugin; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -195,7 +197,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints @Override public boolean isInitialized() { - return getDanaRPump().lastConnection.getTime() > 0; + return getDanaRPump().lastConnection.getTime() > 0 && !getDanaRPump().isConfigUD && !getDanaRPump().isEasyModeEnabled && getDanaRPump().isExtendedBolusEnabled; } // Pump interface @@ -221,6 +223,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints log.error("setNewBasalProfile sExecutionService is null"); return; } + if (!isInitialized()) { + log.error("setNewBasalProfile not initialized"); + Notification notification = new Notification(Notification.NOT_INITIALIZED, MainApp.sResources.getString(R.string.canceledPumpNotInitialized), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + return; + } if (!sExecutionService.updateBasalsInPump(profile)) ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.failedupdatebasalprofile)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPump.java index add4ba734f..16ac0e2507 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPump.java @@ -48,6 +48,7 @@ public class DanaRKoreanPump { public boolean isConfigUD; public boolean isExtendedBolusEnabled; + public boolean isEasyModeEnabled; // Status public double dailyTotalUnits; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java index beae7a36ff..968305446a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java @@ -304,7 +304,7 @@ public class ExecutionService extends Service { } Date now = new Date(); - if (danaRKoreanPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime()) { + if (danaRKoreanPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).isInitialized()) { mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); mSerialIOThread.sendMessage(new MsgSettingMeal()); mSerialIOThread.sendMessage(new MsgSettingBasal()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBasic.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBasic.java index 379a558bea..8ef367d908 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBasic.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBasic.java @@ -4,9 +4,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class MsgInitConnStatusBasic extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusBasic.class); @@ -23,15 +27,20 @@ public class MsgInitConnStatusBasic extends MessageBase { DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump(); int isStatusSuspendOn = intFromBuff(bytes, 0, 1); int isUtilityEnable = intFromBuff(bytes, 1, 1); - int isEasyUIEnable = intFromBuff(bytes, 2, 1); + pump.isEasyModeEnabled = intFromBuff(bytes, 2, 1) == 1; int easyUIMode = intFromBuff(bytes, 3, 1); pump.password = intFromBuff(bytes, 4, 2) ^ 0x3463; if (Config.logDanaMessageDetail) { log.debug("isStatusSuspendOn: " + isStatusSuspendOn); log.debug("isUtilityEnable: " + isUtilityEnable); - log.debug("isEasyUIEnable: " + isEasyUIEnable); + log.debug("Is EasyUI Enabled: " + pump.isEasyModeEnabled); log.debug("easyUIMode: " + easyUIMode); log.debug("Pump password: " + pump.password); } + + if (pump.isEasyModeEnabled) { + Notification notification = new Notification(Notification.EASYMODE_ENABLED, MainApp.sResources.getString(R.string.danar_disableeasymode), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBolus.java index 564c038ee3..604a6b919b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgInitConnStatusBolus.java @@ -4,9 +4,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; /** * Created by mike on 28.05.2016. @@ -38,5 +42,10 @@ public class MsgInitConnStatusBolus extends MessageBase { log.debug("Bolus max: " + pump.maxBolus); log.debug("Delivery status: " + deliveryStatus); } + + if (!pump.isExtendedBolusEnabled) { + Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.sResources.getString(R.string.danar_enableextendedbolus), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgSettingMeal.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgSettingMeal.java index f6e52a40e3..31a07f7285 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgSettingMeal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/comm/MsgSettingMeal.java @@ -4,9 +4,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaR.DanaRPump; import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; /** * Created by mike on 13.12.2016. @@ -36,6 +40,11 @@ public class MsgSettingMeal extends MessageBase { log.debug("Block time: " + blockTime); log.debug("Is Config U/d: " + pump.isConfigUD); } + + if (pump.isConfigUD) { + Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.sResources.getString(R.string.danar_switchtouhmode), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index bcbc14a877..4e83441192 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -14,6 +14,10 @@ public class Notification { public static final int PROFILE_SET_FAILED = 0; public static final int PROFILE_SET_OK = 1; + public static final int EASYMODE_ENABLED = 2; + public static final int EXTENDED_BOLUS_DISABLED = 3; + public static final int UD_MODE_ENABLED = 4; + public static final int NOT_INITIALIZED = 5; public int id; public Date date; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 942455671f..38bd32bb03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -340,6 +340,7 @@ NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used. Please deactivate "NS upload only" to use this feature. Pump not initialized! + Canceled. Pump not initialized! Prime/Fill Please make sure the amount matches the specification of your infusion set! Other @@ -379,4 +380,7 @@ Basal rate: Setting of basal profile failed Basal profile in pump updated + Disable EasyUI mode in pump + Enable extended boluses on pump + Change mode from U/d to U/h on pump