get rid of Date.class

This commit is contained in:
Milos Kozak 2018-08-17 15:11:43 +02:00
parent 15e69a478e
commit 1d67f124fc
53 changed files with 448 additions and 527 deletions

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.interfaces; package info.nightscout.androidaps.interfaces;
import java.util.Date;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
/** /**
@ -9,7 +7,7 @@ import info.nightscout.androidaps.plugins.Loop.APSResult;
*/ */
public interface APSInterface { public interface APSInterface {
public APSResult getLastAPSResult(); public APSResult getLastAPSResult();
public Date getLastAPSRun(); public long getLastAPSRun();
public void invoke(String initiator, boolean tempBasalFallback); public void invoke(String initiator, boolean tempBasalFallback);
} }

View file

@ -2,8 +2,6 @@ package info.nightscout.androidaps.interfaces;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
@ -29,7 +27,7 @@ public interface PumpInterface {
PumpEnactResult setNewBasalProfile(Profile profile); PumpEnactResult setNewBasalProfile(Profile profile);
boolean isThisProfileSet(Profile profile); boolean isThisProfileSet(Profile profile);
Date lastDataTime(); long lastDataTime();
double getBaseBasalRate(); // base basal rate, not temp basal double getBaseBasalRate(); // base basal rate, not temp basal

View file

@ -12,7 +12,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
@ -324,7 +323,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
getBGDataFrom = Math.max(oldestDataAvailable, (long) (from - T.hours(1).msecs() * (24 + dia))); getBGDataFrom = Math.max(oldestDataAvailable, (long) (from - T.hours(1).msecs() * (24 + dia)));
if (getBGDataFrom == oldestDataAvailable) if (getBGDataFrom == oldestDataAvailable)
if (L.isEnabled(L.AUTOSENS)) if (L.isEnabled(L.AUTOSENS))
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); log.debug("Limiting data to oldest available temps: " + DateUtil.dateAndTimeFullString(oldestDataAvailable));
} else } else
getBGDataFrom = (long) (from - T.hours(1).msecs() * (24 + dia)); getBGDataFrom = (long) (from - T.hours(1).msecs() * (24 + dia));
return getBGDataFrom; return getBGDataFrom;
@ -685,11 +684,11 @@ public class IobCobCalculatorPlugin extends PluginBase {
// clear up 5 min back for proper COB calculation // clear up 5 min back for proper COB calculation
long time = ev.time - 5 * 60 * 1000L; long time = ev.time - 5 * 60 * 1000L;
if (L.isEnabled(L.AUTOSENS)) if (L.isEnabled(L.AUTOSENS))
log.debug("Invalidating cached data to: " + new Date(time).toLocaleString()); log.debug("Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
for (int index = iobTable.size() - 1; index >= 0; index--) { for (int index = iobTable.size() - 1; index >= 0; index--) {
if (iobTable.keyAt(index) > time) { if (iobTable.keyAt(index) > time) {
if (L.isEnabled(L.AUTOSENS)) if (L.isEnabled(L.AUTOSENS))
log.debug("Removing from iobTable: " + new Date(iobTable.keyAt(index)).toLocaleString()); log.debug("Removing from iobTable: " + DateUtil.dateAndTimeFullString(iobTable.keyAt(index)));
iobTable.removeAt(index); iobTable.removeAt(index);
} else { } else {
break; break;
@ -698,7 +697,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
for (int index = autosensDataTable.size() - 1; index >= 0; index--) { for (int index = autosensDataTable.size() - 1; index >= 0; index--) {
if (autosensDataTable.keyAt(index) > time) { if (autosensDataTable.keyAt(index) > time) {
if (L.isEnabled(L.AUTOSENS)) if (L.isEnabled(L.AUTOSENS))
log.debug("Removing from autosensDataTable: " + new Date(autosensDataTable.keyAt(index)).toLocaleString()); log.debug("Removing from autosensDataTable: " + DateUtil.dateAndTimeFullString(autosensDataTable.keyAt(index)));
autosensDataTable.removeAt(index); autosensDataTable.removeAt(index);
} else { } else {
break; break;
@ -707,7 +706,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
for (int index = basalDataTable.size() - 1; index >= 0; index--) { for (int index = basalDataTable.size() - 1; index >= 0; index--) {
if (basalDataTable.keyAt(index) > time) { if (basalDataTable.keyAt(index) > time) {
if (L.isEnabled(L.AUTOSENS)) if (L.isEnabled(L.AUTOSENS))
log.debug("Removing from basalDataTable: " + new Date(basalDataTable.keyAt(index)).toLocaleString()); log.debug("Removing from basalDataTable: " + DateUtil.dateAndTimeFullString(basalDataTable.keyAt(index)));
basalDataTable.removeAt(index); basalDataTable.removeAt(index);
} else { } else {
break; break;

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.JSONFormatter; import info.nightscout.utils.JSONFormatter;
@ -108,8 +109,8 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam())); mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug()); scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
} }
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != null) { if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != 0) {
lastRunView.setText(OpenAPSAMAPlugin.getPlugin().lastAPSRun.toLocaleString()); lastRunView.setText(DateUtil.dateAndTimeFullString(OpenAPSAMAPlugin.getPlugin().lastAPSRun));
} }
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) { if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json())); autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));

View file

@ -4,8 +4,6 @@ import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
@ -52,11 +50,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
// last values // last values
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null; DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
Date lastAPSRun = null; long lastAPSRun = 0;
DetermineBasalResultAMA lastAPSResult = null; DetermineBasalResultAMA lastAPSResult = null;
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
public OpenAPSAMAPlugin() { private OpenAPSAMAPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSAMAFragment.class.getName()) .fragmentClass(OpenAPSAMAFragment.class.getName())
@ -85,7 +83,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
} }
@Override @Override
public Date getLastAPSRun() { public long getLastAPSRun() {
return lastAPSRun; return lastAPSRun;
} }
@ -132,13 +130,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
minBg = Round.roundTo(minBg, 0.1d); minBg = Round.roundTo(minBg, 0.1d);
maxBg = Round.roundTo(maxBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d);
Date start = new Date(); long start = System.currentTimeMillis();
Date startPart = new Date(); long startPart = System.currentTimeMillis();
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile); IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "calculateIobArrayInDia()", startPart); Profiler.log(log, "calculateIobArrayInDia()", startPart);
startPart = new Date(); startPart = System.currentTimeMillis();
MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "getMealData()", startPart); Profiler.log(log, "getMealData()", startPart);
@ -170,7 +168,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
if (!HardLimits.checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) if (!HardLimits.checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal()))
return; return;
startPart = new Date(); startPart = System.currentTimeMillis();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin"); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
if (autosensData == null) { if (autosensData == null) {
@ -187,7 +185,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "AMA data gathering", start); Profiler.log(log, "AMA data gathering", start);
start = new Date(); start = System.currentTimeMillis();
try { try {
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData, determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
@ -219,7 +217,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
determineBasalResultAMA.iob = iobArray[0]; determineBasalResultAMA.iob = iobArray[0];
Date now = new Date(); long now = System.currentTimeMillis();
try { try {
determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now));

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.JSONFormatter; import info.nightscout.utils.JSONFormatter;
@ -94,8 +95,8 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam())); profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam())); mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam()));
} }
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != null) { if (OpenAPSMAPlugin.getPlugin().lastAPSRun != 0) {
lastRunView.setText(OpenAPSMAPlugin.getPlugin().lastAPSRun.toLocaleString()); lastRunView.setText(DateUtil.dateAndTimeFullString(OpenAPSMAPlugin.getPlugin().lastAPSRun));
} }
}); });
} }

View file

