fix conflict

This commit is contained in:
Milos Kozak 2017-06-27 13:51:45 +02:00
commit 103836717a
19 changed files with 746 additions and 37 deletions

View file

@ -12,8 +12,6 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -25,7 +23,7 @@ import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
@ -38,6 +36,7 @@ import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -259,11 +258,11 @@ public class DataService extends IntentService {
if (bundles.containsKey("status")) { if (bundles.containsKey("status")) {
try { try {
JSONObject statusJson = new JSONObject(bundles.getString("status")); JSONObject statusJson = new JSONObject(bundles.getString("status"));
NSStatus.getInstance().setData(statusJson); NSSettingsStatus.getInstance().setData(statusJson);
if (Config.logIncommingData) if (Config.logIncommingData)
log.debug("Received status: " + statusJson.toString()); log.debug("Received status: " + statusJson.toString());
Double targetHigh = NSStatus.getInstance().getThreshold("bgTargetTop"); Double targetHigh = NSSettingsStatus.getInstance().getThreshold("bgTargetTop");
Double targetlow = NSStatus.getInstance().getThreshold("bgTargetBottom"); Double targetlow = NSSettingsStatus.getInstance().getThreshold("bgTargetBottom");
if (targetHigh != null) if (targetHigh != null)
OverviewPlugin.bgTargetHigh = targetHigh; OverviewPlugin.bgTargetHigh = targetHigh;
if (targetlow != null) if (targetlow != null)
@ -276,8 +275,8 @@ public class DataService extends IntentService {
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) { if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
try { try {
if (bundles.containsKey("devicestatus")) { if (bundles.containsKey("devicestatus")) {
String devicestatusesstring = bundles.getString("devicestatus");
JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus")); JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus"));
NSDeviceStatus.getInstance().setData(devicestatusJson);
if (devicestatusJson.has("pump")) { if (devicestatusJson.has("pump")) {
// Objectives 0 // Objectives 0
ObjectivesPlugin.pumpStatusIsAvailableInNS = true; ObjectivesPlugin.pumpStatusIsAvailableInNS = true;
@ -287,8 +286,9 @@ public class DataService extends IntentService {
if (bundles.containsKey("devicestatuses")) { if (bundles.containsKey("devicestatuses")) {
String devicestatusesstring = bundles.getString("devicestatuses"); String devicestatusesstring = bundles.getString("devicestatuses");
JSONArray jsonArray = new JSONArray(devicestatusesstring); JSONArray jsonArray = new JSONArray(devicestatusesstring);
if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject devicestatusJson = jsonArray.getJSONObject(0); JSONObject devicestatusJson = jsonArray.getJSONObject(i);
NSDeviceStatus.getInstance().setData(devicestatusJson);
if (devicestatusJson.has("pump")) { if (devicestatusJson.has("pump")) {
// Objectives 0 // Objectives 0
ObjectivesPlugin.pumpStatusIsAvailableInNS = true; ObjectivesPlugin.pumpStatusIsAvailableInNS = true;

View file

@ -1014,6 +1014,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
} }
public Profile getProfile(long time) { public Profile getProfile(long time) {
if (activeTreatments == null)
return null; //app not initialized
//log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time));
boolean ignoreProfileSwitchEvents = SP.getBoolean(R.string.key_do_not_track_profile_switch, false); boolean ignoreProfileSwitchEvents = SP.getBoolean(R.string.key_do_not_track_profile_switch, false);
if (!ignoreProfileSwitchEvents) { if (!ignoreProfileSwitchEvents) {

View file

@ -305,6 +305,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
public void calculateSensitivityData() { public void calculateSensitivityData() {
if (MainApp.getConfigBuilder() == null) if (MainApp.getConfigBuilder() == null)
return; // app still initializing return; // app still initializing
if (MainApp.getConfigBuilder().getProfile() == null)
return; // app still initializing
//log.debug("Locking calculateSensitivityData"); //log.debug("Locking calculateSensitivityData");
long oldestTimeWithData = oldestDataAvailable(); long oldestTimeWithData = oldestDataAvailable();
@ -640,6 +642,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
if (MainApp.getConfigBuilder() == null) if (MainApp.getConfigBuilder() == null)
return; // app still initializing return; // app still initializing
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null)
return; // app still initializing
dia = profile.getDia(); dia = profile.getDia();
if (ev == null) { // on init no need of reset if (ev == null) { // on init no need of reset
return; return;

View file

@ -13,7 +13,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
/** /**
@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ
public class BroadcastStatus { public class BroadcastStatus {
private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class); private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class);
public static void handleNewStatus(NSStatus status, Context context, boolean isDelta) { public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
try { try {
bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName);

View file

@ -0,0 +1,387 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import android.text.Html;
import android.text.Spanned;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import info.nightscout.androidaps.R;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
/**
* Created by mike on 25.06.2017.
*/
/*
{
"_id": "594fdcec327b83c81b6b8c0f",
"device": "openaps://Sony D5803",
"pump": {
"battery": {
"percent": 100
},
"status": {
"status": "normal",
"timestamp": "2017-06-25T15:50:14Z"
},
"extended": {
"Version": "1.5-ac98852-2017.06.25",
"PumpIOB": 1.13,
"LastBolus": "25. 6. 2017 17:25:00",
"LastBolusAmount": 0.3,
"BaseBasalRate": 0.4,
"ActiveProfile": "2016 +30%"
},
"reservoir": 109,
"clock": "2017-06-25T15:55:10Z"
},
"openaps": {
"suggested": {
"temp": "absolute",
"bg": 115.9,
"tick": "+5",
"eventualBG": 105,
"snoozeBG": 105,
"predBGs": {
"IOB": [116, 114, 112, 110, 109, 107, 106, 105, 105, 104, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 107]
},
"COB": 0,
"IOB": -0.035,
"reason": "COB: 0, Dev: -18, BGI: 0.43, ISF: 216, Target: 99; Eventual BG 105 > 99 but Min. Delta -2.60 < Exp. Delta 0.1; setting current basal of 0.4 as temp. Suggested rate is same as profile rate, no temp basal is active, doing nothing",
"timestamp": "2017-06-25T15:55:10Z"
},
"iob": {
"iob": -0.035,
"basaliob": -0.035,
"activity": -0.0004,
"time": "2017-06-25T15:55:10Z"
}
},
"uploaderBattery": 93,
"created_at": "2017-06-25T15:55:10Z",
"NSCLIENT_ID": 1498406118857
}
*/
public class NSDeviceStatus {
private static NSDeviceStatus instance = null;
public static NSDeviceStatus getInstance() {
if (instance == null)
instance = new NSDeviceStatus();
return instance;
}
private JSONObject data = null;
public NSDeviceStatus() {
}
public NSDeviceStatus setData(JSONObject obj) {
this.data = obj;
updatePumpData(obj);
updateOpenApsData(obj);
updateUploaderData(obj);
return this;
}
public String getDevice() {
try {
if (data.has("device")) {
String device = data.getString("device");
if (device.startsWith("openaps://")) {
device = device.substring(10);
return device;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return "";
}
public static class Levels {
static int URGENT = 2;
static int WARN = 1;
static int INFO = 0;
int LOW = -1;
int LOWEST = -2;
static int NONE = -3;
}
// ***** PUMP DATA ******
static DeviceStatusPumpData deviceStatusPumpData = null;
public Spanned getExtendedPumpStatus() {
if (deviceStatusPumpData.extended != null)
return deviceStatusPumpData.extended;
return Html.fromHtml("");
}
public Spanned getPumpStatus() {
//String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"};
if (deviceStatusPumpData == null)
return Html.fromHtml("");
StringBuilder string = new StringBuilder();
// test warning level
int level = Levels.INFO;
long now = System.currentTimeMillis();
if (deviceStatusPumpData.clock + NSSettingsStatus.getInstance().extendedPumpSettings("urgentClock") * 60 * 1000L < now)
level = Levels.URGENT;
else if (deviceStatusPumpData.reservoir < NSSettingsStatus.getInstance().extendedPumpSettings("urgentRes"))
level = Levels.URGENT;
else if (deviceStatusPumpData.isPercent && deviceStatusPumpData.percent < NSSettingsStatus.getInstance().extendedPumpSettings("urgentBattP"))
level = Levels.URGENT;
else if (!deviceStatusPumpData.isPercent && deviceStatusPumpData.voltage < NSSettingsStatus.getInstance().extendedPumpSettings("urgentBattV"))
level = Levels.URGENT;
else if (deviceStatusPumpData.clock + NSSettingsStatus.getInstance().extendedPumpSettings("warnClock") < now)
level = Levels.WARN;
else if (deviceStatusPumpData.reservoir < NSSettingsStatus.getInstance().extendedPumpSettings("warnRes"))
level = Levels.WARN;
else if (deviceStatusPumpData.isPercent && deviceStatusPumpData.percent < NSSettingsStatus.getInstance().extendedPumpSettings("warnBattP"))
level = Levels.WARN;
else if (!deviceStatusPumpData.isPercent && deviceStatusPumpData.voltage < NSSettingsStatus.getInstance().extendedPumpSettings("warnBattV"))
level = Levels.WARN;
string.append("<span style=\"color:");
if (level == Levels.INFO) string.append("white\">");
if (level == Levels.WARN) string.append("yellow\">");
if (level == Levels.URGENT) string.append("red\">");
String fields = NSSettingsStatus.getInstance().pumpExtentendedSettingsFields();
if (fields.contains("reservoir")) {
string.append((int) deviceStatusPumpData.reservoir).append("U ");
}
if (fields.contains("battery") && deviceStatusPumpData.isPercent) {
string.append(deviceStatusPumpData.percent).append("% ");
}
if (fields.contains("battery") && !deviceStatusPumpData.isPercent) {
string.append(Round.roundTo(deviceStatusPumpData.voltage, 0.001d)).append(" ");
}
if (fields.contains("clock")) {
string.append(DateUtil.minAgo(deviceStatusPumpData.clock)).append(" ");
}
if (fields.contains("status")) {
string.append(deviceStatusPumpData.status).append(" ");
}
if (fields.contains("device")) {
string.append(getDevice()).append(" ");
}
string.append("</span>"); // color
return Html.fromHtml(string.toString());
}
static class DeviceStatusPumpData {
long clock = 0L;
boolean isPercent = false;
int percent = 0;
double voltage = 0;
String status = "N/A";
double reservoir = 0d;
Spanned extended = null;
}
public void updatePumpData(JSONObject object) {
try {
JSONObject pump = data != null && data.has("pump") ? data.getJSONObject("pump") : new JSONObject();
long clock = 0L;
if (pump.has("clock"))
clock = DateUtil.fromISODateString(pump.getString("clock")).getTime();
// check if this is new data
if (clock == 0 || deviceStatusPumpData != null && clock < deviceStatusPumpData.clock)
return;
// create new status and process data
deviceStatusPumpData = new DeviceStatusPumpData();
deviceStatusPumpData.clock = clock;
if (pump.has("status") && pump.getJSONObject("status").has("status"))
deviceStatusPumpData.status = pump.getJSONObject("status").getString("status");
if (pump.has("reservoir"))
deviceStatusPumpData.reservoir = pump.getDouble("reservoir");
if (pump.has("battery") && pump.getJSONObject("battery").has("percent")) {
deviceStatusPumpData.isPercent = true;
deviceStatusPumpData.percent = pump.getJSONObject("battery").getInt("percent");
} else if (pump.has("battery") && pump.getJSONObject("battery").has("voltage")) {
deviceStatusPumpData.isPercent = false;
deviceStatusPumpData.voltage = pump.getJSONObject("battery").getDouble("voltage");
}
if (pump.has("extended")) {
JSONObject extendedJson = pump.getJSONObject("extended");
StringBuilder exteneded = new StringBuilder();
Iterator<?> keys = extendedJson.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
String value = extendedJson.getString(key);
exteneded.append("<b>").append(key).append(":</b> ").append(value).append("<br>");
}
deviceStatusPumpData.extended = Html.fromHtml(exteneded.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
// ********* OpenAPS data ***********
static DeviceStatusOpenAPSData deviceStatusOpenAPSData = new DeviceStatusOpenAPSData();
static class DeviceStatusOpenAPSData {
long clockSuggested = 0L;
long clockEnacted = 0L;
JSONObject suggested = null;
JSONObject enacted = null;
}
public void updateOpenApsData(JSONObject object) {
try {
JSONObject openaps = object.has("openaps") ? object.getJSONObject("openaps") : new JSONObject();
JSONObject suggested = openaps.has("suggested") ? openaps.getJSONObject("suggested") : new JSONObject();
JSONObject enacted = openaps.has("enacted") ? openaps.getJSONObject("enacted") : new JSONObject();
long clock = 0L;
if (suggested.has("timestamp"))
clock = DateUtil.fromISODateString(suggested.getString("timestamp")).getTime();
// check if this is new data
if (clock != 0 && clock > deviceStatusOpenAPSData.clockSuggested) {
deviceStatusOpenAPSData.suggested = suggested;
deviceStatusOpenAPSData.clockSuggested = clock;
}
clock = 0L;
if (enacted.has("timestamp"))
clock = DateUtil.fromISODateString(enacted.getString("timestamp")).getTime();
// check if this is new data
if (clock != 0 && clock > deviceStatusOpenAPSData.clockEnacted) {
deviceStatusOpenAPSData.enacted = enacted;
deviceStatusOpenAPSData.clockEnacted = clock;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Spanned getOpenApsStatus() {
StringBuilder string = new StringBuilder();
// test warning level
int level = Levels.INFO;
long now = System.currentTimeMillis();
if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + SP.getInt(R.string.key_nsalarm_urgent_staledatavalue, 16) * 60 * 1000L < now)
level = Levels.URGENT;
else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + SP.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now)
level = Levels.WARN;
string.append("<span style=\"color:");
if (level == Levels.INFO) string.append("white\">");
if (level == Levels.WARN) string.append("yellow\">");
if (level == Levels.URGENT) string.append("red\">");
if (deviceStatusOpenAPSData.clockSuggested != 0) {
string.append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append(" ");
}
string.append("</span>"); // color
return Html.fromHtml(string.toString());
}
public Spanned getExtendedOpenApsStatus() {
StringBuilder string = new StringBuilder();
try {
if (deviceStatusOpenAPSData.enacted != null && deviceStatusOpenAPSData.clockEnacted != deviceStatusOpenAPSData.clockSuggested)
string.append("<b>").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockEnacted)).append("</b> ").append(deviceStatusOpenAPSData.enacted.getString("reason")).append("<br>");
if (deviceStatusOpenAPSData.suggested != null)
string.append("<b>").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append("</b> ").append(deviceStatusOpenAPSData.suggested.getString("reason")).append("<br>");
return Html.fromHtml(string.toString());
} catch (JSONException e) {
e.printStackTrace();
}
return Html.fromHtml("");
}
// ********* Uploader data ***********
public static HashMap<String, Uploader> uploaders = new HashMap<>();
static class Uploader {
long clock = 0L;
int battery = 0;
}
public void updateUploaderData(JSONObject object) {
try {
long clock = 0L;
if (object.has("created_at"))
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
String device = getDevice();
Integer battery = null;
if (object.has("uploaderBattery"))
battery = object.getInt("uploaderBattery");
else if (object.has("uploader")) {
if (object.getJSONObject("uploader").has("battery"))
battery = object.getJSONObject("uploader").getInt("battery");
}
Uploader uploader = uploaders.get(device);
// check if this is new data
if (clock != 0 && (uploader != null && clock > uploader.clock || uploader == null)) {
if (uploader == null)
uploader = new Uploader();
uploader.battery = battery;
uploader.clock = clock;
uploaders.put(device, uploader);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String getUploaderStatus() {
Iterator iter = uploaders.entrySet().iterator();
int minBattery = 100;
while(iter.hasNext()) {
Map.Entry pair = (Map.Entry) iter.next();
Uploader uploader = (Uploader) pair.getValue();
if (minBattery > uploader.battery)
minBattery = uploader.battery;
}
return minBattery + "%";
}
public Spanned getExtendedUploaderStatus() {
StringBuilder string = new StringBuilder();
Iterator iter = uploaders.entrySet().iterator();
while(iter.hasNext()) {
Map.Entry pair = (Map.Entry) iter.next();
Uploader uploader = (Uploader) pair.getValue();
String device = (String) pair.getKey();
string.append("<b>").append(device).append(":</b> ").append(uploader.battery).append("%<br>");
}
return Html.fromHtml(string.toString());
}
}

View file

@ -97,21 +97,21 @@ import java.util.Date;
"activeProfile": "2016 +30%" "activeProfile": "2016 +30%"
} }
*/ */
public class NSStatus { public class NSSettingsStatus {
private static NSStatus instance = null; private static NSSettingsStatus instance = null;
public static NSStatus getInstance() { public static NSSettingsStatus getInstance() {
if (instance == null) if (instance == null)
instance = new NSStatus(); instance = new NSSettingsStatus();
return instance; return instance;
} }
private JSONObject data = null; private JSONObject data = null;
public NSStatus() { public NSSettingsStatus() {
} }
public NSStatus setData(JSONObject obj) { public NSSettingsStatus setData(JSONObject obj) {
this.data = obj; this.data = obj;
return this; return this;
} }
@ -152,8 +152,17 @@ public class NSStatus {
return getStringOrNull("settings"); return getStringOrNull("settings");
} }
public String getExtendedSettings() { public JSONObject getExtendedSettings() {
return getStringOrNull("extendedSettings"); try {
String extended = getStringOrNull("extendedSettings");
if (extended != null)
return new JSONObject(extended);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
} }
public String getActiveProfile() { public String getActiveProfile() {
@ -254,10 +263,89 @@ public class NSStatus {
return ret; return ret;
} }
; // ***** PUMP STATUS ******
public JSONObject getData() { public JSONObject getData() {
return data; return data;
} }
/*
, warnClock: sbx.extendedSettings.warnClock || 30
, urgentClock: sbx.extendedSettings.urgentClock || 60
, warnRes: sbx.extendedSettings.warnRes || 10
, urgentRes: sbx.extendedSettings.urgentRes || 5
, warnBattV: sbx.extendedSettings.warnBattV || 1.35
, urgentBattV: sbx.extendedSettings.urgentBattV || 1.3
, warnBattP: sbx.extendedSettings.warnBattP || 30
, urgentBattP: sbx.extendedSettings.urgentBattP || 20
, enableAlerts: sbx.extendedSettings.enableAlerts || false
*/
public double extendedPumpSettings(String setting) {
try {
JSONObject pump = extentendedPumpSettings();
switch (setting) {
case "warnClock":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "urgentClock":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "warnRes":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "urgentRes":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "warnBattV":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "urgentBattV":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "warnBattP":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
case "urgentBattP":
return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30;
}
} catch (JSONException e) {
e.printStackTrace();
}
return 0d;
}
@Nullable
public JSONObject extentendedPumpSettings() {
try {
JSONObject extended = getExtendedSettings();
if (extended.has("pump")) {
JSONObject pump = extended.getJSONObject("pump");
return pump;
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public boolean pumpExtentendedSettingsEnabledAlerts() {
try {
JSONObject pump = extentendedPumpSettings();
if (pump != null && pump.has("enableAlerts")) {
return pump.getBoolean("enableAlerts");
}
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
public String pumpExtentendedSettingsFields() {
try {
JSONObject pump = extentendedPumpSettings();
if (pump != null && pump.has("fields")) {
return pump.getString("fields");
}
} catch (JSONException e) {
e.printStackTrace();
}
return "";
}
} }

View file

@ -51,7 +51,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastT
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
@ -432,17 +432,17 @@ public class NSClientService extends Service {
if (data.has("status")) { if (data.has("status")) {
JSONObject status = data.getJSONObject("status"); JSONObject status = data.getJSONObject("status");
NSStatus nsStatus = NSStatus.getInstance().setData(status); NSSettingsStatus nsSettingsStatus = NSSettingsStatus.getInstance().setData(status);
if (!status.has("versionNum")) { if (!status.has("versionNum")) {
if (status.getInt("versionNum") < Config.SUPPORTEDNSVERSION) { if (status.getInt("versionNum") < Config.SUPPORTEDNSVERSION) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!")); MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
} }
} else { } else {
nightscoutVersionName = nsStatus.getVersion(); nightscoutVersionName = nsSettingsStatus.getVersion();
nightscoutVersionCode = nsStatus.getVersionNum(); nightscoutVersionCode = nsSettingsStatus.getVersionNum();
} }
BroadcastStatus.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta); BroadcastStatus.handleNewStatus(nsSettingsStatus, MainApp.instance().getApplicationContext(), isDelta);
/* Other received data to 2016/02/10 /* Other received data to 2016/02/10
{ {
@ -516,8 +516,7 @@ public class NSClientService extends Service {
// remove from upload queue if Ack is failing // remove from upload queue if Ack is failing
UploadQueue.removeID(jsonStatus); UploadQueue.removeID(jsonStatus);
} }
// send only last record BroadcastDeviceStatus.handleNewDeviceStatus(devicestatuses, MainApp.instance().getApplicationContext(), isDelta);
BroadcastDeviceStatus.handleNewDeviceStatus(devicestatuses.getJSONObject(devicestatuses.length() - 1), MainApp.instance().getApplicationContext(), isDelta);
} }
} }
if (data.has("mbgs")) { if (data.has("mbgs")) {

View file

@ -71,7 +71,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (getDialog() != null) if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(1000, ViewGroup.LayoutParams.WRAP_CONTENT);
MainApp.bus().register(this); MainApp.bus().register(this);
running = true; running = true;
if (bolusEnded) dismiss(); if (bolusEnded) dismiss();

View file

@ -49,7 +49,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.overview_newtreatment_dialog, null, false); View view = inflater.inflate(R.layout.overview_newtreatment_dialog, container, false);
view.findViewById(R.id.ok).setOnClickListener(this); view.findViewById(R.id.ok).setOnClickListener(this);
view.findViewById(R.id.cancel).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this);
@ -70,7 +70,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (getDialog() != null) if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
} }
@Override @Override

View file

@ -131,7 +131,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (getDialog() != null) if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
MainApp.bus().register(this); MainApp.bus().register(this);
} }

View file

@ -6,7 +6,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
/** /**
@ -122,7 +122,7 @@ public class Notification {
BgReading bgReading = MainApp.getDbHelper().lastBg(); BgReading bgReading = MainApp.getDbHelper().lastBg();
if (bgReading == null) if (bgReading == null)
return false; return false;
Double threshold = NSStatus.getInstance().getThreshold("bgTargetTop"); Double threshold = NSSettingsStatus.getInstance().getThreshold("bgTargetTop");
if (threshold == null) if (threshold == null)
return false; return false;
if (bgReading.value <= threshold) if (bgReading.value <= threshold)
@ -134,7 +134,7 @@ public class Notification {
BgReading bgReading = MainApp.getDbHelper().lastBg(); BgReading bgReading = MainApp.getDbHelper().lastBg();
if (bgReading == null) if (bgReading == null)
return false; return false;
Double threshold = NSStatus.getInstance().getThreshold("bgTargetBottom"); Double threshold = NSSettingsStatus.getInstance().getThreshold("bgTargetBottom");
if (threshold == null) if (threshold == null)
return false; return false;
if (bgReading.value >= threshold) if (bgReading.value >= threshold)

View file

@ -117,7 +117,9 @@ import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.utils.BolusWizard; import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
import info.nightscout.utils.OKDialog;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -147,6 +149,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
TextView apsModeView; TextView apsModeView;
TextView tempTargetView; TextView tempTargetView;
TextView pumpStatusView; TextView pumpStatusView;
TextView pumpDeviceStatusView;
TextView openapsDeviceStatusView;
TextView uploaderDeviceStatusView;
LinearLayout loopStatusLayout; LinearLayout loopStatusLayout;
LinearLayout pumpStatusLayout; LinearLayout pumpStatusLayout;
GraphView bgGraph; GraphView bgGraph;
@ -237,6 +242,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus); extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus);
activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile);
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus); pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump);
openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps);
uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader);
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout); loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout); pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
@ -1141,6 +1149,39 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.GONE); getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.GONE);
} }
// pump status from ns
if (pumpDeviceStatusView != null) {
pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus());
pumpDeviceStatusView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.pump), NSDeviceStatus.getInstance().getExtendedPumpStatus(), null);
}
});
}
// OpenAPS status from ns
if (openapsDeviceStatusView != null) {
openapsDeviceStatusView.setText(NSDeviceStatus.getInstance().getOpenApsStatus());
openapsDeviceStatusView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.openaps), NSDeviceStatus.getInstance().getExtendedOpenApsStatus(), null);
}
});
}
// Uploader status from ns
if (uploaderDeviceStatusView != null) {
uploaderDeviceStatusView.setText(NSDeviceStatus.getInstance().getUploaderStatus());
uploaderDeviceStatusView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus(), null);
}
});
}
// ****** GRAPH ******* // ****** GRAPH *******
//log.debug("updateGUI checkpoint 1"); //log.debug("updateGUI checkpoint 1");

View file

@ -11,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
@ -155,7 +156,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
@Override @Override
public String getUnits() { public String getUnits() {
return profile.getUnits(); return profile != null ? profile.getUnits() : Constants.MGDL;
} }
@Override @Override

View file

@ -197,7 +197,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override @Override
public void refreshDataFromPump(String reason) { public void refreshDataFromPump(String reason) {
NSUpload.uploadDeviceStatus(); if (!BuildConfig.NSCLIENTOLNY)
NSUpload.uploadDeviceStatus();
lastDataTime = new Date(); lastDataTime = new Date();
} }

View file

@ -12,6 +12,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/** /**
* The Class DateUtil. A simple wrapper around SimpleDateFormat to ease the handling of iso date string &lt;-&gt; date obj * The Class DateUtil. A simple wrapper around SimpleDateFormat to ease the handling of iso date string &lt;-&gt; date obj
@ -111,4 +112,10 @@ public class DateUtil {
public static String dateAndTimeString(long mills) { public static String dateAndTimeString(long mills) {
return dateString(mills) + " " + timeString(mills); return dateString(mills) + " " + timeString(mills);
} }
public static String minAgo(long time) {
int mins = (int) ((System.currentTimeMillis() - time) / 1000 / 60);
return String.format(MainApp.sResources.getString(R.string.minago), mins);
}
} }

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper; import android.support.v7.view.ContextThemeWrapper;
import android.text.Spanned;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -41,4 +42,28 @@ public class OKDialog {
log.debug("show_dialog exception: " + e); log.debug("show_dialog exception: " + e);
} }
} }
public static void show(final Activity activity, String title, Spanned message, final Runnable runnable) {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme));
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (runnable != null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
activity.runOnUiThread(runnable);
}
}
});
builder.create().show();
} catch (Exception e) {
log.debug("show_dialog exception: " + e);
}
}
} }

View file

@ -400,6 +400,156 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/pump"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/overview_pump"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:text=""
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/openaps"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/overview_openaps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:text=""
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/uploader"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/overview_uploader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="start"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:text=""
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment"> tools:context="info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -653,4 +653,8 @@
<string name="key_do_not_track_profile_switch">do_not_track_profile_switch</string> <string name="key_do_not_track_profile_switch">do_not_track_profile_switch</string>
<string name="do_not_track_profile_switch">Ignore profile switch events</string> <string name="do_not_track_profile_switch">Ignore profile switch events</string>
<string name="do_not_track_profile_switch_summary">All profile switch events are ignoreg and active profile is always used</string> <string name="do_not_track_profile_switch_summary">All profile switch events are ignoreg and active profile is always used</string>
<string name="pump">Pump</string>
<string name="openaps">OpenAPS</string>
<string name="device">Device</string>
<string name="uploader">Uploader</string>
</resources> </resources>