From 2a126783b7b81b2ceab3b4d79e97f86ae2d81f88 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 19 Jan 2019 06:31:11 +0100 Subject: [PATCH] Upload JSON status --- .../PumpInsightLocal/LocalInsightPlugin.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 58bae220f1..d32ce09948 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -20,6 +20,7 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; +import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; @@ -48,6 +49,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; +import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.HistoryReadingDirection; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.ReadHistoryEventsMessage; @@ -815,7 +817,50 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public JSONObject getJSONStatus(Profile profile, String profileName) { - return new JSONObject(); + long now = System.currentTimeMillis(); + if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { + return null; + } + + final JSONObject pump = new JSONObject(); + final JSONObject battery = new JSONObject(); + final JSONObject status = new JSONObject(); + final JSONObject extended = new JSONObject(); + try { + status.put("timestamp", DateUtil.toISOString(connectionService.getLastConnected())); + extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + try { + extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); + } catch (Exception e) { + } + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); + if (tb != null) { + extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); + extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); + extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); + } + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); + if (eb != null) { + extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); + extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); + extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes()); + } + extended.put("BaseBasalRate", getBaseBasalRate()); + status.put("timestamp", DateUtil.toISOString(now)); + + pump.put("extended", extended); + if (statusLoaded) { + status.put("status", operatingMode != OperatingMode.STARTED ? "suspended" : "normal"); + pump.put("status", status); + battery.put("percent", batteryStatus.getBatteryAmount()); + pump.put("battery", battery); + pump.put("reservoir", cartridgeStatus.getRemainingAmount()); + } + pump.put("clock", DateUtil.toISOString(now)); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return pump; } @Override