@ -4,8 +4,6 @@ import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
@ -52,10 +50,10 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
// last values // last values
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null; DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
Date lastAPSRun = null; long lastAPSRun = 0;
DetermineBasalResultMA lastAPSResult = null; DetermineBasalResultMA lastAPSResult = null;
public OpenAPSMAPlugin() { private OpenAPSMAPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSMAFragment.class.getName()) .fragmentClass(OpenAPSMAFragment.class.getName())
@ -84,7 +82,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
} }
@Override @Override
public Date getLastAPSRun() { public long getLastAPSRun() {
return lastAPSRun; return lastAPSRun;
} }
@ -93,7 +91,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback); log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null; lastAPSResult = null;
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = null; DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext())); determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
@ -132,7 +130,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
minBg = Round.roundTo(minBg, 0.1d); minBg = Round.roundTo(minBg, 0.1d);
maxBg = Round.roundTo(maxBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d);
Date start = new Date(); long start = System.currentTimeMillis();
TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); TreatmentsPlugin.getPlugin().updateTotalIOBTreatments();
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments(); IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments();
@ -159,7 +157,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA)) if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA))
return; return;
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
return; return;
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
return; return;
@ -168,7 +166,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal()))
return; return;
start = new Date(); start = System.currentTimeMillis();
try { try {
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData); determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
} catch (JSONException e) { } catch (JSONException e) {
@ -205,7 +203,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
lastAPSResult = determineBasalResultMA; lastAPSResult = determineBasalResultMA;
lastAPSRun = new Date(now); lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); MainApp.bus().post(new EventOpenAPSUpdateGui());
} }

View file

@ -25,6 +25,7 @@ import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.JSONFormatter; import info.nightscout.utils.JSONFormatter;
@ -111,8 +112,8 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
if (lastAPSResult != null && lastAPSResult.inputConstraints != null) if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim()); constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
} }
if (plugin.lastAPSRun != null) { if (plugin.lastAPSRun != 0) {
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim()); lastRunView.setText(DateUtil.dateAndTimeFullString(plugin.lastAPSRun));
} }
if (plugin.lastAutosensResult != null) { if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim()); autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());

View file

