Upload IOB to NS without available BG
This commit is contained in:
parent
034bf3ecd8
commit
e423b5bc06
4 changed files with 39 additions and 13 deletions
|
@ -381,13 +381,11 @@ public class DeviceStatus {
|
||||||
try {
|
try {
|
||||||
if (device != null) record.put("device", device);
|
if (device != null) record.put("device", device);
|
||||||
if (pump != null) record.put("pump", pump);
|
if (pump != null) record.put("pump", pump);
|
||||||
if (suggested != null) {
|
|
||||||
JSONObject openaps = new JSONObject();
|
JSONObject openaps = new JSONObject();
|
||||||
if (enacted != null) openaps.put("enacted", enacted);
|
if (enacted != null) openaps.put("enacted", enacted);
|
||||||
if (suggested != null) openaps.put("suggested", suggested);
|
if (suggested != null) openaps.put("suggested", suggested);
|
||||||
if (iob != null) openaps.put("iob", iob);
|
if (iob != null) openaps.put("iob", iob);
|
||||||
record.put("openaps", openaps);
|
record.put("openaps", openaps);
|
||||||
}
|
|
||||||
if (uploaderBattery != 0) record.put("uploaderBattery", uploaderBattery);
|
if (uploaderBattery != 0) record.put("uploaderBattery", uploaderBattery);
|
||||||
if (created_at != null) record.put("created_at", created_at);
|
if (created_at != null) record.put("created_at", created_at);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.content.pm.ResolveInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
@ -24,10 +25,8 @@ import java.util.Locale;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.services.Intents;
|
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
|
@ -35,11 +34,15 @@ import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
|
import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.DbLogger;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.DbLogger;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
|
import info.nightscout.androidaps.services.Intents;
|
||||||
import info.nightscout.androidaps.utils.BatteryLevel;
|
import info.nightscout.androidaps.utils.BatteryLevel;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
@ -246,7 +249,12 @@ public class NSUpload {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
log.debug("OpenAPS data too old to upload");
|
log.debug("OpenAPS data too old to upload, sending iob only");
|
||||||
|
IobTotal[] iob = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||||
|
if (iob.length > 0) {
|
||||||
|
deviceStatus.iob = iob[0].json();
|
||||||
|
deviceStatus.iob.put("time", DateUtil.toISOString(DateUtil.now()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
||||||
JSONObject pumpstatus = ConfigBuilderPlugin.getPlugin().getActivePump().getJSONStatus(profile, profileName);
|
JSONObject pumpstatus = ConfigBuilderPlugin.getPlugin().getActivePump().getJSONStatus(profile, profileName);
|
||||||
|
|
|
@ -11,14 +11,15 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.queue.commands.Command;
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
|
@ -34,6 +35,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
public static final long STATUS_UPDATE_FREQUENCY = T.mins(15).msecs();
|
public static final long STATUS_UPDATE_FREQUENCY = T.mins(15).msecs();
|
||||||
private static long lastReadStatus = 0;
|
private static long lastReadStatus = 0;
|
||||||
private static long lastRun = 0;
|
private static long lastRun = 0;
|
||||||
|
private static long lastIobUpload = 0;
|
||||||
|
|
||||||
public static void cancelAlarm(Context context) {
|
public static void cancelAlarm(Context context) {
|
||||||
Intent intent = new Intent(context, KeepAliveReceiver.class);
|
Intent intent = new Intent(context, KeepAliveReceiver.class);
|
||||||
|
@ -51,12 +53,25 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
LocalAlertUtils.shortenSnoozeInterval();
|
LocalAlertUtils.shortenSnoozeInterval();
|
||||||
LocalAlertUtils.checkStaleBGAlert();
|
LocalAlertUtils.checkStaleBGAlert();
|
||||||
checkPump();
|
checkPump();
|
||||||
|
checkAPS();
|
||||||
|
|
||||||
if (L.isEnabled(L.CORE))
|
if (L.isEnabled(L.CORE))
|
||||||
log.debug("KeepAlive received");
|
log.debug("KeepAlive received");
|
||||||
wl.release();
|
wl.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAPS() {
|
||||||
|
APSInterface usedAPS = ConfigBuilderPlugin.getPlugin().getActiveAPS();
|
||||||
|
boolean shouldUploadStatus = false;
|
||||||
|
if (usedAPS == null) shouldUploadStatus = true;
|
||||||
|
else if (DateUtil.isOlderThan(usedAPS.getLastAPSRun(), 5)) shouldUploadStatus = true;
|
||||||
|
|
||||||
|
if (DateUtil.isOlderThan(lastIobUpload, 5) && shouldUploadStatus) {
|
||||||
|
lastIobUpload = DateUtil.now();
|
||||||
|
NSUpload.uploadDeviceStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkPump() {
|
private void checkPump() {
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||||
|
|
|
@ -217,6 +217,11 @@ public class DateUtil {
|
||||||
return diff < T.mins(2).msecs();
|
return diff < T.mins(2).msecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isOlderThan(long date, long minutes) {
|
||||||
|
long diff = now() - date;
|
||||||
|
return diff > T.mins(minutes).msecs();
|
||||||
|
}
|
||||||
|
|
||||||
public static GregorianCalendar gregorianCalendar() {
|
public static GregorianCalendar gregorianCalendar() {
|
||||||
return new GregorianCalendar();
|
return new GregorianCalendar();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue