From 6e5d3635c8589224dd2ef7d4bd43932606ccce00 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 8 May 2017 23:13:43 +0200 Subject: [PATCH 01/10] using bolus amount from history if comm is interrupted --- .../PumpDanaR/Services/ExecutionService.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java index 54aae17687..ffd16fefdf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java @@ -391,7 +391,7 @@ public class ExecutionService extends Service { return true; } - public boolean bolus(Double amount, int carbs, Treatment t) { + public boolean bolus(double amount, int carbs, Treatment t) { bolusingTreatment = t; MsgBolusStart start = new MsgBolusStart(amount); MsgBolusStop stop = new MsgBolusStop(amount, t); @@ -405,6 +405,7 @@ public class ExecutionService extends Service { } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables MainApp.bus().post(new EventDanaRBolusStart()); + long startTime = new Date().getTime(); if (!stop.stopped) { mSerialIOThread.sendMessage(start); @@ -422,7 +423,23 @@ public class ExecutionService extends Service { } waitMsec(300); bolusingTreatment = null; - getPumpStatus(); + // try to find real amount if bolusing was interrupted or comm failed + if (t.insulin != amount) { + disconnect("bolusingInterrupted"); + long now = new Date().getTime(); + long estimatedBolusEnd = (long) (startTime + amount / 5d * 60 * 1000); // std delivery rate 5 U/min + waitMsec(Math.max(5000, estimatedBolusEnd - now + 3000)); + connect("bolusingInterrupted"); + getPumpStatus(); + if (danaRPump.lastBolusTime.getTime() > now - 60 * 1000L) { // last bolus max 1 min old + t.insulin = danaRPump.lastBolusAmount; + log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount); + } else { + log.debug("Bolus amount in history too old: " + danaRPump.lastBolusTime.toLocaleString()); + } + } else { + getPumpStatus(); + } return true; } From 8d3be5e9584376073b27be2cf6d16c7a158f14fa Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 8 May 2017 23:19:11 +0200 Subject: [PATCH 02/10] colors on danar fragment --- app/src/main/res/layout/danar_fragment.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index 5155ad2ed6..6a6b866d0e 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -47,6 +47,7 @@ android:gravity="start" android:paddingLeft="5dp" android:text="{fa-bluetooth-b}" + android:textColor="@android:color/white" android:textSize="20dp" /> @@ -92,6 +93,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="20dp" /> @@ -137,6 +139,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -181,6 +184,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -225,6 +229,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -269,6 +274,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -313,6 +319,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -357,6 +364,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -401,6 +409,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -445,6 +454,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> @@ -489,6 +499,7 @@ android:layout_weight="1" android:gravity="start" android:paddingLeft="5dp" + android:textColor="@android:color/white" android:textSize="14sp" /> From 09fea02ed284696bd4e1139c2fbf7be468f3c0b1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 9 May 2017 16:24:53 +0200 Subject: [PATCH 03/10] Allow to disable NS upload while client is connected --- .../info/nightscout/androidaps/Services/DataService.java | 4 ++-- .../NSClientInternal/receivers/DBAccessReceiver.java | 6 ++++++ .../plugins/TempTargetRange/TempTargetRangeFragment.java | 4 ++-- .../androidaps/plugins/Treatments/TreatmentsFragment.java | 4 ++-- app/src/main/res/values/strings.xml | 8 ++++++-- app/src/main/res/xml/pref_advanced.xml | 7 ++++++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 0863c8e72d..ca811af251 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTarget import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; +import info.nightscout.utils.SP; public class DataService extends IntentService { @@ -98,8 +99,7 @@ public class DataService extends IntentService { boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class); - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (intent != null) { final String action = intent.getAction(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 44c6587fb1..91fca44d12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -14,10 +14,12 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.db.DbRequest; +import info.nightscout.utils.SP; public class DBAccessReceiver extends BroadcastReceiver { private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class); @@ -32,6 +34,10 @@ public class DBAccessReceiver extends BroadcastReceiver { if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) { return; } + if (SP.getBoolean(R.string.key_ns_noupload, false)) { + log.debug("Upload disabled. Message dropped"); + return; + } wakeLock.acquire(); try { Bundle bundles = intent.getExtras(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java index 13cae1aad0..9222a9a819 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempTargetRange/TempTargetRangeFragment.java @@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; /** @@ -194,8 +195,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis public void onClick(View view) { switch (view.getId()) { case R.id.temptargetrange_refreshfromnightscout: - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (nsUploadOnly) { ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index 704d71e61b..0c4dcb26f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; public class TreatmentsFragment extends Fragment implements View.OnClickListener { @@ -192,8 +193,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener public void onClick(View view) { switch (view.getId()) { case R.id.treatments_reshreshfromnightscout: - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); + boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); if (nsUploadOnly) { ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); } else { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4370d8f297..027ae451b9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -508,12 +508,12 @@ Password for settings Unlock settings Approaching insulin daily limit - NSClient internal + NSClient NSCI URL: Autoscroll Restart - Internal NSClient + NSClient Nightscout URL Enter Nightscout URL NS API secret @@ -603,4 +603,8 @@ xDrip Status (watch) xDrip Statusline (watch) xds + No upload to NS + All data sent to NS are dropped. AAPS is connected to NS but no change in NS is done + ns_upload_only + ns_noupload diff --git a/app/src/main/res/xml/pref_advanced.xml b/app/src/main/res/xml/pref_advanced.xml index b385206d10..05898654fe 100644 --- a/app/src/main/res/xml/pref_advanced.xml +++ b/app/src/main/res/xml/pref_advanced.xml @@ -10,9 +10,14 @@ android:title="@string/nightscout"> + Date: Tue, 9 May 2017 16:51:08 +0200 Subject: [PATCH 04/10] invalidate autosens on new profile --- .../androidaps/Services/DataService.java | 2 +- .../androidaps/events/EventNewBasalProfile.java | 4 +++- .../Careportal/Dialogs/NewNSTreatmentDialog.java | 2 +- .../IobCobCalculator/IobCobCalculatorPlugin.java | 16 +++++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index ca811af251..b9bc74f526 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -356,7 +356,7 @@ public class DataService extends IntentService { String activeProfile = bundles.getString("activeprofile"); String profile = bundles.getString("profile"); NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile); - MainApp.bus().post(new EventNewBasalProfile(nsProfile)); + MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NSClient")); PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java index 3e270e8a1b..b3750f59c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java @@ -7,8 +7,10 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; */ public class EventNewBasalProfile { public NSProfile newNSProfile = null; + public String from = ""; - public EventNewBasalProfile(NSProfile newProfile) { + public EventNewBasalProfile(NSProfile newProfile, String from) { newNSProfile = newProfile; + this.from = from; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index 34641f5ebb..f0cf085e16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -618,7 +618,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if (pump != null) { pump.setNewBasalProfile(nsProfile); log.debug("Setting new profile: " + profile); - MainApp.bus().post(new EventNewBasalProfile(nsProfile)); + MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NewNSTreatmentDialog")); } else { log.error("No active pump selected"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 0e9e4512ae..b28927d3ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -156,7 +156,7 @@ public class IobCobCalculatorPlugin implements PluginBase { private void loadBgData() { //log.debug("Locking loadBgData"); synchronized (dataLock) { - onNewProfile(new EventNewBasalProfile(null)); + onNewProfile(new EventNewBasalProfile(null, "IobCobCalculator init")); bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia)), false); log.debug("BG data loaded. Size: " + bgReadings.size()); } @@ -545,6 +545,20 @@ public class IobCobCalculatorPlugin implements PluginBase { if (profile != null) { dia = profile.getDia(); } + if (ev.newNSProfile == null) { // on init no need of reset + return; + } + synchronized (dataLock) { + log.debug("Invalidating cached data because of new profile from " + ev.from + ". IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); + iobTable = new LongSparseArray<>(); + autosensDataTable = new LongSparseArray<>(); + } + sHandler.post(new Runnable() { + @Override + public void run() { + calculateSensitivityData(); + } + }); } // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated From 84a6554e0727abc83ad68e96894786c2fb10e55e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 9 May 2017 18:36:13 +0200 Subject: [PATCH 05/10] smaller font size on careportal buttons --- .../main/res/layout/careportal_fragment.xml | 19 +++++++++++++++++++ app/src/main/res/values/styles.xml | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/app/src/main/res/layout/careportal_fragment.xml b/app/src/main/res/layout/careportal_fragment.xml index b0beb569f3..f72dc7070e 100644 --- a/app/src/main/res/layout/careportal_fragment.xml +++ b/app/src/main/res/layout/careportal_fragment.xml @@ -19,6 +19,7 @@