commit
ac66e37bec
42 changed files with 395 additions and 211 deletions
|
@ -29,4 +29,14 @@ public class DetailedBolusInfo {
|
|||
public Context context = null; // context for progress dialog
|
||||
public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment)
|
||||
public boolean isSMB = false; // is a Super-MicroBolus
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new Date(date).toLocaleString() +
|
||||
" insulin: " + insulin +
|
||||
" carbs: " + carbs +
|
||||
" isValid: " + isValid +
|
||||
" carbTime: " + carbTime +
|
||||
" isSMB: " + isSMB;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,7 +256,7 @@ public class Profile {
|
|||
private String format_HH_MM(Integer timeAsSeconds) {
|
||||
String time;
|
||||
int hour = timeAsSeconds / 60 / 60;
|
||||
int minutes = timeAsSeconds - hour * 60 * 60;
|
||||
int minutes = (timeAsSeconds - hour * 60 * 60) / 60;
|
||||
DecimalFormat df = new DecimalFormat("00");
|
||||
time = df.format(hour) + ":" + df.format(minutes);
|
||||
return time;
|
||||
|
|
|
@ -961,7 +961,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
|
||||
public String getProfileUnits() {
|
||||
return activeProfile.getUnits();
|
||||
return getProfile().getUnits();
|
||||
}
|
||||
|
||||
public Profile getProfile(long time) {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class DetailedBolusInfoStorage {
|
|||
private static List<DetailedBolusInfo> store = new ArrayList<>();
|
||||
|
||||
public static void add(DetailedBolusInfo detailedBolusInfo) {
|
||||
log.debug("Bolus info stored: " + new Date(detailedBolusInfo.date).toLocaleString());
|
||||
log.debug("Stored bolus info: " + detailedBolusInfo);
|
||||
store.add(detailedBolusInfo);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class DetailedBolusInfoStorage {
|
|||
DetailedBolusInfo found = null;
|
||||
for (int i = 0; i < store.size(); i++) {
|
||||
long infoTime = store.get(i).date;
|
||||
log.debug("Existing info: " + new Date(infoTime).toLocaleString());
|
||||
log.debug("Existing bolus info: " + store.get(i));
|
||||
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
||||
found = store.get(i);
|
||||
break;
|
||||
|
@ -42,7 +42,7 @@ public class DetailedBolusInfoStorage {
|
|||
for (int i = 0; i < store.size(); i++) {
|
||||
long infoTime = store.get(i).date;
|
||||
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
||||
log.debug("Removing info: " + new Date(infoTime).toLocaleString());
|
||||
log.debug("Removing bolus info: " + store.get(i));
|
||||
store.remove(i);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -366,6 +366,9 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (profile.getIsf(bgTime) == null)
|
||||
return; // profile not set yet
|
||||
|
||||
double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits());
|
||||
|
||||
AutosensData autosensData = new AutosensData();
|
||||
|
|
|
@ -183,7 +183,7 @@ public class BroadcastTreatment {
|
|||
ret.add(newarr);
|
||||
}
|
||||
newarr = new JSONArray();
|
||||
count = 50;
|
||||
count = 20;
|
||||
}
|
||||
newarr.put(array.get(i));
|
||||
--count;
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.squareup.otto.Subscribe;
|
|||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.javascript.tools.debugger.Main;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -401,15 +402,11 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
|
||||
ArrayList<CharSequence> profileList;
|
||||
profileList = profileStore.getProfileList();
|
||||
profileList.add(0, MainApp.sResources.getString(R.string.active));
|
||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
|
||||
R.layout.spinner_centered, profileList);
|
||||
|
||||
profileSpinner.setAdapter(adapter);
|
||||
// set selected to actual profile
|
||||
for (int p = 0; p < profileList.size(); p++) {
|
||||
if (profileList.get(p).equals(MainApp.getConfigBuilder().getProfileName()))
|
||||
profileSpinner.setSelection(p);
|
||||
}
|
||||
|
||||
String units = profile.getUnits();
|
||||
bgUnits.setText(units);
|
||||
|
@ -451,7 +448,11 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
if (profileSpinner == null || profileSpinner.getSelectedItem() == null)
|
||||
return; // not initialized yet
|
||||
String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
|
||||
Profile specificProfile = profile.getSpecificProfile(selectedAlternativeProfile);
|
||||
Profile specificProfile;
|
||||
if (selectedAlternativeProfile.equals(MainApp.sResources.getString(R.string.active)))
|
||||
specificProfile = MainApp.getConfigBuilder().getProfile();
|
||||
else
|
||||
specificProfile = profile.getSpecificProfile(selectedAlternativeProfile);
|
||||
|
||||
// Entered values
|
||||
Double c_bg = SafeParse.stringToDouble(editBg.getText());
|
||||
|
|
|
@ -187,12 +187,12 @@ public class SerialIOThread extends Thread {
|
|||
scheduledDisconnection = null;
|
||||
}
|
||||
}
|
||||
// prepare task for execution in 5 sec
|
||||
// prepare task for execution in 10 sec
|
||||
// cancel waiting task to prevent sending multiple disconnections
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
Runnable task = new DisconnectRunnable();
|
||||
final int sec = 5;
|
||||
final int sec = 10;
|
||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.SerialIOThread;
|
||||
|
@ -410,12 +411,12 @@ public class DanaRExecutionService extends Service {
|
|||
|
||||
public boolean bolus(double amount, int carbs, Treatment t) {
|
||||
bolusingTreatment = t;
|
||||
int speed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
MessageBase start;
|
||||
if (speed == 0)
|
||||
if (preferencesSpeed == 0)
|
||||
start = new MsgBolusStart(amount);
|
||||
else
|
||||
start = new MsgBolusStartWithSpeed(amount, speed);
|
||||
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||
|
||||
connect("bolus");
|
||||
|
@ -426,7 +427,7 @@ public class DanaRExecutionService extends Service {
|
|||
}
|
||||
|
||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||
long startTime = System.currentTimeMillis();
|
||||
long bolusStart = System.currentTimeMillis();
|
||||
|
||||
if (!stop.stopped) {
|
||||
mSerialIOThread.sendMessage(start);
|
||||
|
@ -436,23 +437,47 @@ public class DanaRExecutionService extends Service {
|
|||
}
|
||||
while (!stop.stopped && !start.failed) {
|
||||
waitMsec(100);
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
log.debug("Communication stopped");
|
||||
}
|
||||
}
|
||||
waitMsec(300);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
|
||||
bolusingTreatment = null;
|
||||
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
case 0:
|
||||
speed = 12;
|
||||
break;
|
||||
case 1:
|
||||
speed = 30;
|
||||
break;
|
||||
case 2:
|
||||
speed = 60;
|
||||
break;
|
||||
}
|
||||
// try to find real amount if bolusing was interrupted or comm failed
|
||||
if (t.insulin != amount) {
|
||||
disconnect("bolusingInterrupted");
|
||||
long now = System.currentTimeMillis();
|
||||
long estimatedBolusEnd = (long) (startTime + amount / 5d * 60 * 1000); // std delivery rate 5 U/min
|
||||
waitMsec(Math.max(5000, estimatedBolusEnd - now + 3000));
|
||||
long bolusDurationInMSec = (long) (amount * speed * 1000);
|
||||
long expectedEnd = bolusStart + bolusDurationInMSec + 3000;
|
||||
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
connect("bolusingInterrupted");
|
||||
getPumpStatus();
|
||||
if (danaRPump.lastBolusTime.getTime() > now - 60 * 1000L) { // last bolus max 1 min old
|
||||
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
||||
t.insulin = danaRPump.lastBolusAmount;
|
||||
log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
|
||||
} else {
|
||||
|
|
|
@ -49,6 +49,7 @@ import info.nightscout.androidaps.events.EventAppExit;
|
|||
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
@ -218,7 +219,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
connect(from);
|
||||
}
|
||||
|
||||
public static synchronized void connect(String from) {
|
||||
public static void connect(String from) {
|
||||
log.debug("RS connect from: " + from);
|
||||
if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) {
|
||||
final Object o = new Object();
|
||||
|
@ -264,7 +265,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
connectIfNotConnected("loadHistory");
|
||||
return danaRSService.loadHistory(type);
|
||||
danaRSService.loadHistory(type);
|
||||
disconnect("LoadHistory");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Constraints interface
|
||||
|
@ -375,7 +378,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int setNewBasalProfile(Profile profile) {
|
||||
public synchronized int setNewBasalProfile(Profile profile) {
|
||||
if (danaRSService == null) {
|
||||
log.error("setNewBasalProfile sExecutionService is null");
|
||||
return FAILED;
|
||||
|
@ -392,10 +395,12 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
if (!danaRSService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
disconnect("SetNewBasalProfile");
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
disconnect("SetNewBasalProfile");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -426,10 +431,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void refreshDataFromPump(String reason) {
|
||||
public synchronized void refreshDataFromPump(String reason) {
|
||||
log.debug("Refreshing data from pump");
|
||||
if (!isConnected() && !isConnecting()) {
|
||||
connect(reason);
|
||||
disconnect("RefreshDataFromPump");
|
||||
} else
|
||||
log.debug("Already connecting ...");
|
||||
}
|
||||
|
@ -440,11 +446,10 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
|
@ -459,8 +464,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
break;
|
||||
}
|
||||
// v2 stores end time for bolus, we need to adjust time
|
||||
// default delivery speed is 12 U/min
|
||||
detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000;
|
||||
// default delivery speed is 12 sec/U
|
||||
detailedBolusInfo.date += detailedBolusInfo.insulin * speed * 1000;
|
||||
// clean carbs to prevent counting them as twice because they will picked up as another record
|
||||
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
|
||||
double carbs = detailedBolusInfo.carbs;
|
||||
|
@ -468,6 +473,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
int carbTime = detailedBolusInfo.carbTime;
|
||||
detailedBolusInfo.carbTime = 0;
|
||||
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
|
||||
Treatment t = new Treatment();
|
||||
boolean connectionOK = false;
|
||||
connectIfNotConnected("bolus");
|
||||
|
@ -480,7 +487,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (Config.logPumpActions)
|
||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
// remove carbs because it's get from history seprately
|
||||
disconnect("DeliverTreatment");
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -504,7 +511,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
|
||||
// This is called from APS
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||
// Recheck pump status if older than 30 min
|
||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
connect("setTempBasalAbsolute old data");
|
||||
|
@ -581,7 +588,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
percent = configBuilderPlugin.applyBasalConstraints(percent);
|
||||
|
@ -623,6 +630,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
disconnect("setTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -632,7 +640,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
return result;
|
||||
}
|
||||
|
||||
public PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
connectIfNotConnected("hightempbasal");
|
||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||
|
@ -646,6 +654,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setHighTempBasalPercent: OK");
|
||||
disconnect("setHighTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -656,7 +665,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||
// needs to be rounded
|
||||
|
@ -689,6 +698,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = false;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setExtendedBolus: OK");
|
||||
disconnect("setExtendedBolus");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -699,7 +709,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
||||
public synchronized PumpEnactResult cancelTempBasal(boolean force) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
|
@ -707,6 +717,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
danaRSService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("cancelTempBasal");
|
||||
}
|
||||
if (!pump.isTempBasalInProgress) {
|
||||
result.success = true;
|
||||
|
@ -725,7 +736,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
public synchronized PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null) {
|
||||
|
@ -733,6 +744,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
danaRSService.extendedBolusStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("extendedBolusStop");
|
||||
}
|
||||
if (!pump.isExtendedInProgress) {
|
||||
result.success = true;
|
||||
|
@ -808,7 +820,28 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
|
||||
@Override
|
||||
public String shortStatus(boolean veryShort) {
|
||||
return null;
|
||||
String ret = "";
|
||||
if (pump.lastConnection.getTime() != 0) {
|
||||
Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime();
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " minago\n";
|
||||
}
|
||||
if (pump.lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||
}
|
||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n";
|
||||
}
|
||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString() + "\n";
|
||||
}
|
||||
if (!veryShort) {
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
|
||||
}
|
||||
ret += "IOB: " + pump.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,15 +10,14 @@ import java.util.Date;
|
|||
import java.util.GregorianCalendar;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
||||
|
@ -32,11 +31,11 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
private int sec = 0;
|
||||
|
||||
public boolean done;
|
||||
public int totalCount;
|
||||
private int totalCount;
|
||||
|
||||
public static long lastEventTimeLoaded = 0;
|
||||
|
||||
public DanaRS_Packet_APS_History_Events() {
|
||||
DanaRS_Packet_APS_History_Events() {
|
||||
super();
|
||||
opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS;
|
||||
done = false;
|
||||
|
@ -97,70 +96,87 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
|
||||
if (detailedBolusInfo == null) {
|
||||
log.debug("DetailedBolusInfo not found for " + datetime.toLocaleString());
|
||||
log.debug("Detailed bolus info not found for " + datetime.toLocaleString());
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
} else {
|
||||
log.debug("Detailed bolus info found: " + detailedBolusInfo);
|
||||
}
|
||||
detailedBolusInfo.date = datetime.getTime();
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.pumpId = datetime.getTime();
|
||||
|
||||
String status;
|
||||
|
||||
switch (recordCode) {
|
||||
case DanaRPump.TEMPSTART:
|
||||
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min");
|
||||
temporaryBasal.percentRate = param1;
|
||||
temporaryBasal.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
||||
status = "TEMPSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.TEMPSTOP:
|
||||
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
|
||||
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
||||
status = "TEMPSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.EXTENDEDSTART:
|
||||
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
extendedBolus.insulin = param1 / 100d;
|
||||
extendedBolus.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "EXTENDEDSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.EXTENDEDSTOP:
|
||||
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.BOLUS:
|
||||
detailedBolusInfo.insulin = param1 / 100d;
|
||||
boolean newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
|
||||
status = "BOLUS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALBOLUS:
|
||||
detailedBolusInfo.insulin = param1 / 100d;
|
||||
newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
|
||||
status = "DUALBOLUS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALEXTENDEDSTART:
|
||||
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
extendedBolus.insulin = param1 / 100d;
|
||||
extendedBolus.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALEXTENDEDSTOP:
|
||||
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.SUSPENDON:
|
||||
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString());
|
||||
status = "SUSPENDON " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.SUSPENDOFF:
|
||||
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString());
|
||||
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.REFILL:
|
||||
log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
status = "REFILL " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.PRIME:
|
||||
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
status = "PRIME " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.PROFILECHANGE:
|
||||
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
|
||||
status = "PROFILECHANGE " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.CARBS:
|
||||
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
|
||||
|
@ -170,17 +186,22 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
emptyCarbsInfo.pumpId = datetime.getTime();
|
||||
newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(emptyCarbsInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
|
||||
status = "CARBS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.PRIMECANNULA:
|
||||
log.debug("EVENT PRIME CANNULA(" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
log.debug("EVENT PRIMECANNULA(" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
status = "PRIMECANNULA " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
default:
|
||||
log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
|
||||
status = "UNKNOWN " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
}
|
||||
|
||||
if (datetime.getTime() > lastEventTimeLoaded)
|
||||
lastEventTimeLoaded = datetime.getTime();
|
||||
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.processinghistory) + ": " + status));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,13 +4,13 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
|
||||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
public class DanaRS_Packet_Basal_Set_Basal_Rate extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Basal_Rate.class);
|
||||
|
||||
private double[] profileBasalRate;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Basal_Rate() {
|
||||
super();
|
||||
|
@ -38,11 +38,12 @@ public class DanaRS_Packet_Basal_Set_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
public class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.class);
|
||||
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal() {
|
||||
super();
|
||||
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL;
|
||||
|
@ -22,9 +20,12 @@ public class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal extends DanaRS_Packe
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
error = byteArrayToInt(getBytes(data, DATA_START, 1));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class DanaRS_Packet_Basal_Set_Profile_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
private int profileNumber; // 0 - 4
|
||||
private double[] profileBasalRate;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Profile_Basal_Rate() {
|
||||
super();
|
||||
|
@ -41,11 +40,12 @@ public class DanaRS_Packet_Basal_Set_Profile_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
public class DanaRS_Packet_Basal_Set_Profile_Number extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Profile_Number.class);
|
||||
private int profileNumber;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Profile_Number() {
|
||||
super();
|
||||
|
@ -33,11 +32,12 @@ public class DanaRS_Packet_Basal_Set_Profile_Number extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_Off extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_Off.class);
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Suspend_Off() {
|
||||
super();
|
||||
|
@ -20,11 +19,12 @@ public class DanaRS_Packet_Basal_Set_Suspend_Off extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_On extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_On.class);
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Suspend_On() {
|
||||
super();
|
||||
|
@ -20,11 +19,12 @@ public class DanaRS_Packet_Basal_Set_Suspend_On extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class DanaRS_Packet_Basal_Set_Temporary_Basal extends DanaRS_Packet {
|
|||
|
||||
private int temporaryBasalRatio;
|
||||
private int temporaryBasalDuration;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Temporary_Basal() {
|
||||
super();
|
||||
|
@ -37,11 +36,12 @@ public class DanaRS_Packet_Basal_Set_Temporary_Basal extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,12 +111,12 @@ public class DanaRS_Packet_Bolus_Set_Bolus_Option extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,12 +83,12 @@ public class DanaRS_Packet_Bolus_Set_CIR_CF_Array extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ public class DanaRS_Packet_Bolus_Set_Dual_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ public class DanaRS_Packet_Bolus_Set_Extended_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ public class DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel extends DanaRS_Packet
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ public class DanaRS_Packet_Bolus_Set_Initial_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,14 +48,12 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
|
|||
}
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
failed = status != 0x00;
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,13 +35,14 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
stopped = true;
|
||||
if (!forced) {
|
||||
|
|
|
@ -31,12 +31,12 @@ public class DanaRS_Packet_General_Set_History_Upload_Mode extends DanaRS_Packet
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ public class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear extends DanaR
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,10 @@ public class DanaRS_Packet_Option_Set_Pump_Time extends DanaRS_Packet {
|
|||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (error == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet {
|
|||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (error == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,19 +165,6 @@ public class BLEComm {
|
|||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING));
|
||||
isConnecting = true;
|
||||
|
||||
// Following should be removed later because we close Gatt on disconnect and this should never happen
|
||||
if ((mBluetoothDeviceAddress != null) && (address.equals(mBluetoothDeviceAddress)) && (mBluetoothGatt != null)) {
|
||||
log.debug("Trying to use an existing mBluetoothGatt for connection.");
|
||||
sHandler.post(updateProgress);
|
||||
if (mBluetoothGatt.connect()) {
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||
return true;
|
||||
}
|
||||
sHandler.removeCallbacks(updateProgress);
|
||||
return false;
|
||||
}
|
||||
// end
|
||||
|
||||
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
||||
if (device == null) {
|
||||
log.debug("Device not found. Unable to connect.");
|
||||
|
@ -201,12 +188,19 @@ public class BLEComm {
|
|||
|
||||
public void disconnect(String from) {
|
||||
log.debug("disconnect from: " + from);
|
||||
|
||||
// cancel previous scheduled disconnection to prevent closing upcomming connection
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
scheduledDisconnection = null;
|
||||
|
||||
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
|
||||
return;
|
||||
}
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), false);
|
||||
mBluetoothGatt.disconnect();
|
||||
isConnected = false;
|
||||
SystemClock.sleep(2000);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -214,6 +208,7 @@ public class BLEComm {
|
|||
if (mBluetoothGatt == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mBluetoothGatt.close();
|
||||
mBluetoothGatt = null;
|
||||
}
|
||||
|
@ -687,18 +682,19 @@ public class BLEComm {
|
|||
}
|
||||
|
||||
public void scheduleDisconnection() {
|
||||
|
||||
class DisconnectRunnable implements Runnable {
|
||||
public void run() {
|
||||
disconnect("scheduleDisconnection");
|
||||
scheduledDisconnection = null;
|
||||
}
|
||||
}
|
||||
// prepare task for execution in 5 sec
|
||||
// prepare task for execution in 30 sec
|
||||
// cancel waiting task to prevent sending multiple disconnections
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
Runnable task = new DisconnectRunnable();
|
||||
final int sec = 5;
|
||||
final int sec = 30;
|
||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
||||
log.debug("Disconnection scheduled");
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
|
|||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
|
@ -188,16 +189,16 @@ public class DanaRSService extends Service {
|
|||
while (!msg.done && bleComm.isConnected()) {
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
SystemClock.sleep(200);
|
||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean bolus(double insulin, int carbs, long carbtime, Treatment t) {
|
||||
public boolean bolus(final double insulin, int carbs, long carbtime, Treatment t) {
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
||||
bolusingTreatment = t;
|
||||
int speed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(insulin, speed);
|
||||
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(insulin, preferencesSpeed);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(insulin, t); // initialize static variables
|
||||
DanaRS_Packet_Notify_Delivery_Complete complete = new DanaRS_Packet_Notify_Delivery_Complete(insulin, t); // initialize static variables
|
||||
|
||||
|
@ -210,28 +211,57 @@ public class DanaRSService extends Service {
|
|||
bleComm.sendMessage(msgSetHistoryEntry_v2);
|
||||
lastHistoryFetched = carbtime - 60000;
|
||||
}
|
||||
if (insulin > 0) {
|
||||
DanaRS_Packet_Notify_Delivery_Rate_Display progress = new DanaRS_Packet_Notify_Delivery_Rate_Display(insulin, t); // initialize static variables
|
||||
|
||||
final long bolusStart = System.currentTimeMillis();
|
||||
if (insulin > 0) {
|
||||
if (!stop.stopped) {
|
||||
bleComm.sendMessage(start);
|
||||
} else {
|
||||
t.insulin = 0d;
|
||||
return false;
|
||||
}
|
||||
DanaRS_Packet_Notify_Delivery_Rate_Display progress = new DanaRS_Packet_Notify_Delivery_Rate_Display(insulin, t); // initialize static variables
|
||||
|
||||
while (!stop.stopped && !start.failed && !complete.done) {
|
||||
SystemClock.sleep(100);
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 20 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
log.debug("Communication stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemClock.sleep(3000);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
|
||||
bolusingTreatment = null;
|
||||
DanaRSPlugin.connectIfNotConnected("ReadHistoryAfterBolus");
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
case 0:
|
||||
speed = 12;
|
||||
break;
|
||||
case 1:
|
||||
speed = 30;
|
||||
break;
|
||||
case 2:
|
||||
speed = 60;
|
||||
break;
|
||||
}
|
||||
long bolusDurationInMSec = (long) (insulin * speed * 1000);
|
||||
long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
if (!(isConnected()))
|
||||
DanaRSPlugin.getPlugin().connect("loadEvents");
|
||||
loadEvents();
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -293,9 +293,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
// v2 stores end time for bolus, we need to adjust time
|
||||
// default delivery speed is 12 U/min
|
||||
// default delivery speed is 12 sec/U
|
||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
|
@ -309,7 +308,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
speed = 60;
|
||||
break;
|
||||
}
|
||||
detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000;
|
||||
detailedBolusInfo.date += speed * detailedBolusInfo.insulin * 1000;
|
||||
// clean carbs to prevent counting them as twice because they will picked up as another record
|
||||
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
|
||||
double carbs = detailedBolusInfo.carbs;
|
||||
|
@ -317,6 +316,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
int carbTime = detailedBolusInfo.carbTime;
|
||||
detailedBolusInfo.carbTime = 0;
|
||||
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
|
||||
Treatment t = new Treatment();
|
||||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||
|
|
|
@ -188,12 +188,12 @@ public class SerialIOThread extends Thread {
|
|||
scheduledDisconnection = null;
|
||||
}
|
||||
}
|
||||
// prepare task for execution in 5 sec
|
||||
// prepare task for execution in 10 sec
|
||||
// cancel waiting task to prevent sending multiple disconnections
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
Runnable task = new DisconnectRunnable();
|
||||
final int sec = 5;
|
||||
final int sec = 10;
|
||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,16 @@ import java.util.Date;
|
|||
import java.util.GregorianCalendar;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
public class MsgHistoryEvents_v2 extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents_v2.class);
|
||||
|
@ -65,70 +68,87 @@ public class MsgHistoryEvents_v2 extends MessageBase {
|
|||
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
|
||||
if (detailedBolusInfo == null) {
|
||||
log.debug("DetailedBolusInfo not found for " + datetime.toLocaleString());
|
||||
log.debug("Detailed bolus info not found for " + datetime.toLocaleString());
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
} else {
|
||||
log.debug("Detailed bolus info found: " + detailedBolusInfo);
|
||||
}
|
||||
detailedBolusInfo.date = datetime.getTime();
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.pumpId = datetime.getTime();
|
||||
|
||||
String status = "";
|
||||
|
||||
switch (recordCode) {
|
||||
case DanaRPump.TEMPSTART:
|
||||
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min");
|
||||
temporaryBasal.percentRate = param1;
|
||||
temporaryBasal.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
||||
status = "TEMPSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.TEMPSTOP:
|
||||
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
|
||||
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
|
||||
status = "TEMPSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.EXTENDEDSTART:
|
||||
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
extendedBolus.insulin = param1 / 100d;
|
||||
extendedBolus.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "EXTENDEDSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.EXTENDEDSTOP:
|
||||
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.BOLUS:
|
||||
detailedBolusInfo.insulin = param1 / 100d;
|
||||
boolean newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
|
||||
status = "BOLUS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALBOLUS:
|
||||
detailedBolusInfo.insulin = param1 / 100d;
|
||||
newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
|
||||
status = "DUALBOLUS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALEXTENDEDSTART:
|
||||
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||
extendedBolus.insulin = param1 / 100d;
|
||||
extendedBolus.durationInMinutes = param2;
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALEXTENDEDSTOP:
|
||||
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
|
||||
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.SUSPENDON:
|
||||
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString());
|
||||
status = "SUSPENDON " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.SUSPENDOFF:
|
||||
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString());
|
||||
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.REFILL:
|
||||
log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
status = "REFILL " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.PRIME:
|
||||
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||
status = "PRIME " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.PROFILECHANGE:
|
||||
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
|
||||
status = "PROFILECHANGE " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.CARBS:
|
||||
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
|
||||
|
@ -138,14 +158,17 @@ public class MsgHistoryEvents_v2 extends MessageBase {
|
|||
emptyCarbsInfo.pumpId = datetime.getTime();
|
||||
newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(emptyCarbsInfo);
|
||||
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
|
||||
status = "CARBS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
default:
|
||||
log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
|
||||
status = "UNKNOWN " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
}
|
||||
|
||||
if (datetime.getTime() > lastEventTimeLoaded)
|
||||
lastEventTimeLoaded = datetime.getTime();
|
||||
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.processinghistory) + ": " + status));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.*;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
|
@ -400,14 +401,15 @@ public class DanaRv2ExecutionService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean bolus(double amount, int carbs, long carbtime, Treatment t) {
|
||||
public boolean bolus(final double amount, int carbs, long carbtime, Treatment t) {
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
||||
bolusingTreatment = t;
|
||||
int speed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
MessageBase start;
|
||||
if (speed == 0)
|
||||
if (preferencesSpeed == 0)
|
||||
start = new MsgBolusStart(amount);
|
||||
else
|
||||
start = new MsgBolusStartWithSpeed(amount, speed);
|
||||
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||
|
||||
connect("bolus");
|
||||
|
@ -420,6 +422,8 @@ public class DanaRv2ExecutionService extends Service {
|
|||
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
|
||||
lastHistoryFetched = carbtime - 60000;
|
||||
}
|
||||
|
||||
final long bolusStart = System.currentTimeMillis();
|
||||
if (amount > 0) {
|
||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||
|
||||
|
@ -431,26 +435,46 @@ public class DanaRv2ExecutionService extends Service {
|
|||
}
|
||||
while (!stop.stopped && !start.failed) {
|
||||
waitMsec(100);
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
log.debug("Communication stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
|
||||
bolusingTreatment = null;
|
||||
// run loading history in separate thread and allow bolus dialog to be closed
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
waitMsec(4000);
|
||||
if (!(isConnected()))
|
||||
connect("loadEvents");
|
||||
loadEvents();
|
||||
}
|
||||
}).start();
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
case 0:
|
||||
speed = 12;
|
||||
break;
|
||||
case 1:
|
||||
speed = 30;
|
||||
break;
|
||||
case 2:
|
||||
speed = 60;
|
||||
break;
|
||||
}
|
||||
long bolusDurationInMSec = (long) (amount * speed * 1000);
|
||||
long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
if (!(isConnected()))
|
||||
connect("loadEvents");
|
||||
loadEvents();
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void bolusStop() {
|
||||
if (Config.logDanaBTComm)
|
||||
|
|
|
@ -5,11 +5,9 @@ import android.support.v4.util.LongSparseArray;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
|
@ -32,7 +30,7 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
private boolean fragmentEnabled = true;
|
||||
private boolean fragmentVisible = false;
|
||||
|
||||
static SensitivityWeightedAveragePlugin plugin = null;
|
||||
private static SensitivityWeightedAveragePlugin plugin = null;
|
||||
|
||||
public static SensitivityWeightedAveragePlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
|
@ -108,13 +106,15 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
|
||||
|
||||
if (autosensDataTable == null || autosensDataTable.size() < 4) {
|
||||
log.debug("No autosens data available");
|
||||
if (Config.logAutosensData)
|
||||
log.debug("No autosens data available");
|
||||
return new AutosensResult();
|
||||
}
|
||||
|
||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime);
|
||||
if (current == null) {
|
||||
log.debug("No autosens data available");
|
||||
if (Config.logAutosensData)
|
||||
log.debug("No autosens data available");
|
||||
return new AutosensResult();
|
||||
}
|
||||
|
||||
|
@ -181,9 +181,10 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
double sens = profile.getIsf();
|
||||
|
||||
String ratioLimit = "";
|
||||
String sensResult = "";
|
||||
String sensResult;
|
||||
|
||||
log.debug("Records: " + index + " " + pastSensitivity);
|
||||
if (Config.logAutosensData)
|
||||
log.debug("Records: " + index + " " + pastSensitivity);
|
||||
|
||||
double average = weightedsum / weights;
|
||||
double basalOff = average * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
||||
|
@ -197,7 +198,8 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
sensResult = "Sensitivity normal";
|
||||
}
|
||||
|
||||
log.debug(sensResult);
|
||||
if (Config.logAutosensData)
|
||||
log.debug(sensResult);
|
||||
|
||||
double rawRatio = ratio;
|
||||
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7")));
|
||||
|
@ -205,10 +207,12 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
|
||||
if (ratio != rawRatio) {
|
||||
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
|
||||
log.debug(ratioLimit);
|
||||
if (Config.logAutosensData)
|
||||
log.debug(ratioLimit);
|
||||
}
|
||||
|
||||
log.debug("Sensitivity to: " + new Date(toTime).toLocaleString() + " weightedaverage: " + average + " ratio: " + ratio);
|
||||
if (Config.logAutosensData)
|
||||
log.debug("Sensitivity to: " + new Date(toTime).toLocaleString() + " weightedaverage: " + average + " ratio: " + ratio);
|
||||
|
||||
AutosensResult output = new AutosensResult();
|
||||
output.ratio = Round.roundTo(ratio, 0.01);
|
||||
|
|
|
@ -72,9 +72,9 @@
|
|||
<string name="duration">Срок</string>
|
||||
<string name="reason">Основание</string>
|
||||
<string name="glucose">Кръвна захар</string>
|
||||
<string name="delta">Промяна</string>
|
||||
<string name="delta">Изменение (Δ)</string>
|
||||
<string name="sms_delta">Delta:</string>
|
||||
<string name="avgdelta">Средна промяна</string>
|
||||
<string name="avgdelta">Средно изменение (Δ),</string>
|
||||
<string name="configbuilder">Конфигурация</string>
|
||||
<string name="objectives">Цели</string>
|
||||
<string name="openapsma">OpenAPS MA</string>
|
||||
|
@ -85,8 +85,6 @@
|
|||
<string name="treatments">Лечения</string>
|
||||
<string name="virtualpump">Виртуална помпа</string>
|
||||
<string name="careportal">Careportal</string>
|
||||
|
||||
|
||||
<string name="configbuilder_pump">Помпа</string>
|
||||
<string name="configbuilder_treatments">Treatments</string>
|
||||
<string name="configbuilder_tempbasals">Временен базал</string>
|
||||
|
@ -140,7 +138,7 @@
|
|||
<string name="unsupportednsversion">Несъвместима версия на Nightscout</string>
|
||||
<string name="nsclientnotinstalled">NSClient не е открит. Записът е загубен!</string>
|
||||
<string name="objectives_bgavailableinns">КЗ да се вижда в NS</string>
|
||||
<string name="objectives_pumpstatusavailableinns">Статуса на помпа да е достъпен в NS</string>
|
||||
<string name="objectives_pumpstatusavailableinns">Статуса на помпата да е достъпен в NS</string>
|
||||
<string name="objectives_manualenacts">Ръчно приложени</string>
|
||||
<string name="loopdisabled">LOOP Е СПРЯН ОТ ОГРАНИЧЕНИЯТА</string>
|
||||
<string name="cs_lang">Czech</string>
|
||||
|
@ -370,7 +368,7 @@
|
|||
<string name="open_settings_on_wear">Отвори настройките на часовника</string>
|
||||
<string name="pumperror">Грешка в промпата</string>
|
||||
<string name="lowbattery">Изтощена батерия</string>
|
||||
<string name="pumpshutdown">Помпа изключена</string>
|
||||
<string name="pumpshutdown">Помпата е изключена</string>
|
||||
<string name="batterydischarged">Батерията на помпата е изтощена</string>
|
||||
<string name="danarkoreanpump">DanaR Korean</string>
|
||||
<string name="wrongpumpdriverselected">Избран е грешен тип помпа</string>
|
||||
|
@ -448,7 +446,7 @@
|
|||
<string name="openapsama_autosens_adjusttargets_summary">По подразбиране: разрешено\nТова позволява на autosens да променя и целевите КЗ(освен чувствителност и базал).</string>
|
||||
<string name="openapsama_bolussnooze_dia_divisor_summary">По подразбиране: 2\nBolus snooze се активира след като поставите болус за основно хранене, така Loop няма да пуснка/намаля базалите веднага след като сте се хранили. Примерът тук е с 2; така при 3 часа DIA това ще означава че bolus snooze ще бъде внимателно изместен 1.5 часа (3DIA/2).</string>
|
||||
<string name="openapsama_min_5m_carbimpact_summary">По подразбиране: 3.0\nТова е настройка на количеството на покачване на КЗ при усвояване на въглехидратите за всеки 5 минути. По подразбиране 3мг/дл/5мин. Това се отразява на това колко бързо се усвояват COB според алгоритъма, и как това се отразява в предвиждането на КЗ, когато тя не се покачва или пада с различен темп от очакваното.</string>
|
||||
<string name="openapsama_link_to_preferncejson_doc_txt">Внимание! Обикновенно вие не трябва да променяте тези стойности. Моля НАТИСНЕТЕ ТУК, ПРОЧЕТЕТЕ текста и бъдете сигурни, че вие го РАЗБИРАТЕ преди да направите промени на тези стойности!</string>
|
||||
<string name="openapsama_link_to_preferncejson_doc_txt">Внимание! Обикновено Вие не трябва да променяте тези стойности. Моля НАТИСНЕТЕ ТУК, прочетете текста и бъдете сигурни, че го РАЗБИРАТЕ преди да направите каквито и да е промени!</string>
|
||||
<string name="openapsama_link_to_preferncejson_doc">http://openaps.readthedocs.io/en/latest/docs/walkthrough/phase-3/beyond-low-glucose-suspend.html</string>
|
||||
<string name="error_only_numeric_digits_allowed">Позволени са само числа</string>
|
||||
<string name="error_only_numeric_digits_range_allowed" formatted="false">Позволени са числа между %1$s - %2$s</string>
|
||||
|
@ -529,7 +527,7 @@
|
|||
<string name="smscommunicator_wrongduration">Wrong duration</string>
|
||||
<string name="smscommunicator_loopsuspended">Loop suspended</string>
|
||||
<string name="smscommunicator_loopresumed">Loop resumed</string>
|
||||
<string name="treatments_wizard_bgtrend_label">промяна за 15мин</string>
|
||||
<string name="treatments_wizard_bgtrend_label">Δ за 15мин</string>
|
||||
<string name="treatments_wizard_cob_label">COB</string>
|
||||
<string name="superbolus">Суперболус</string>
|
||||
<string name="ns_logappstartedevent">Записвай всяко стартиране на AndroidAPS в NS</string>
|
||||
|
@ -652,7 +650,7 @@
|
|||
<string name="activity_duration">време за физ. активност</string>
|
||||
<string name="activity_target">Целева КЗ при физ. активност</string>
|
||||
<string name="bolusspeed">Скорост на болус</string>
|
||||
<string name="careportal_newnstreatment_percentage_label">% промяна</string>
|
||||
<string name="careportal_newnstreatment_percentage_label">% от профила</string>
|
||||
<string name="careportal_newnstreatment_timeshift_label">Време на отместване</string>
|
||||
<string name="danars_nodeviceavailable">Все още устройството не е намерено</string>
|
||||
<string name="danarspump">DanaRS</string>
|
||||
|
@ -663,14 +661,14 @@
|
|||
<string name="emptyreservoir">Празен резервоар</string>
|
||||
<string name="gettingbolusstatus">Получава болус статус</string>
|
||||
<string name="gettingextendedbolusstatus">Получава статус на удължен болус</string>
|
||||
<string name="gettingpumpsettings">Получава настройки на помпа</string>
|
||||
<string name="gettingpumptime">Получава време на помпата</string>
|
||||
<string name="gettingpumpsettings">Получава настройките на помпата</string>
|
||||
<string name="gettingpumptime">Получава времето на помпата</string>
|
||||
<string name="gettingtempbasalstatus">Получава статус на временен базал</string>
|
||||
<string name="pairing">СДВОЯВАНЕ</string>
|
||||
<string name="pairingok">Сдвоени</string>
|
||||
<string name="pairingtimedout">Времето за сдвояване изтече</string>
|
||||
<string name="pairpump">Сдвояване с нова помпа</string>
|
||||
<string name="reuse">опитва отново</string>
|
||||
<string name="reuse">отново</string>
|
||||
<string name="selectedpump">Избрана помпа</string>
|
||||
<string name="serialnumber">Сериен номер</string>
|
||||
<string name="treatments_wizard_tt_label">ЛЕЧ</string>
|
||||
|
|
|
@ -659,4 +659,8 @@
|
|||
<string name="wearcontrol_summary">Nastavování dočasných cílů a vkládání ošetření na hodinkách Wear</string>
|
||||
<string name="wearcontrol_title">Řízení z hodinek Wear</string>
|
||||
<string name="danar_model" formatted="false">Model: %02X Protokol: %02X Kód: %02X</string>
|
||||
<string name="active"><![CDATA[<Aktivní>]]></string>
|
||||
<string name="bloodsugarmeasurementalert">Výstraha měření glykémie</string>
|
||||
<string name="connectiontimedout">Vypršel čas připojování</string>
|
||||
<string name="treatments_wizard_tt_label">DC</string>
|
||||
</resources>
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
<string name="loopdisabled">LOOP DEAKTIVIERT DURCH DIE BESCHRÄNKUNG</string>
|
||||
<string name="loop_constraintsprocessed_label">Nach Beschränkungen</string>
|
||||
<string name="loop">Loop</string>
|
||||
<string name="objectives_manualenacts">Manual enacts</string>
|
||||
<string name="objectives_manualenacts">Manuelle Eingriffe</string>
|
||||
<string name="carbsconstraintapplied">Kohlenhydrate Beschränkung erreicht</string>
|
||||
<string name="nav_resetdb">Reset Datenbanken</string>
|
||||
<string name="objectives_minimalduration">Minimale Dauer</string>
|
||||
|
@ -231,7 +231,7 @@
|
|||
<string name="nobtadapter">Kein Bluetoothadapter gefunden</string>
|
||||
<string name="smscommunicator_remotebolusnotallowed">Remote Bolus ist nicht erlaubt</string>
|
||||
<string formatted="false" name="smscommunicator_bolusreplywithcode">Um Bolus %.2fU bitte mit %s antworten</string>
|
||||
<string name="ko_lang">Koreanisch</string>
|
||||
<string name="ko_lang">Korean</string>
|
||||
<string name="youareonallowedlimit">Limit erreicht</string>
|
||||
<string name="wrongpumppassword">Falsches Pumpen-Passwort!</string>
|
||||
<string name="waitingforpumpclicktorefresh">Warte auf Pumpe. Klicke zum aktualisieren.</string>
|
||||
|
@ -314,8 +314,8 @@
|
|||
<string name="loop_shortname">LOOP</string>
|
||||
<string name="localprofile_shortname">LP</string>
|
||||
<string name="danarpump_shortname">DANA</string>
|
||||
<string name="configbuilder_shortname">"CONF"</string>
|
||||
<string name="circadian_percentage_profile_shortname">"CPP"</string>
|
||||
<string name="configbuilder_shortname">CONF</string>
|
||||
<string name="circadian_percentage_profile_shortname">CPP</string>
|
||||
<string name="careportal_shortname">CP</string>
|
||||
<string name="error_only_numeric_digits_allowed">Bitte verwenden Sie nur Ziffern.</string>
|
||||
<string name="error_field_must_not_be_empty">Pflichtfeld</string>
|
||||
|
@ -591,7 +591,7 @@
|
|||
<string name="configbuilder_sensitivity">Empfindlichkeitserkennung</string>
|
||||
<string name="cob">COB</string>
|
||||
<string name="enablesuperbolus_summary">Aktiviere die SuperBolus-Funktion im Wizard. Nicht aktivieren, wenn du nicht weißt, was es macht! ES KANN ZU EINER ÜBERDOSIERUNG AN INSULIN KOMMEN, WENN DU ES BLIND BENUTZT!</string>
|
||||
<string name="objectives_2_objective">"Verstehen des OpenLoops und der Temp-Basal-Empfehlungen</string>
|
||||
<string name="objectives_2_objective">Verstehen des OpenLoops und der Temp-Basal-Empfehlungen</string>
|
||||
<string name="openapsama_useautosens">Verwende AMA Autosense</string>
|
||||
<string formatted="false" name="smscommunicator_basalreplywithcode">Um Basal mit %.2fU/h zu starten, antworte mit dem Code %s</string>
|
||||
<string name="ultrafastactinginsulincomment">Fiasp</string>
|
||||
|
|
|
@ -49,9 +49,9 @@
|
|||
</string-array>
|
||||
|
||||
<string-array name="danaSpeedArray">
|
||||
<item>12s 1U</item>
|
||||
<item>30s 1U</item>
|
||||
<item>60s 1U</item>
|
||||
<item>12 s/U</item>
|
||||
<item>30 s/U</item>
|
||||
<item>60 s/U</item>
|
||||
</string-array>
|
||||
<string-array name="danaSpeedValues">
|
||||
<item>0</item>
|
||||
|
|
|
@ -746,5 +746,9 @@
|
|||
<string name="wearcontrol_title">Controls from Watch</string>
|
||||
<string name="wearcontrol_summary">Set Temp-Targets and enter Treatments from the watch.</string>
|
||||
<string name="connectiontimedout">Connection timed out</string>
|
||||
<string name="active"><![CDATA[<Active>]]></string>
|
||||
<string name="waitingforestimatedbolusend" formatted="false">Waiting for estimated bolus end. Remaining %d sec.</string>
|
||||
<string name="processinghistory">Processing event</string>
|
||||
<string name="startingbolus">Starting bolus delivery</string>
|
||||
</resources>
|
||||
|
||||
|
|
Loading…
Reference in a new issue