@ -55,7 +55,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
// last values // last values
DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null; DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null;
Date lastAPSRun = null; long lastAPSRun = 0;
DetermineBasalResultSMB lastAPSResult = null; DetermineBasalResultSMB lastAPSResult = null;
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
@ -88,7 +88,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
} }
@Override @Override
public Date getLastAPSRun() { public long getLastAPSRun() {
return lastAPSRun; return lastAPSRun;
} }
@ -139,13 +139,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
minBg = Round.roundTo(minBg, 0.1d); minBg = Round.roundTo(minBg, 0.1d);
maxBg = Round.roundTo(maxBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d);
Date start = new Date(); long start = System.currentTimeMillis();
Date startPart = new Date(); long startPart = System.currentTimeMillis();
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(profile); IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(profile);
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "calculateIobArrayInDia()", startPart); Profiler.log(log, "calculateIobArrayInDia()", startPart);
startPart = new Date(); startPart = System.currentTimeMillis();
MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "getMealData()", startPart); Profiler.log(log, "getMealData()", startPart);
@ -177,7 +177,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal()))
return; return;
startPart = new Date(); startPart = System.currentTimeMillis();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin"); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
if (autosensData == null) { if (autosensData == null) {
@ -203,7 +203,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
Profiler.log(log, "SMB data gathering", start); Profiler.log(log, "SMB data gathering", start);
start = new Date(); start = System.currentTimeMillis();
try { try {
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData, determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
lastAutosensResult.ratio, //autosensDataRatio lastAutosensResult.ratio, //autosensDataRatio
@ -248,7 +248,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS; lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
lastAPSResult = determineBasalResultSMB; lastAPSResult = determineBasalResultSMB;
lastAPSRun = new Date(now); lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); MainApp.bus().post(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json; //deviceStatus.suggested = determineBasalResultAMA.json;

View file

@ -66,6 +66,7 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
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.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.events.EventCareportalEventChange;
import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventInitializationChanged;
@ -86,7 +87,6 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
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.ConstraintsObjectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
@ -95,6 +95,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalcul
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
@ -111,14 +112,12 @@ import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
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.utils.DefaultValueHelper; import info.nightscout.utils.DefaultValueHelper;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.utils.OKDialog; import info.nightscout.utils.OKDialog;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -189,8 +188,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
Handler sLoopHandler = new Handler(); Handler sLoopHandler = new Handler();
Runnable sRefreshLoop = null; Runnable sRefreshLoop = null;
final Object updateSync = new Object();
public enum CHARTTYPE {PRE, BAS, IOB, COB, DEV, SEN, DEVSLOPE} public enum CHARTTYPE {PRE, BAS, IOB, COB, DEV, SEN, DEVSLOPE}
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
@ -320,15 +317,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6); rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6);
bgGraph.setOnLongClickListener(new View.OnLongClickListener() { bgGraph.setOnLongClickListener(v -> {
@Override
public boolean onLongClick(View v) {
rangeToDisplay += 6; rangeToDisplay += 6;
rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay; rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay;
SP.putInt(R.string.key_rangetodisplay, rangeToDisplay); SP.putInt(R.string.key_rangetodisplay, rangeToDisplay);
updateGUI("rangeChange"); updateGUI("rangeChange");
return false; return false;
}
}); });
setupChartMenu(view); setupChartMenu(view);
@ -338,9 +332,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
private void setupChartMenu(View view) { private void setupChartMenu(View view) {
chartButton = (ImageButton) view.findViewById(R.id.overview_chartMenuButton); chartButton = (ImageButton) view.findViewById(R.id.overview_chartMenuButton);
chartButton.setOnClickListener(new View.OnClickListener() { chartButton.setOnClickListener(v -> {
@Override
public void onClick(View v) {
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
boolean predictionsAvailable; boolean predictionsAvailable;
if (Config.APS) if (Config.APS)
@ -445,7 +437,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
}); });
popup.show(); popup.show();
}
}); });
} }
@ -638,8 +629,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean xdrip = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginType.BGSOURCE); boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE);
boolean g5 = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginType.BGSOURCE); boolean g5 = SourceDexcomG5Plugin.getPlugin().isEnabled(PluginType.BGSOURCE);
String units = ProfileFunctions.getInstance().getProfileUnits(); String units = ProfileFunctions.getInstance().getProfileUnits();
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
@ -1027,7 +1018,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void updateGUI(final String from) { public void updateGUI(final String from) {
if (L.isEnabled(L.OVERVIEW)) if (L.isEnabled(L.OVERVIEW))
log.debug("updateGUI entered from: " + from); log.debug("updateGUI entered from: " + from);
final Date updateGUIStart = new Date(); final long updateGUIStart = System.currentTimeMillis();
if (getActivity() == null) if (getActivity() == null)
return; return;

View file

@ -355,8 +355,8 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
@NonNull @NonNull
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return new Date(pump.lastSuccessfulCmdTime); return pump.lastSuccessfulCmdTime;
} }
/** /**

View file

@ -143,8 +143,8 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
} }
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return new Date(DanaRPump.getInstance().lastConnection); return DanaRPump.getInstance().lastConnection;
} }
@Override @Override
@ -333,8 +333,8 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
status.put("timestamp", DateUtil.toISOString(pump.lastConnection)); status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", pump.iob); extended.put("PumpIOB", pump.iob);
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime != 0) {
extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolus", DateUtil.dateAndTimeFullString(pump.lastBolusTime));
extended.put("LastBolusAmount", pump.lastBolusAmount); extended.put("LastBolusAmount", pump.lastBolusAmount);
} }
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); TemporaryBasal tb = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now);
@ -441,7 +441,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n"; ret += "LastConn: " + agoMin + " minago\n";
} }
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.PumpDanaR; package info.nightscout.androidaps.plugins.PumpDanaR;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -27,6 +26,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.TDDStatsActivity; import info.nightscout.androidaps.activities.TDDStatsActivity;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
@ -157,9 +157,7 @@ public class DanaRFragment extends SubscriberFragment {
final String status = c.textStatus(); final String status = c.textStatus();
if (activity != null) { if (activity != null) {
activity.runOnUiThread( activity.runOnUiThread(
new Runnable() { () -> {
@Override
public void run() {
synchronized (DanaRFragment.this) { synchronized (DanaRFragment.this) {
if (btConnectionView == null || pumpStatusView == null || pumpStatusLayout == null) if (btConnectionView == null || pumpStatusView == null || pumpStatusLayout == null)
@ -180,7 +178,6 @@ public class DanaRFragment extends SubscriberFragment {
} }
} }
} }
}
); );
} }
} }
@ -210,10 +207,7 @@ public class DanaRFragment extends SubscriberFragment {
protected void updateGUI() { protected void updateGUI() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null && basaBasalRateView != null) if (activity != null && basaBasalRateView != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@SuppressLint("SetTextI18n")
@Override
public void run() {
synchronized (DanaRFragment.this) { synchronized (DanaRFragment.this) {
if (!isBound()) return; if (!isBound()) return;
@ -224,11 +218,11 @@ public class DanaRFragment extends SubscriberFragment {
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")"); lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d); SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
} }
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime(); Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime;
double agoHours = agoMsec / 60d / 60d / 1000d; double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U"); lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText(""); else lastBolusView.setText("");
} }
@ -244,8 +238,9 @@ public class DanaRFragment extends SubscriberFragment {
} }
} else { } else {
// v2 plugin // v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); if (tb != null) {
tempBasalView.setText(tb.toStringFull());
} else { } else {
tempBasalView.setText(""); tempBasalView.setText("");
} }
@ -279,12 +274,11 @@ public class DanaRFragment extends SubscriberFragment {
} }
} }
//hide user options button if not an RS pump //hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP); boolean isKorean = DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP);
if (isKorean) { if (isKorean) {
danar_user_options.setVisibility(View.GONE); danar_user_options.setVisibility(View.GONE);
} }
} }
}
}); });
} }

View file

@ -65,11 +65,11 @@ public class DanaRPump {
// Info // Info
public String serialNumber = ""; public String serialNumber = "";
public Date shippingDate = new Date(0); public long shippingDate = 0;
public String shippingCountry = ""; public String shippingCountry = "";
public boolean isNewPump = true; public boolean isNewPump = true;
public int password = -1; public int password = -1;
public Date pumpTime = new Date(0); public long pumpTime = 0;
public static final int DOMESTIC_MODEL = 0x01; public static final int DOMESTIC_MODEL = 0x01;
public static final int EXPORT_MODEL = 0x03; public static final int EXPORT_MODEL = 0x03;
@ -98,7 +98,7 @@ public class DanaRPump {
public int batteryRemaining; public int batteryRemaining;
public boolean bolusBlocked; public boolean bolusBlocked;
public Date lastBolusTime = new Date(0); public long lastBolusTime = 0;
public double lastBolusAmount; public double lastBolusAmount;
public double currentBasal; public double currentBasal;
@ -107,7 +107,7 @@ public class DanaRPump {
public int tempBasalPercent; public int tempBasalPercent;
public int tempBasalRemainingMin; public int tempBasalRemainingMin;
public int tempBasalTotalSec; public int tempBasalTotalSec;
public Date tempBasalStart; public long tempBasalStart;
public boolean isDualBolusInProgress; public boolean isDualBolusInProgress;
public boolean isExtendedInProgress; public boolean isExtendedInProgress;
@ -115,7 +115,7 @@ public class DanaRPump {
public double extendedBolusAmount; public double extendedBolusAmount;
public double extendedBolusAbsoluteRate; public double extendedBolusAbsoluteRate;
public int extendedBolusSoFarInMinutes; public int extendedBolusSoFarInMinutes;
public Date extendedBolusStart; public long extendedBolusStart;
public int extendedBolusRemainingMinutes; public int extendedBolusRemainingMinutes;
public double extendedBolusDeliveredSoFar; //RS only public double extendedBolusDeliveredSoFar; //RS only

View file

@ -1,8 +1,6 @@
package info.nightscout.androidaps.plugins.PumpDanaR.Dialogs; package info.nightscout.androidaps.plugins.PumpDanaR.Dialogs;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -10,22 +8,12 @@ import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;

View file

@ -129,8 +129,8 @@ public class MessageBase {
return 0; return 0;
} }
public static Date dateTimeFromBuff(byte[] buff, int offset) { public static long dateTimeFromBuff(byte[] buff, int offset) {
Date date = return
new Date( new Date(
100 + intFromBuff(buff, offset, 1), 100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1, intFromBuff(buff, offset + 1, 1) - 1,
@ -138,8 +138,7 @@ public class MessageBase {
intFromBuff(buff, offset + 3, 1), intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1), intFromBuff(buff, offset + 4, 1),
0 0
); ).getTime();
return date;
} }
public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) { public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
@ -154,14 +153,13 @@ public class MessageBase {
).getTime(); ).getTime();
} }
public static Date dateFromBuff(byte[] buff, int offset) { public static long dateFromBuff(byte[] buff, int offset) {
Date date = return
new Date( new Date(
100 + intFromBuff(buff, offset, 1), 100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1, intFromBuff(buff, offset + 1, 1) - 1,
intFromBuff(buff, offset + 2, 1) intFromBuff(buff, offset + 2, 1)
); ).getTime();
return date;
} }
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)

View file

@ -23,8 +23,8 @@ public class MsgHistoryAll extends MessageBase {
@Override @Override
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
byte recordCode = (byte) intFromBuff(bytes, 0, 1); byte recordCode = (byte) intFromBuff(bytes, 0, 1);
Date date = dateFromBuff(bytes, 1); // 3 bytes long date = dateFromBuff(bytes, 1); // 3 bytes
Date datetime = dateTimeFromBuff(bytes, 1); // 5 bytes long datetime = dateTimeFromBuff(bytes, 1); // 5 bytes
long datetimewihtsec = dateTimeSecFromBuff(bytes, 1); // 6 bytes long datetimewihtsec = dateTimeSecFromBuff(bytes, 1); // 6 bytes
double dailyBasal = intFromBuff(bytes, 4, 2) * 0.01d; double dailyBasal = intFromBuff(bytes, 4, 2) * 0.01d;
@ -46,7 +46,7 @@ public class MsgHistoryAll extends MessageBase {
switch (recordCode) { switch (recordCode) {
case RecordTypes.RECORD_TYPE_BOLUS: case RecordTypes.RECORD_TYPE_BOLUS:
danaRHistoryRecord.recordDate = datetime.getTime(); danaRHistoryRecord.recordDate = datetime;
switch (0xF0 & paramByte8) { switch (0xF0 & paramByte8) {
case 0xA0: case 0xA0:
danaRHistoryRecord.bolusType = "DS"; danaRHistoryRecord.bolusType = "DS";
@ -73,7 +73,7 @@ public class MsgHistoryAll extends MessageBase {
break; break;
case RecordTypes.RECORD_TYPE_DAILY: case RecordTypes.RECORD_TYPE_DAILY:
messageType += "dailyinsulin"; messageType += "dailyinsulin";
danaRHistoryRecord.recordDate = date.getTime(); danaRHistoryRecord.recordDate = date;
danaRHistoryRecord.recordDailyBasal = dailyBasal; danaRHistoryRecord.recordDailyBasal = dailyBasal;
danaRHistoryRecord.recordDailyBolus = dailyBolus; danaRHistoryRecord.recordDailyBolus = dailyBolus;
break; break;

View file

@ -7,6 +7,7 @@ import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.DateUtil;
public class MsgSettingPumpTime extends MessageBase { public class MsgSettingPumpTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -18,7 +19,7 @@ public class MsgSettingPumpTime extends MessageBase {
} }
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
Date time = long time =
new Date( new Date(
100 + intFromBuff(bytes, 5, 1), 100 + intFromBuff(bytes, 5, 1),
intFromBuff(bytes, 4, 1) - 1, intFromBuff(bytes, 4, 1) - 1,
@ -26,10 +27,10 @@ public class MsgSettingPumpTime extends MessageBase {
intFromBuff(bytes, 2, 1), intFromBuff(bytes, 2, 1),
intFromBuff(bytes, 1, 1), intFromBuff(bytes, 1, 1),
intFromBuff(bytes, 0, 1) intFromBuff(bytes, 0, 1)
); ).getTime();
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Pump time: " + time + " Phone time: " + new Date()); log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time) + " Phone time: " + new Date());
DanaRPump.getInstance().pumpTime = time; DanaRPump.getInstance().pumpTime = time;
} }

View file

@ -5,14 +5,13 @@ import android.support.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
public class MsgStatusBolusExtended extends MessageBase { public class MsgStatusBolusExtended extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -36,7 +35,7 @@ public class MsgStatusBolusExtended extends MessageBase {
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60; int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d; double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0); long extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : 0;
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes; int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
@ -56,14 +55,14 @@ public class MsgStatusBolusExtended extends MessageBase {
log.debug("Extended bolus amount: " + extendedBolusAmount); log.debug("Extended bolus amount: " + extendedBolusAmount);
log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes); log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes);
log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate); log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate);
log.debug("Extended bolus start: " + extendedBolusStart); log.debug("Extended bolus start: " + DateUtil.dateAndTimeFullString(extendedBolusStart));
log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes); log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes);
} }
} }
@NonNull @NonNull
private Date getDateFromSecAgo(int tempBasalAgoSecs) { private long getDateFromSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
} }
public static void updateExtendedBolusInDB() { public static void updateExtendedBolusInDB() {
@ -76,12 +75,12 @@ public class MsgStatusBolusExtended extends MessageBase {
if (pump.isExtendedInProgress) { if (pump.isExtendedInProgress) {
if (extendedBolus.absoluteRate() != pump.extendedBolusAbsoluteRate) { if (extendedBolus.absoluteRate() != pump.extendedBolusAbsoluteRate) {
// Close current extended // Close current extended
ExtendedBolus exStop = new ExtendedBolus(pump.extendedBolusStart.getTime() - 1000); ExtendedBolus exStop = new ExtendedBolus(pump.extendedBolusStart - 1000);
exStop.source = Source.USER; exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop); treatmentsInterface.addToHistoryExtendedBolus(exStop);
// Create new // Create new
ExtendedBolus newExtended = new ExtendedBolus(); ExtendedBolus newExtended = new ExtendedBolus();
newExtended.date = pump.extendedBolusStart.getTime(); newExtended.date = pump.extendedBolusStart;
newExtended.insulin = pump.extendedBolusAmount; newExtended.insulin = pump.extendedBolusAmount;
newExtended.durationInMinutes = pump.extendedBolusMinutes; newExtended.durationInMinutes = pump.extendedBolusMinutes;
newExtended.source = Source.USER; newExtended.source = Source.USER;
@ -97,7 +96,7 @@ public class MsgStatusBolusExtended extends MessageBase {
if (pump.isExtendedInProgress) { if (pump.isExtendedInProgress) {
// Create new // Create new
ExtendedBolus newExtended = new ExtendedBolus(); ExtendedBolus newExtended = new ExtendedBolus();
newExtended.date = pump.extendedBolusStart.getTime(); newExtended.date = pump.extendedBolusStart;
newExtended.insulin = pump.extendedBolusAmount; newExtended.insulin = pump.extendedBolusAmount;
newExtended.durationInMinutes = pump.extendedBolusMinutes; newExtended.durationInMinutes = pump.extendedBolusMinutes;
newExtended.source = Source.USER; newExtended.source = Source.USER;

View file

@ -5,8 +5,6 @@ import android.support.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
@ -33,7 +31,7 @@ public class MsgStatusTempBasal extends MessageBase {
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60; else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3); int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60; int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0); long tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : 0;
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
pump.isTempBasalInProgress = isTempBasalInProgress; pump.isTempBasalInProgress = isTempBasalInProgress;
@ -55,8 +53,8 @@ public class MsgStatusTempBasal extends MessageBase {
} }
@NonNull @NonNull
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) { private long getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
} }
public static void updateTempBasalInDB() { public static void updateTempBasalInDB() {
@ -68,11 +66,11 @@ public class MsgStatusTempBasal extends MessageBase {
if (danaRPump.isTempBasalInProgress) { if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percentRate != danaRPump.tempBasalPercent) { if (tempBasal.percentRate != danaRPump.tempBasalPercent) {
// Close current temp basal // Close current temp basal
TemporaryBasal tempStop = new TemporaryBasal().date(danaRPump.tempBasalStart.getTime() - 1000).source(Source.USER); TemporaryBasal tempStop = new TemporaryBasal().date(danaRPump.tempBasalStart - 1000).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
// Create new // Create new
TemporaryBasal newTempBasal = new TemporaryBasal() TemporaryBasal newTempBasal = new TemporaryBasal()
.date(danaRPump.tempBasalStart.getTime()) .date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent) .percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60) .duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER); .source(Source.USER);
@ -87,7 +85,7 @@ public class MsgStatusTempBasal extends MessageBase {
if (danaRPump.isTempBasalInProgress) { if (danaRPump.isTempBasalInProgress) {
// Create new // Create new
TemporaryBasal newTempBasal = new TemporaryBasal() TemporaryBasal newTempBasal = new TemporaryBasal()
.date(danaRPump.tempBasalStart.getTime()) .date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent) .percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60) .duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER); .source(Source.USER);

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
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.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
@ -63,7 +64,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class DanaRExecutionService extends AbstractDanaRExecutionService { public class DanaRExecutionService extends AbstractDanaRExecutionService {
@ -109,9 +110,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
if (mConnectionInProgress) if (mConnectionInProgress)
return; return;
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
mConnectionInProgress = true; mConnectionInProgress = true;
getBTSocketForSelectedPump(); getBTSocketForSelectedPump();
if (mRfcommSocket == null || mBTDevice == null) { if (mRfcommSocket == null || mBTDevice == null) {
@ -137,7 +136,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
} }
mConnectionInProgress = false; mConnectionInProgress = false;
}
}).start(); }).start();
} }
@ -193,13 +191,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingUserOptions()); mSerialIOThread.sendMessage(new MsgSettingUserOptions());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) { if (Math.abs(timeDiff) > 10) {
mSerialIOThread.sendMessage(new MsgSetTime(new Date())); mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
} }
@ -344,13 +342,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
ConfigBuilderPlugin.getCommandQueue().independentConnect("bolusingInterrupted", new Callback() { ConfigBuilderPlugin.getCommandQueue().independentConnect("bolusingInterrupted", new Callback() {
@Override @Override
public void run() { public void run() {
if (mDanaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old if (mDanaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
t.insulin = mDanaRPump.lastBolusAmount; t.insulin = mDanaRPump.lastBolusAmount;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Used bolus amount from history: " + mDanaRPump.lastBolusAmount); log.debug("Used bolus amount from history: " + mDanaRPump.lastBolusAmount);
} else { } else {
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Bolus amount in history too old: " + mDanaRPump.lastBolusTime.toLocaleString()); log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(mDanaRPump.lastBolusTime));
} }
synchronized (o) { synchronized (o) {
o.notify(); o.notify();

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;

View file

@ -191,13 +191,13 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) { if (Math.abs(timeDiff) > 10) {
mSerialIOThread.sendMessage(new MsgSetTime(new Date())); mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
} }
@ -282,7 +282,6 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (amount > 0) { if (amount > 0) {
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
long bolusStart = System.currentTimeMillis();
if (!stop.stopped) { if (!stop.stopped) {
mSerialIOThread.sendMessage(start); mSerialIOThread.sendMessage(start);

View file

@ -16,8 +16,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.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -380,8 +378,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return new Date(DanaRPump.getInstance().lastConnection); return DanaRPump.getInstance().lastConnection;
} }
@Override @Override
@ -725,8 +723,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
status.put("timestamp", DateUtil.toISOString(pump.lastConnection)); status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", pump.iob); extended.put("PumpIOB", pump.iob);
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime != 0) {
extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolus", DateUtil.dateAndTimeFullString(pump.lastBolusTime));
extended.put("LastBolusAmount", pump.lastBolusAmount); extended.put("LastBolusAmount", pump.lastBolusAmount);
} }
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now);
@ -777,7 +775,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n"; ret += "LastConn: " + agoMin + " minago\n";
} }
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());

View file

@ -142,14 +142,13 @@ public class DanaRS_Packet {
return new String(strbuff, StandardCharsets.UTF_8); return new String(strbuff, StandardCharsets.UTF_8);
} }
public static Date dateFromBuff(byte[] buff, int offset) { public static long dateFromBuff(byte[] buff, int offset) {
Date date = return
new Date( new Date(
100 + byteArrayToInt(getBytes(buff, offset, 1)), 100 + byteArrayToInt(getBytes(buff, offset, 1)),
byteArrayToInt(getBytes(buff, offset + 1, 1)) - 1, byteArrayToInt(getBytes(buff, offset + 1, 1)) - 1,
byteArrayToInt(getBytes(buff, offset + 2, 1)) byteArrayToInt(getBytes(buff, offset + 2, 1))
); ).getTime();
return date;
} }
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)

View file

@ -7,10 +7,9 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.DateUtil;
public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet { public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -55,7 +54,7 @@ public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet
dataSize = 2; dataSize = 2;
int runningMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)); int runningMin = byteArrayToInt(getBytes(data, dataIndex, dataSize));
int tempBasalRemainingMin = (pump.tempBasalTotalSec - runningMin * 60) / 60; int tempBasalRemainingMin = (pump.tempBasalTotalSec - runningMin * 60) / 60;
Date tempBasalStart = pump.isTempBasalInProgress ? getDateFromTempBasalSecAgo(runningMin * 60) : new Date(0); long tempBasalStart = pump.isTempBasalInProgress ? getDateFromTempBasalSecAgo(runningMin * 60) : 0;
if (L.isEnabled(L.PUMPCOMM)) { if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Error code: " + error); log.debug("Error code: " + error);
@ -64,7 +63,7 @@ public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet
log.debug("Current temp basal percent: " + pump.tempBasalPercent); log.debug("Current temp basal percent: " + pump.tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin); log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + pump.tempBasalTotalSec); log.debug("Current temp basal total sec: " + pump.tempBasalTotalSec);
log.debug("Current temp basal start: " + tempBasalStart); log.debug("Current temp basal start: " + DateUtil.dateAndTimeFullString(tempBasalStart));
} }
} }
@ -74,8 +73,8 @@ public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet
} }
@NonNull @NonNull
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) { private long getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
} }
} }

View file

@ -9,6 +9,7 @@ import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.DateUtil;
public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packet { public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -36,14 +37,16 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
dataSize = 2; dataSize = 2;
pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
pump.lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today Date lbt = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 1; dataSize = 1;
pump.lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize))); lbt.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 1; dataSize = 1;
pump.lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize))); lbt.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
pump.lastBolusTime = lbt.getTime();
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 2; dataSize = 2;
@ -56,13 +59,13 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 1; dataSize = 1;
pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
if ( error != 0) if (error != 0)
failed = true; failed = true;
if (L.isEnabled(L.PUMPCOMM)) { if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Result: " + error); log.debug("Result: " + error);
log.debug("BolusType: " + bolusType); log.debug("BolusType: " + bolusType);
log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U"); log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U");
log.debug("Last bolus time: " + pump.lastBolusTime.toLocaleString()); log.debug("Last bolus time: " + DateUtil.dateAndTimeFullString(pump.lastBolusTime));
log.debug("Last bolus amount: " + pump.lastBolusAmount); log.debug("Last bolus amount: " + pump.lastBolusAmount);
log.debug("Max bolus: " + pump.maxBolus + " U"); log.debug("Max bolus: " + pump.maxBolus + " U");
log.debug("Bolus step: " + pump.bolusStep + " U"); log.debug("Bolus step: " + pump.bolusStep + " U");

View file

@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.DateUtil;
public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packet { public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -20,7 +21,7 @@ public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packe
@Override @Override
public void handleMessage(byte[] data) { public void handleMessage(byte[] data) {
if (data.length < 18){ if (data.length < 18) {
failed = true; failed = true;
return; return;
} }
@ -40,7 +41,7 @@ public class DanaRS_Packet_General_Get_Shipping_Information extends DanaRS_Packe
if (L.isEnabled(L.PUMPCOMM)) { if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Serial number: " + pump.serialNumber); log.debug("Serial number: " + pump.serialNumber);
log.debug("Shipping date: " + pump.shippingDate); log.debug("Shipping date: " + DateUtil.dateAndTimeString(pump.shippingDate));
log.debug("Shipping country: " + pump.shippingCountry); log.debug("Shipping country: " + pump.shippingCountry);
} }
} }

View file

@ -33,11 +33,11 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
totalCount = 0; totalCount = 0;
} }
public DanaRS_Packet_History_(Date from) { public DanaRS_Packet_History_(long from) {
this(); this();
GregorianCalendar cal = new GregorianCalendar(); GregorianCalendar cal = new GregorianCalendar();
if (from.getTime() != 0) if (from != 0)
cal.setTime(from); cal.setTimeInMillis(from);
else else
cal.set(2000, 0, 1, 0, 0, 0); cal.set(2000, 0, 1, 0, 0, 0);
year = cal.get(Calendar.YEAR) - 1900 - 100; year = cal.get(Calendar.YEAR) - 1900 - 100;

View file

@ -17,7 +17,7 @@ public class DanaRS_Packet_History_Alarm extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM;
} }
public DanaRS_Packet_History_Alarm(Date from) { public DanaRS_Packet_History_Alarm(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALARM;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_All_History extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_All_History extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_All_History extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY;
} }
public DanaRS_Packet_History_All_History(Date from) { public DanaRS_Packet_History_All_History(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__ALL_HISTORY;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Basal extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Basal extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Basal extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL;
} }
public DanaRS_Packet_History_Basal(Date from) { public DanaRS_Packet_History_Basal(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BASAL;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Blood_Glucose extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Blood_Glucose extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Blood_Glucose extends DanaRS_Packet_History_
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE;
} }
public DanaRS_Packet_History_Blood_Glucose(Date from) { public DanaRS_Packet_History_Blood_Glucose(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BLOOD_GLUCOSE;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Bolus extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Bolus extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Bolus extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS;
} }
public DanaRS_Packet_History_Bolus(Date from) { public DanaRS_Packet_History_Bolus(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__BOLUS;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Carbohydrate extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Carbohydrate extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Carbohydrate extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE;
} }
public DanaRS_Packet_History_Carbohydrate(Date from) { public DanaRS_Packet_History_Carbohydrate(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__CARBOHYDRATE;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Daily extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Daily extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Daily extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY;
} }
public DanaRS_Packet_History_Daily(Date from) { public DanaRS_Packet_History_Daily(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__DAILY;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Prime extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Prime extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Prime extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME;
} }
public DanaRS_Packet_History_Prime(Date from) { public DanaRS_Packet_History_Prime(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__PRIME;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Refill extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Refill extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Refill extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL;
} }
public DanaRS_Packet_History_Refill(Date from) { public DanaRS_Packet_History_Refill(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__REFILL;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Suspend extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Suspend extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Suspend extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND;
} }
public DanaRS_Packet_History_Suspend(Date from) { public DanaRS_Packet_History_Suspend(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SUSPEND;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -5,8 +5,6 @@ import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_History_Temporary extends DanaRS_Packet_History_ { public class DanaRS_Packet_History_Temporary extends DanaRS_Packet_History_ {
@ -17,7 +15,7 @@ public class DanaRS_Packet_History_Temporary extends DanaRS_Packet_History_ {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY;
} }
public DanaRS_Packet_History_Temporary(Date from) { public DanaRS_Packet_History_Temporary(long from) {
super(from); super(from);
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__TEMPORARY;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))

View file

@ -48,7 +48,7 @@ public class DanaRS_Packet_Option_Get_Pump_Time extends DanaRS_Packet {
int sec = byteArrayToInt(getBytes(data, dataIndex, dataSize)); int sec = byteArrayToInt(getBytes(data, dataIndex, dataSize));
Date time = new Date(100 + year, month - 1, day, hour, min, sec); Date time = new Date(100 + year, month - 1, day, hour, min, sec);
DanaRPump.getInstance().pumpTime = time; DanaRPump.getInstance().pumpTime = time.getTime();
if ( year == month && month == day && day == hour && hour == min && min == sec && sec == 1) if ( year == month && month == day && day == hour && hour == min && min == sec && sec == 1)
failed = true; failed = true;

View file

@ -156,7 +156,7 @@ public class DanaRSService extends Service {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time()); bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time());
long timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 3) { if (Math.abs(timeDiff) > 3) {
@ -181,7 +181,7 @@ public class DanaRSService extends Service {
// add 10sec to be sure we are over minute (will be cutted off anyway) // add 10sec to be sure we are over minute (will be cutted off anyway)
bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(new Date(DateUtil.now() + T.secs(10).msecs()))); bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(new Date(DateUtil.now() + T.secs(10).msecs())));
bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time()); bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time());
timeDiff = (danaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
} }
@ -241,7 +241,7 @@ public class DanaRSService extends Service {
} else { } else {
msg = new DanaRS_Packet_APS_History_Events(lastHistoryFetched); msg = new DanaRS_Packet_APS_History_Events(lastHistoryFetched);
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString()); log.debug("Loading event history from: " +DateUtil.dateAndTimeFullString(lastHistoryFetched));
} }
bleComm.sendMessage(msg); bleComm.sendMessage(msg);
while (!msg.done && bleComm.isConnected()) { while (!msg.done && bleComm.isConnected()) {

View file

@ -5,8 +5,6 @@ import android.support.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@ -33,7 +31,7 @@ public class MsgStatusBolusExtended_v2 extends MessageBase {
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60; int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d; double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0); long extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : 0;
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes; int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
@ -57,8 +55,8 @@ public class MsgStatusBolusExtended_v2 extends MessageBase {
} }
@NonNull @NonNull
private Date getDateFromSecAgo(int tempBasalAgoSecs) { private long getDateFromSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
} }
} }

View file

@ -5,11 +5,10 @@ import android.support.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.utils.DateUtil;
public class MsgStatusTempBasal_v2 extends MessageBase { public class MsgStatusTempBasal_v2 extends MessageBase {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -31,7 +30,7 @@ public class MsgStatusTempBasal_v2 extends MessageBase {
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60; else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3); int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60; int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0); long tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : 0;
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
pump.isTempBasalInProgress = isTempBasalInProgress; pump.isTempBasalInProgress = isTempBasalInProgress;
@ -46,13 +45,13 @@ public class MsgStatusTempBasal_v2 extends MessageBase {
log.debug("Current temp basal percent: " + tempBasalPercent); log.debug("Current temp basal percent: " + tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin); log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + tempBasalTotalSec); log.debug("Current temp basal total sec: " + tempBasalTotalSec);
log.debug("Current temp basal start: " + tempBasalStart); log.debug("Current temp basal start: " + DateUtil.dateAndTimeFullString(tempBasalStart));
} }
} }
@NonNull @NonNull
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) { private long getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000); return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
} }
} }

View file

@ -133,9 +133,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (mConnectionInProgress) if (mConnectionInProgress)
return; return;
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
mConnectionInProgress = true; mConnectionInProgress = true;
getBTSocketForSelectedPump(); getBTSocketForSelectedPump();
if (mRfcommSocket == null || mBTDevice == null) { if (mRfcommSocket == null || mBTDevice == null) {
@ -161,7 +159,6 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
} }
mConnectionInProgress = false; mConnectionInProgress = false;
}
}).start(); }).start();
} }
@ -203,7 +200,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; long timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 3) { if (Math.abs(timeDiff) > 3) {
@ -228,7 +225,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
// add 10sec to be sure we are over minute (will be cutted off anyway) // add 10sec to be sure we are over minute (will be cutted off anyway)
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs()))); mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
mSerialIOThread.sendMessage(new MsgSettingPumpTime()); mSerialIOThread.sendMessage(new MsgSettingPumpTime());
timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; timeDiff = (mDanaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds"); log.debug("Pump time difference: " + timeDiff + " seconds");
} }
@ -269,7 +266,6 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
} catch (Exception e) { } catch (Exception e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
return;
} }
public boolean tempBasal(int percent, int durationInHours) { public boolean tempBasal(int percent, int durationInHours) {
@ -479,7 +475,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
} else { } else {
msg = new MsgHistoryEvents_v2(lastHistoryFetched); msg = new MsgHistoryEvents_v2(lastHistoryFetched);
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString()); log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched));
} }
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) { while (!msg.done && mRfcommSocket.isConnected()) {

View file

@ -103,7 +103,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
private static Logger log = LoggerFactory.getLogger(InsightPlugin.class); private static Logger log = LoggerFactory.getLogger(InsightPlugin.class);
private StatusTaskRunner.Result statusResult; private StatusTaskRunner.Result statusResult;
private long statusResultTime = -1; private long statusResultTime = -1;
private Date lastDataTime = new Date(0); private long lastDataTime = 0;
private boolean fauxTBRcancel = true; private boolean fauxTBRcancel = true;
private PumpDescription pumpDescription = new PumpDescription(); private PumpDescription pumpDescription = new PumpDescription();
private double basalRate = 0; private double basalRate = 0;
@ -407,7 +407,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
} }
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return lastDataTime; return lastDataTime;
} }
@ -877,7 +877,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
private <T> T fetchTaskRunner(TaskRunner taskRunner, Class<T> resultType) throws Exception { private <T> T fetchTaskRunner(TaskRunner taskRunner, Class<T> resultType) throws Exception {
try { try {
T result = (T) taskRunner.fetchAndWaitUsingLatch(BUSY_WAIT_TIME); T result = (T) taskRunner.fetchAndWaitUsingLatch(BUSY_WAIT_TIME);
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} catch (Exception e) { } catch (Exception e) {
log("Error while fetching " + taskRunner.getClass().getSimpleName() + ": " + e.getClass().getSimpleName()); log("Error while fetching " + taskRunner.getClass().getSimpleName() + ": " + e.getClass().getSimpleName());
@ -888,7 +888,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
private <T extends AppLayerMessage> T fetchSingleMessage(AppLayerMessage message, Class<T> resultType) throws Exception { private <T extends AppLayerMessage> T fetchSingleMessage(AppLayerMessage message, Class<T> resultType) throws Exception {
try { try {
T result = (T) new SingleMessageTaskRunner(connector.getServiceConnector(), message).fetchAndWaitUsingLatch(BUSY_WAIT_TIME); T result = (T) new SingleMessageTaskRunner(connector.getServiceConnector(), message).fetchAndWaitUsingLatch(BUSY_WAIT_TIME);
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} catch (Exception e) { } catch (Exception e) {
log("Error while fetching " + message.getClass().getSimpleName() + ": " + e.getClass().getSimpleName()); log("Error while fetching " + message.getClass().getSimpleName() + ": " + e.getClass().getSimpleName());

View file

@ -5,8 +5,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.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -120,8 +118,8 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
} }
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return new Date(); return System.currentTimeMillis();
} }
@Override @Override

View file

@ -7,8 +7,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.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -53,7 +51,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
static Integer batteryPercent = 50; static Integer batteryPercent = 50;
static Integer reservoirInUnits = 50; static Integer reservoirInUnits = 50;
private Date lastDataTime = new Date(0); private long lastDataTime = 0;
private static boolean fromNSAreCommingFakedExtendedBoluses = false; private static boolean fromNSAreCommingFakedExtendedBoluses = false;
@ -153,7 +151,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
public void connect(String reason) { public void connect(String reason) {
if (!Config.NSCLIENT) if (!Config.NSCLIENT)
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
} }
@Override @Override
@ -166,12 +164,12 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override @Override
public void getPumpStatus() { public void getPumpStatus() {
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
} }
@Override @Override
public PumpEnactResult setNewBasalProfile(Profile profile) { public PumpEnactResult setNewBasalProfile(Profile profile) {
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
@ -186,7 +184,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
} }
@Override @Override
public Date lastDataTime() { public long lastDataTime() {
return lastDataTime; return lastDataTime;
} }
@ -227,7 +225,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
return result; return result;
} }
@ -255,7 +253,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Setting temp basal absolute: " + result); log.debug("Setting temp basal absolute: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} }
@ -283,7 +281,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Settings temp basal percent: " + result); log.debug("Settings temp basal percent: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} }
@ -307,7 +305,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Setting extended bolus: " + result); log.debug("Setting extended bolus: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} }
@ -326,7 +324,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
log.debug("Canceling temp basal: " + result); log.debug("Canceling temp basal: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
} }
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} }
@ -345,7 +343,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("Canceling extended bolus: " + result); log.debug("Canceling extended bolus: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = System.currentTimeMillis();
return result; return result;
} }

View file

@ -68,7 +68,7 @@ public class SmsCommunicatorFragment extends SubscriberFragment {
public void run() { public void run() {
class CustomComparator implements Comparator<SmsCommunicatorPlugin.Sms> { class CustomComparator implements Comparator<SmsCommunicatorPlugin.Sms> {
public int compare(SmsCommunicatorPlugin.Sms object1, SmsCommunicatorPlugin.Sms object2) { public int compare(SmsCommunicatorPlugin.Sms object1, SmsCommunicatorPlugin.Sms object2) {
return (int) (object1.date.getTime() - object2.date.getTime()); return (int) (object1.date - object2.date);
} }
} }
Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator()); Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator());

View file

@ -73,7 +73,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
class Sms { class Sms {
String phoneNumber; String phoneNumber;
String text; String text;
Date date; long date;
boolean received = false; boolean received = false;
boolean sent = false; boolean sent = false;
boolean processed = false; boolean processed = false;
@ -87,18 +87,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
Sms(SmsMessage message) { Sms(SmsMessage message) {
phoneNumber = message.getOriginatingAddress(); phoneNumber = message.getOriginatingAddress();
text = message.getMessageBody(); text = message.getMessageBody();
date = new Date(message.getTimestampMillis()); date = message.getTimestampMillis();
received = true; received = true;
} }
Sms(String phoneNumber, String text, Date date) { Sms(String phoneNumber, String text, long date) {
this.phoneNumber = phoneNumber; this.phoneNumber = phoneNumber;
this.text = text; this.text = text;
this.date = date; this.date = date;
sent = true; sent = true;
} }
Sms(String phoneNumber, String text, Date date, String confirmCode) { Sms(String phoneNumber, String text, long date, String confirmCode) {
this.phoneNumber = phoneNumber; this.phoneNumber = phoneNumber;
this.text = text; this.text = text;
this.date = date; this.date = date;
@ -230,7 +230,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
+ MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)"; + MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
receivedSms.processed = true; receivedSms.processed = true;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bg")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bg"));
break; break;
@ -248,7 +248,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " + String reply = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " +
MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
}); });
} }
@ -261,7 +261,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginType.LOOP, true); loopPlugin.setPluginEnabled(PluginType.LOOP, true);
reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled); reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
} }
receivedSms.processed = true; receivedSms.processed = true;
@ -278,7 +278,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_loopisdisabled); reply = MainApp.gs(R.string.smscommunicator_loopisdisabled);
} }
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
receivedSms.processed = true; receivedSms.processed = true;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
@ -288,7 +288,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME"));
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
reply = MainApp.gs(R.string.smscommunicator_loopresumed); reply = MainApp.gs(R.string.smscommunicator_loopresumed);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
break; break;
case "SUSPEND": case "SUSPEND":
@ -298,18 +298,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
duration = Math.min(180, duration); duration = Math.min(180, duration);
if (duration == 0) { if (duration == 0) {
reply = MainApp.gs(R.string.smscommunicator_wrongduration); reply = MainApp.gs(R.string.smscommunicator_wrongduration);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else if (remoteCommandsAllowed) { } else if (remoteCommandsAllowed) {
passCode = generatePasscode(); passCode = generatePasscode();
reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
suspendWaitingForConfirmation.duration = duration; suspendWaitingForConfirmation.duration = duration;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend"));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
break; break;
} }
@ -323,7 +323,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
reply = "TERATMENTS REFRESH " + q.size() + " receivers"; reply = "TERATMENTS REFRESH " + q.size() + " receivers";
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
receivedSms.processed = true; receivedSms.processed = true;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Treatments_Refresh")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Treatments_Refresh"));
break; break;
@ -337,7 +337,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0); List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
reply = "NSCLIENT RESTART " + q.size() + " receivers"; reply = "NSCLIENT RESTART " + q.size() + " receivers";
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
receivedSms.processed = true; receivedSms.processed = true;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Nsclient_Restart")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Nsclient_Restart"));
break; break;
@ -352,11 +352,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (result.success) { if (result.success) {
if (pump != null) { if (pump != null) {
String reply = pump.shortStatus(true); String reply = pump.shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} else { } else {
String reply = MainApp.gs(R.string.readstatusfailed); String reply = MainApp.gs(R.string.readstatusfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
}); });
@ -371,18 +371,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} else { } else {
tempBasal = SafeParse.stringToDouble(splited[1]); tempBasal = SafeParse.stringToDouble(splited[1]);
Profile profile = ProfileFunctions.getInstance().getProfile(); Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile == null) { if (profile == null) {
reply = MainApp.gs(R.string.noprofile); reply = MainApp.gs(R.string.noprofile);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value(); tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
if (remoteCommandsAllowed) { if (remoteCommandsAllowed) {
@ -390,12 +390,12 @@ public class SmsCommunicatorPlugin extends PluginBase {
reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
tempBasalWaitingForConfirmation.tempBasal = tempBasal; tempBasalWaitingForConfirmation.tempBasal = tempBasal;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Basal"));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
} }
@ -404,10 +404,10 @@ public class SmsCommunicatorPlugin extends PluginBase {
case "BOLUS": case "BOLUS":
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) { if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else if (ConfigBuilderPlugin.getActivePump().isSuspended()) { } else if (ConfigBuilderPlugin.getActivePump().isSuspended()) {
reply = MainApp.gs(R.string.pumpsuspended); reply = MainApp.gs(R.string.pumpsuspended);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else if (splited.length > 1) { } else if (splited.length > 1) {
amount = SafeParse.stringToDouble(splited[1]); amount = SafeParse.stringToDouble(splited[1]);
amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value(); amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
@ -416,12 +416,12 @@ public class SmsCommunicatorPlugin extends PluginBase {
reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), amount, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
bolusWaitingForConfirmation.bolusRequested = amount; bolusWaitingForConfirmation.bolusRequested = amount;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Bolus"));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
break; break;
@ -433,18 +433,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), amount, passCode); reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
receivedSms.processed = true; receivedSms.processed = true;
resetWaitingMessages(); resetWaitingMessages();
sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis(), passCode));
calibrationWaitingForConfirmation.calibrationRequested = amount; calibrationWaitingForConfirmation.calibrationRequested = amount;
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal")); FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Cal"));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed); reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
break; break;
default: // expect passCode here default: // expect passCode here
if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed && if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
bolusWaitingForConfirmation.processed = true; bolusWaitingForConfirmation.processed = true;
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested; detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
@ -459,18 +459,18 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (pump != null) if (pump != null)
reply += "\n" + pump.shortStatus(true); reply += "\n" + pump.shortStatus(true);
lastRemoteBolusTime = new Date(); lastRemoteBolusTime = new Date();
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
SystemClock.sleep(T.secs(60).msecs()); // wait some time to get history SystemClock.sleep(T.secs(60).msecs()); // wait some time to get history
String reply = MainApp.gs(R.string.smscommunicator_bolusfailed); String reply = MainApp.gs(R.string.smscommunicator_bolusfailed);
if (pump != null) if (pump != null)
reply += "\n" + pump.shortStatus(true); reply += "\n" + pump.shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
}); });
} else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed && } else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
tempBasalWaitingForConfirmation.processed = true; tempBasalWaitingForConfirmation.processed = true;
Profile profile = ProfileFunctions.getInstance().getProfile(); Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile != null) if (profile != null)
@ -480,16 +480,16 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (result.success) { if (result.success) {
String reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); String reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
}); });
} else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed && } else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
cancelTempBasalWaitingForConfirmation.processed = true; cancelTempBasalWaitingForConfirmation.processed = true;
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
@ -497,27 +497,27 @@ public class SmsCommunicatorPlugin extends PluginBase {
if (result.success) { if (result.success) {
String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcanceled);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
}); });
} else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed && } else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed &&
calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
calibrationWaitingForConfirmation.processed = true; calibrationWaitingForConfirmation.processed = true;
boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
if (result) { if (result) {
reply = MainApp.gs(R.string.smscommunicator_calibrationsent); reply = MainApp.gs(R.string.smscommunicator_calibrationsent);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
reply = MainApp.gs(R.string.smscommunicator_calibrationfailed); reply = MainApp.gs(R.string.smscommunicator_calibrationfailed);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed && } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date < Constants.SMS_CONFIRM_TIMEOUT) {
suspendWaitingForConfirmation.processed = true; suspendWaitingForConfirmation.processed = true;
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
@ -528,16 +528,16 @@ public class SmsCommunicatorPlugin extends PluginBase {
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " + String reply = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed); MainApp.gs(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} else { } else {
String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed); String reply = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed);
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true); reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, System.currentTimeMillis()));
} }
} }
}); });
} else { } else {
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand), new Date())); sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand), System.currentTimeMillis()));
} }
resetWaitingMessages(); resetWaitingMessages();
break; break;
@ -549,7 +549,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
public void sendNotificationToAllNumbers(String text) { public void sendNotificationToAllNumbers(String text) {
for (int i = 0; i < allowedNumbers.size(); i++) { for (int i = 0; i < allowedNumbers.size(); i++) {
Sms sms = new Sms(allowedNumbers.get(i), text, new Date()); Sms sms = new Sms(allowedNumbers.get(i), text, System.currentTimeMillis());
sendSMS(sms); sendSMS(sms);
} }
} }

View file

@ -12,8 +12,6 @@ import com.crashlytics.android.answers.CustomEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -65,8 +63,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
final Profile profile = ProfileFunctions.getInstance().getProfile(); final Profile profile = ProfileFunctions.getInstance().getProfile();
if (pump != null && profile != null) { if (pump != null && profile != null) {
Date lastConnection = pump.lastDataTime(); long lastConnection = pump.lastDataTime();
boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis(); boolean isStatusOutdated = lastConnection + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis();
boolean isBasalOutdated = Math.abs(profile.getBasal() - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep; boolean isBasalOutdated = Math.abs(profile.getBasal() - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep;
if (L.isEnabled(L.CORE)) if (L.isEnabled(L.CORE))

View file

@ -3,8 +3,6 @@ package info.nightscout.utils;
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;
@ -35,8 +33,8 @@ public class LocalAlertUtils {
return T.mins(SP.getInt(MainApp.gs(R.string.key_pump_unreachable_threshold), 30)).msecs(); return T.mins(SP.getInt(MainApp.gs(R.string.key_pump_unreachable_threshold), 30)).msecs();
} }
public static void checkPumpUnreachableAlarm(Date lastConnection, boolean isStatusOutdated) { public static void checkPumpUnreachableAlarm(long lastConnection, boolean isStatusOutdated) {
boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis(); boolean alarmTimeoutExpired = lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis();
boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis(); boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis();
if (Config.APS && SP.getBoolean(MainApp.gs(R.string.key_enable_pump_unreachable_alert), true) if (Config.APS && SP.getBoolean(MainApp.gs(R.string.key_enable_pump_unreachable_alert), true)
@ -83,8 +81,8 @@ public class LocalAlertUtils {
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
final Profile profile = ProfileFunctions.getInstance().getProfile(); final Profile profile = ProfileFunctions.getInstance().getProfile();
if (pump != null && profile != null) { if (pump != null && profile != null) {
Date lastConnection = pump.lastDataTime(); long lastConnection = pump.lastDataTime();
long earliestAlarmTime = lastConnection.getTime() + pumpUnreachableThreshold(); long earliestAlarmTime = lastConnection + pumpUnreachableThreshold();
if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < earliestAlarmTime) { if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < earliestAlarmTime) {
SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime); SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime);
} }

View file

@ -2,8 +2,6 @@ package info.nightscout.utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.Date;
/** /**
* Created by mike on 29.01.2017. * Created by mike on 29.01.2017.
*/ */
@ -11,8 +9,8 @@ import java.util.Date;
public class Profiler { public class Profiler {
public Profiler(){} public Profiler(){}
static public void log(Logger log, String function, Date start) { static public void log(Logger log, String function, long start) {
long msec = System.currentTimeMillis() - start.getTime(); long msec = System.currentTimeMillis() - start;
log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds"); log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds");
} }
} }