consolidate DanaR code

This commit is contained in:
Milos Kozak 2017-05-12 22:40:22 +02:00
parent d641b0edd9
commit 7bbd2cff2d
37 changed files with 260 additions and 1017 deletions

View file

@ -52,7 +52,7 @@ public class DanaRPump {
public boolean isConfigUD;
public boolean isExtendedBolusEnabled;
public boolean isEasyModeEnabled;
// Status
public boolean pumpSuspended;

View file

@ -28,10 +28,11 @@ public class MsgInitConnStatusTime extends MessageBase {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).doDisconnect("Wrong Model");
log.debug("Wrong model selected. Switching to Korean DanaR");
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PUMP, true);
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentVisible(PluginBase.PUMP, true);
((DanaRPlugin)MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
((DanaRPlugin)MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginBase.PUMP, false);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
//If profile coming from pump, switch it as well
if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){

View file

@ -4,6 +4,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
/**
@ -34,6 +39,13 @@ public class MsgSettingMeal extends MessageBase {
log.debug("Block time: " + blockTime);
log.debug("Is Config U/d: " + pump.isConfigUD);
}
if (pump.isConfigUD) {
Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.sResources.getString(R.string.danar_switchtouhmode), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.UD_MODE_ENABLED));
}
}
}

View file

@ -13,7 +13,6 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
public class MsgStatusTempBasal extends MessageBase {
@ -24,9 +23,14 @@ public class MsgStatusTempBasal extends MessageBase {
}
public void handleMessage(byte[] bytes) {
boolean isTempBasalInProgress = intFromBuff(bytes, 0, 1) == 1;
boolean isTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x01) == 0x01;
boolean isAPSTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x02) == 0x02;
int tempBasalPercent = intFromBuff(bytes, 1, 1);
int tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10;
int tempBasalTotalSec;
if (intFromBuff(bytes, 2, 1) == 150) tempBasalTotalSec = 15 * 60;
else if (intFromBuff(bytes, 2, 1) == 160) tempBasalTotalSec = 30 * 60;
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0);
@ -42,6 +46,7 @@ public class MsgStatusTempBasal extends MessageBase {
if (Config.logDanaMessageDetail) {
log.debug("Is temp basal running: " + isTempBasalInProgress);
log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress);
log.debug("Current temp basal percent: " + tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + tempBasalTotalSec);

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.History.DanaRHistoryActivity;
@ -199,7 +200,7 @@ public class DanaRKoreanFragment extends Fragment {
@SuppressLint("SetTextI18n")
@Override
public void run() {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d);

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
@ -65,15 +66,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
public static DanaRKoreanExecutionService sExecutionService;
private static DanaRKoreanPump sDanaRKoreanPump = new DanaRKoreanPump();
private static DanaRPump pump = DanaRPump.getInstance();
private static boolean useExtendedBoluses = false;
public static PumpDescription pumpDescription = new PumpDescription();
public static DanaRKoreanPump getDanaRPump() {
return sDanaRKoreanPump;
}
String textStatus = "";
public DanaRKoreanPlugin() {
@ -227,12 +224,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public boolean isInitialized() {
return getDanaRPump().lastConnection.getTime() > 0 && !getDanaRPump().isConfigUD && !getDanaRPump().isEasyModeEnabled && getDanaRPump().isExtendedBolusEnabled;
return pump.lastConnection.getTime() > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
}
@Override
public boolean isSuspended() {
return getDanaRPump().pumpSuspended;
return pump.pumpSuspended;
}
@Override
@ -277,7 +274,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
public boolean isThisProfileSet(NSProfile profile) {
if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRKoreanPump pump = getDanaRPump();
if (pump.pumpProfiles == null)
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
int basalValues = pump.basal48Enable ? 48 : 24;
@ -295,7 +291,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public Date lastDataTime() {
return getDanaRPump().lastConnection;
return pump.lastConnection;
}
@Override
@ -307,7 +303,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public double getBaseBasalRate() {
return getDanaRPump().currentBasal;
return pump.currentBasal;
}
public TempBasal getTempBasal(long time) {
@ -358,7 +354,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
// Recheck pump status if older than 30 min
if (getDanaRPump().lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) {
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) {
doConnect("setTempBasalAbsolute old data");
}
@ -465,17 +461,17 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
// What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) {
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
}
// Compare with extended rate in progress
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set
result.success = true;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
result.absolute = pump.extendedBolusAbsoluteRate;
result.enacted = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.duration = pump.extendedBolusRemainingMinutes;
result.isPercent = false;
result.isTempCancel = false;
if (Config.logPumpActions)
@ -518,13 +514,13 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
return result;
}
if (percent > getPumpDescription().maxHighTempPercent) percent = getPumpDescription().maxHighTempPercent;
if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
if (pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = false;
result.success = true;
result.isTempCancel = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = getDanaRPump().tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set");
@ -532,13 +528,13 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
}
int durationInHours = Math.max(durationInMinutes / 60, 1);
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
if (connectionOK && getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true;
result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = getDanaRPump().tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK");
@ -559,28 +555,28 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
if (pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = false;
result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.isPercent = false;
result.isTempCancel = false;
if (Config.logPumpActions)
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + getDanaRPump().extendedBolusAmount + " Asked: " + insulin);
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
return result;
}
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true;
result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
result.bolusDelivered = getDanaRPump().extendedBolusAmount;
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.bolusDelivered = pump.extendedBolusAmount;
result.isPercent = false;
if (Config.logPumpActions)
log.debug("setExtendedBolus: OK");
@ -609,12 +605,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
public PumpEnactResult cancelRealTempBasal() {
PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isTempBasalInProgress) {
if (pump.isTempBasalInProgress) {
sExecutionService.tempBasalStop();
result.enacted = true;
result.isTempCancel = true;
}
if (!getDanaRPump().isTempBasalInProgress) {
if (!pump.isTempBasalInProgress) {
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
@ -633,12 +629,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress) {
if (pump.isExtendedInProgress) {
sExecutionService.extendedBolusStop();
result.enacted = true;
result.isTempCancel = true;
}
if (!getDanaRPump().isExtendedInProgress) {
if (!pump.isExtendedInProgress) {
result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions)
@ -670,21 +666,21 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public JSONObject getJSONStatus() {
if (getDanaRPump().lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) {
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) {
return null;
}
JSONObject pump = new JSONObject();
JSONObject pumpjson = new JSONObject();
JSONObject battery = new JSONObject();
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
battery.put("percent", getDanaRPump().batteryRemaining);
battery.put("percent", pump.batteryRemaining);
status.put("status", "normal");
status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection));
status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", getDanaRPump().iob);
// extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
// extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
extended.put("PumpIOB", pump.iob);
// extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
// extended.put("LastBolusAmount", pump.lastBolusAmount);
TempBasal tb = getTempBasal(new Date().getTime());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate());
@ -698,20 +694,20 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
} catch (Exception e) {
}
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", (int) getDanaRPump().reservoirRemainingUnits);
pump.put("clock", DateUtil.toISOString(new Date()));
pumpjson.put("battery", battery);
pumpjson.put("status", status);
pumpjson.put("extended", extended);
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pumpjson.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) {
e.printStackTrace();
}
return pump;
return pumpjson;
}
@Override
public String deviceID() {
return getDanaRPump().serialNumber;
return pump.serialNumber;
}
@Override
@ -747,9 +743,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public Double applyBasalConstraints(Double absoluteRate) {
double origAbsoluteRate = absoluteRate;
if (getDanaRPump() != null) {
if (absoluteRate > getDanaRPump().maxBasal) {
absoluteRate = getDanaRPump().maxBasal;
if (pump != null) {
if (absoluteRate > pump.maxBasal) {
absoluteRate = pump.maxBasal;
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h");
}
@ -772,9 +768,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override
public Double applyBolusConstraints(Double insulin) {
double origInsulin = insulin;
if (getDanaRPump() != null) {
if (insulin > getDanaRPump().maxBolus) {
insulin = getDanaRPump().maxBolus;
if (pump != null) {
if (insulin > pump.maxBolus) {
insulin = pump.maxBolus;
if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit)
log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U");
}
@ -795,7 +791,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Nullable
@Override
public NSProfile getProfile() {
DanaRKoreanPump pump = getDanaRPump();
if (pump.lastSettingsRead.getTime() == 0)
return null; // no info now
return pump.createConvertedProfile();
@ -804,13 +799,13 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
// Reply for sms communicator
public String shortStatus(boolean veryShort) {
String ret = "";
if (getDanaRPump().lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - getDanaRPump().lastConnection.getTime();
if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n";
}
// if (getDanaRPump().lastBolusTime.getTime() != 0) {
// ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\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().isTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n";
@ -819,11 +814,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
}
if (!veryShort){
ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n";
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
}
ret += "IOB: " + getDanaRPump().iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + "U\n";
ret += "Batt: " + getDanaRPump().batteryRemaining + "\n";
ret += "IOB: " + pump.iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
ret += "Batt: " + pump.batteryRemaining + "\n";
return ret;
}
// TODO: daily total constraint

View file

@ -1,167 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DecimalFormat;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SP;
/**
* Created by mike on 04.07.2016.
*/
public class DanaRKoreanPump {
public static final int UNITS_MGDL = 0;
public static final int UNITS_MMOL = 1;
public static final int DELIVERY_PRIME = 0x01;
public static final int DELIVERY_STEP_BOLUS = 0x02;
public static final int DELIVERY_BASAL = 0x04;
public static final int DELIVERY_EXT_BOLUS = 0x08;
public static final String PROFILE_PREFIX = "DanaR-";
public Date lastConnection = new Date(0);
public Date lastSettingsRead = new Date(0);
// Info
public String serialNumber = "";
public Date shippingDate = new Date(0);
public String shippingCountry = "";
public boolean isNewPump = true;
public int password = -1;
public Date pumpTime = new Date(0);
public static final int DOMESTIC_MODEL = 0x01;
public static final int EXPORT_MODEL = 0x03;
public int model;
public int protocol;
public int productCode;
public boolean pumpSuspended;
public boolean isConfigUD;
public boolean isExtendedBolusEnabled;
public boolean isEasyModeEnabled;
// Status
public double dailyTotalUnits;
public int maxDailyTotalUnits;
public double bolusStep;
public double basalStep;
public double iob;
public double reservoirRemainingUnits;
public int batteryRemaining;
public double currentBasal;
public boolean isTempBasalInProgress;
public int tempBasalPercent;
public int tempBasalRemainingMin;
public int tempBasalTotalSec;
public Date tempBasalStart;
public boolean isExtendedInProgress;
public int extendedBolusMinutes;
public double extendedBolusAmount;
public double extendedBolusAbsoluteRate;
public int extendedBolusSoFarInMinutes;
public Date extendedBolusStart;
public int extendedBolusRemainingMinutes;
// Profile
public int units;
public int easyBasalMode;
public boolean basal48Enable = false;
public int currentCIR;
public double currentCF;
public double currentAI;
public double currentTarget;
public int currentAIDR;
public int morningCIR;
public double morningCF;
public int afternoonCIR;
public double afternoonCF;
public int eveningCIR;
public double eveningCF;
public int nightCIR;
public double nightCF;
public int activeProfile = 0;
public double[][] pumpProfiles = null;
//Limits
public double maxBolus;
public double maxBasal;
public NSProfile createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();
JSONObject profile = new JSONObject();
// Morning / 6:0010:59
// Afternoon / 11:0016:59
// Evening / 17:0021:59
// Night / 22:005:59
double dia = SP.getDouble(R.string.key_danarprofile_dia, Constants.defaultDIA);
try {
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1));
json.put("store", store);
profile.put("dia", dia);
JSONArray carbratios = new JSONArray();
carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR));
carbratios.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR));
carbratios.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR));
carbratios.put(new JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR));
carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR));
profile.put("carbratio", carbratios);
JSONArray sens = new JSONArray();
sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF));
sens.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF));
sens.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF));
sens.put(new JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF));
sens.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF));
profile.put("sens", sens);
JSONArray basals = new JSONArray();
int basalValues = basal48Enable ? 48 : 24;
int basalIncrement = basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
String time;
DecimalFormat df = new DecimalFormat("00");
if (basal48Enable) {
time = df.format((long) h / 2) + ":" + df.format(30 * (h % 2));
} else {
time = df.format(h) + ":00";
}
basals.put(new JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", pumpProfiles[activeProfile][h]));
}
profile.put("basal", basals);
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)));
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)));
profile.put("units", units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL);
store.put(PROFILE_PREFIX + (activeProfile + 1), profile);
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
return null;
}
return new NSProfile(json, PROFILE_PREFIX + (activeProfile + 1));
}
}

View file

@ -14,8 +14,9 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MessageHashTable;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MessageHashTable_k;
import info.nightscout.utils.CRC;
/**
@ -72,7 +73,7 @@ public class SerialIOThread extends Thread {
message = processedMessage;
} else {
// get it from hash table
message = MessageHashTable.findMessage(command);
message = MessageHashTable_k.findMessage(command);
}
if (Config.logDanaMessageDetail)
@ -177,7 +178,7 @@ public class SerialIOThread extends Thread {
if (!message.received) {
log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) {
DanaRKoreanPlugin.getDanaRPump().isNewPump = false;
DanaRPump.getInstance().isNewPump = false;
log.debug("Old firmware detected");
}
}

View file

@ -11,8 +11,8 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.*;
/**
* Created by mike on 28.05.2016.
*/
public class MessageHashTable {
private static Logger log = LoggerFactory.getLogger(MessageHashTable.class);
public class MessageHashTable_k {
private static Logger log = LoggerFactory.getLogger(MessageHashTable_k.class);
public static HashMap<Integer, MessageBase> messages = null;
@ -24,12 +24,12 @@ public class MessageHashTable {
put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE
put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I
put(new MsgStatusBasic()); // 0x020A CMD_PUMP_INITVIEW_I
put(new MsgStatus()); // 0x020B CMD_PUMP_STATUS
put(new MsgInitConnStatusTime()); // 0x0301 CMD_PUMPINIT_TIME_INFO
put(new MsgInitConnStatusBolus()); // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(new MsgInitConnStatusBasic()); // 0x0303 CMD_PUMPINIT_INIT_INFO
put(new MsgStatusBolusExtended_k()); // 0x0207 CMD_PUMP_EXPANS_INS_I
put(new MsgStatusBasic_k()); // 0x020A CMD_PUMP_INITVIEW_I
put(new MsgStatus_k()); // 0x020B CMD_PUMP_STATUS
put(new MsgInitConnStatusTime_k()); // 0x0301 CMD_PUMPINIT_TIME_INFO
put(new MsgInitConnStatusBolus_k()); // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(new MsgInitConnStatusBasic_k()); // 0x0303 CMD_PUMPINIT_INIT_INFO
put(new MsgSetTempBasalStart()); // 0x0401 CMD_PUMPSET_EXERCISE_S
put(new MsgSetCarbsEntry()); // 0x0402 CMD_PUMPSET_HIS_S
put(new MsgSetTempBasalStop()); // 0x0403 CMD_PUMPSET_EXERCISE_STOP
@ -43,11 +43,11 @@ public class MessageHashTable {
put(new MsgHistoryGlucose()); // 0x3104 CMD_HISTORY_GLUCOSE
put(new MsgHistoryAlarm()); // 0x3105 CMD_HISTORY_ALARM
put(new MsgHistoryCarbo()); // 0x3107 CMD_HISTORY_CARBOHY
put(new MsgSettingBasal()); // 0x3202 CMD_SETTING_V_BASAL_INS_I
put(new MsgSettingBasal_k()); // 0x3202 CMD_SETTING_V_BASAL_INS_I
put(new MsgSettingMeal()); // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
put(new MsgSettingProfileRatios()); // 0x3204 CMD_SETTING_V_CCC_I
put(new MsgSettingMaxValues()); // 0x3205 CMD_SETTING_V_MAX_VALUE_I
put(new MsgSettingBasalProfileAll()); // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(new MsgSettingBasalProfileAll_k()); // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(new MsgSettingShippingInfo()); // 0x3207 CMD_SETTING_V_SHIPPING_I
put(new MsgSettingGlucose()); // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(new MsgSettingPumpTime()); // 0x320A CMD_SETTING_V_TIME_I
@ -55,7 +55,7 @@ public class MessageHashTable {
put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL
put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE
put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW
put(new MsgCheckValue()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(new MsgCheckValue_k()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
}
}

View file

@ -6,32 +6,32 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
import info.nightscout.utils.ToastUtils;
/**
* Created by mike on 30.06.2016.
*/
public class MsgCheckValue extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgCheckValue.class);
public class MsgCheckValue_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgCheckValue_k.class);
public MsgCheckValue() {
public MsgCheckValue_k() {
SetCommand(0xF0F1);
}
@Override
public void handleMessage(byte[] bytes) {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
DanaRPump pump = DanaRPump.getInstance();
DanaRKoreanPlugin.getDanaRPump().isNewPump = true;
pump.isNewPump = true;
log.debug("New firmware confirmed");
pump.model = intFromBuff(bytes, 0, 1);
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRKoreanPump.DOMESTIC_MODEL) {
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).doDisconnect("Wrong Model");
log.debug("Wrong model selected");

View file

@ -6,17 +6,16 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
public class MsgInitConnStatusBasic extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusBasic.class);
public class MsgInitConnStatusBasic_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusBasic_k.class);
public MsgInitConnStatusBasic() {
public MsgInitConnStatusBasic_k() {
SetCommand(0x0303);
}
@ -25,7 +24,7 @@ public class MsgInitConnStatusBasic extends MessageBase {
if (bytes.length - 10 > 6) {
return;
}
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
DanaRPump pump = DanaRPump.getInstance();
pump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1;
int isUtilityEnable = intFromBuff(bytes, 1, 1);
pump.isEasyModeEnabled = intFromBuff(bytes, 2, 1) == 1;

View file

@ -6,9 +6,8 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -16,10 +15,10 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
* Created by mike on 28.05.2016.
*/
public class MsgInitConnStatusBolus extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusBolus.class);
public class MsgInitConnStatusBolus_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusBolus_k.class);
public MsgInitConnStatusBolus() {
public MsgInitConnStatusBolus_k() {
SetCommand(0x0302);
}
@ -28,7 +27,7 @@ public class MsgInitConnStatusBolus extends MessageBase {
if (bytes.length - 10 < 13) {
return;
}
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
DanaRPump pump = DanaRPump.getInstance();
int bolusConfig = intFromBuff(bytes, 0, 1);
pump.isExtendedBolusEnabled = (bolusConfig & 0x01) != 0;

View file

@ -11,14 +11,15 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.utils.ToastUtils;
public class MsgInitConnStatusTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime.class);
public class MsgInitConnStatusTime_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime_k.class);
public MsgInitConnStatusTime() {
public MsgInitConnStatusTime_k() {
SetCommand(0x0301);
}
@ -29,10 +30,11 @@ public class MsgInitConnStatusTime extends MessageBase {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).doDisconnect("Wrong Model");
log.debug("Wrong model selected. Switching to export DanaR");
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentVisible(PluginBase.PUMP, false);
((DanaRPlugin)MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PUMP, true);
((DanaRPlugin)MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginBase.PUMP, true);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
//If profile coming from pump, switch it as well
if(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)){

View file

@ -4,9 +4,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
@ -15,16 +14,16 @@ import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
* <p/>
* THIS IS BROKEN IN PUMP... SENDING ONLY 1 PROFILE
*/
public class MsgSettingBasalProfileAll extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingBasalProfileAll.class);
public class MsgSettingBasalProfileAll_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingBasalProfileAll_k.class);
public MsgSettingBasalProfileAll() {
public MsgSettingBasalProfileAll_k() {
SetCommand(0x3206);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
if (DanaRKoreanPlugin.getDanaRPump().basal48Enable) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.basal48Enable) {
pump.pumpProfiles = new double[4][];
for (int profile = 0; profile < 4; profile++) {
int position = intFromBuff(bytes, 107 * profile, 1);
@ -51,10 +50,10 @@ public class MsgSettingBasalProfileAll extends MessageBase {
}
if (Config.logDanaMessageDetail) {
if (DanaRKoreanPlugin.getDanaRPump().basal48Enable) {
if (pump.basal48Enable) {
for (int profile = 0; profile < 4; profile++) {
for (int index = 0; index < 24; index++) {
log.debug("Basal profile " + profile + ": " + String.format("%02d", index) + "h: " + DanaRKoreanPlugin.getDanaRPump().pumpProfiles[profile][index]);
log.debug("Basal profile " + profile + ": " + String.format("%02d", index) + "h: " + pump.pumpProfiles[profile][index]);
}
}
} else {
@ -63,7 +62,7 @@ public class MsgSettingBasalProfileAll extends MessageBase {
log.debug("Basal profile " + profile + ": " +
String.format("%02d", (index / 2)) +
":" + String.format("%02d", (index % 2) * 30) + " : " +
DanaRKoreanPlugin.getDanaRPump().pumpProfiles[profile][index]);
pump.pumpProfiles[profile][index]);
}
}
}

View file

@ -4,22 +4,22 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingBasal.class);
public class MsgSettingBasal_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingBasal_k.class);
public MsgSettingBasal() {
public MsgSettingBasal_k() {
SetCommand(0x3202);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
DanaRPump pump = DanaRPump.getInstance();
if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][];
pump.pumpProfiles[pump.activeProfile] = new double[24];
for (int index = 0; index < 24; index++) {
@ -30,7 +30,7 @@ public class MsgSettingBasal extends MessageBase {
if (Config.logDanaMessageDetail)
for (int index = 0; index < 24; index++) {
log.debug("Basal " + String.format("%02d", index) + "h: " + DanaRKoreanPlugin.getDanaRPump().pumpProfiles[DanaRKoreanPlugin.getDanaRPump().activeProfile][index]);
log.debug("Basal " + String.format("%02d", index) + "h: " + pump.pumpProfiles[pump.activeProfile][index]);
}
}
}

View file

@ -1,30 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingGlucose extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingGlucose.class);
public MsgSettingGlucose() {
SetCommand(0x3209);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPlugin.getDanaRPump().units = intFromBuff(bytes, 0, 1);
DanaRKoreanPlugin.getDanaRPump().easyBasalMode = intFromBuff(bytes, 1, 1);
if (Config.logDanaMessageDetail) {
log.debug("Pump units: " + (DanaRKoreanPlugin.getDanaRPump().units == DanaRKoreanPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Easy basal mode: " + DanaRKoreanPlugin.getDanaRPump().easyBasalMode);
}
}
}

View file

@ -1,33 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingMaxValues extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingMaxValues.class);
public MsgSettingMaxValues() {
SetCommand(0x3205);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPlugin.getDanaRPump().maxBolus = intFromBuff(bytes, 0, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().maxBasal = intFromBuff(bytes, 2, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().maxDailyTotalUnits = intFromBuff(bytes, 4, 2) / 100;
if (Config.logDanaMessageDetail) {
log.debug("Max bolus: " + DanaRKoreanPlugin.getDanaRPump().maxBolus);
log.debug("Max basal: " + DanaRKoreanPlugin.getDanaRPump().maxBasal);
log.debug("Total daily max units: " + DanaRKoreanPlugin.getDanaRPump().maxDailyTotalUnits);
}
}
}

View file

@ -1,53 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
* Created by mike on 13.12.2016.
*/
public class MsgSettingMeal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingMeal.class);
public MsgSettingMeal() {
SetCommand(0x3203);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
pump.basalStep = intFromBuff(bytes, 0, 1) / 100d;
pump.bolusStep = intFromBuff(bytes, 1, 1) / 100d;
boolean bolusEnabled = intFromBuff(bytes, 2, 1) == 1;
int melodyTime = intFromBuff(bytes, 3, 1);
int blockTime = intFromBuff(bytes, 4, 1);
pump.isConfigUD = intFromBuff(bytes, 5, 1) == 1;
if (Config.logDanaMessageDetail) {
log.debug("Basal step: " + pump.basalStep);
log.debug("Bolus step: " + pump.bolusStep);
log.debug("Bolus enabled: " + bolusEnabled);
log.debug("Melody time: " + melodyTime);
log.debug("Block time: " + blockTime);
log.debug("Is Config U/d: " + pump.isConfigUD);
}
if (pump.isConfigUD) {
Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.sResources.getString(R.string.danar_switchtouhmode), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.UD_MODE_ENABLED));
}
}
}

View file

@ -1,45 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingProfileRatios extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingProfileRatios.class);
public MsgSettingProfileRatios() {
SetCommand(0x3204);
}
public void handleMessage(byte[] bytes) {
if (DanaRKoreanPlugin.getDanaRPump().units == DanaRKoreanPump.UNITS_MGDL) {
DanaRKoreanPlugin.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2);
DanaRKoreanPlugin.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2);
DanaRKoreanPlugin.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2);
DanaRKoreanPlugin.getDanaRPump().currentAIDR = intFromBuff(bytes, 8, 1);
} else {
DanaRKoreanPlugin.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2);
DanaRKoreanPlugin.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentAIDR = intFromBuff(bytes, 8, 1);
}
if (Config.logDanaMessageDetail) {
log.debug("Pump units (saved): " + (DanaRKoreanPlugin.getDanaRPump().units == DanaRKoreanPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Current pump CIR: " + DanaRKoreanPlugin.getDanaRPump().currentCIR);
log.debug("Current pump CF: " + DanaRKoreanPlugin.getDanaRPump().currentCF);
log.debug("Current pump AI: " + DanaRKoreanPlugin.getDanaRPump().currentAI);
log.debug("Current pump target: " + DanaRKoreanPlugin.getDanaRPump().currentTarget);
log.debug("Current pump AIDR: " + DanaRKoreanPlugin.getDanaRPump().currentAIDR);
}
}
}

View file

@ -1,35 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
public class MsgSettingPumpTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingPumpTime.class);
public MsgSettingPumpTime() {
SetCommand(0x320A);
}
public void handleMessage(byte[] bytes) {
Date time =
new Date(
100 + intFromBuff(bytes, 5, 1),
intFromBuff(bytes, 4, 1) - 1,
intFromBuff(bytes, 3, 1),
intFromBuff(bytes, 2, 1),
intFromBuff(bytes, 1, 1),
intFromBuff(bytes, 0, 1)
);
if (Config.logDanaMessageDetail)
log.debug("Pump time: " + time);
DanaRKoreanPlugin.getDanaRPump().pumpTime = time;
}
}

View file

@ -1,33 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingShippingInfo extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSettingShippingInfo.class);
public MsgSettingShippingInfo() {
SetCommand(0x3207);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
pump.serialNumber = stringFromBuff(bytes, 0, 10);
pump.shippingDate = dateFromBuff(bytes, 10);
pump.shippingCountry = asciiStringFromBuff(bytes, 13, 3);
if (Config.logDanaMessageDetail) {
log.debug("Serial number: " + pump.serialNumber);
log.debug("Shipping date: " + pump.shippingDate);
log.debug("Shipping country: " + pump.shippingCountry);
}
}
}

View file

@ -1,39 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
public class MsgStatus extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatus.class);
public MsgStatus() {
SetCommand(0x020B);
}
public void handleMessage(byte[] bytes) {
DanaRKoreanPlugin.getDanaRPump().dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750d;
DanaRKoreanPlugin.getDanaRPump().isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1;
DanaRKoreanPlugin.getDanaRPump().extendedBolusMinutes = intFromBuff(bytes, 4, 2);
DanaRKoreanPlugin.getDanaRPump().extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100d;
Double lastBolusAmount = intFromBuff(bytes, 13, 2) / 100d;
// if (lastBolusAmount != 0d) {
// DanaRKoreanPlugin.getDanaRPump().lastBolusTime = dateTimeFromBuff(bytes, 8);
// DanaRKoreanPlugin.getDanaRPump().lastBolusAmount = lastBolusAmount;
// }
DanaRKoreanPlugin.getDanaRPump().iob = intFromBuff(bytes, 15, 2) / 100d;
if (Config.logDanaMessageDetail) {
log.debug("Daily total: " + DanaRKoreanPlugin.getDanaRPump().dailyTotalUnits);
log.debug("Is extended bolus running: " + DanaRKoreanPlugin.getDanaRPump().isExtendedInProgress);
log.debug("Extended bolus min: " + DanaRKoreanPlugin.getDanaRPump().extendedBolusMinutes);
log.debug("Extended bolus amount: " + DanaRKoreanPlugin.getDanaRPump().extendedBolusAmount);
// log.debug("Last bolus time: " + DanaRKoreanPlugin.getDanaRPump().lastBolusTime);
// log.debug("Last bolus amount: " + DanaRKoreanPlugin.getDanaRPump().lastBolusAmount);
log.debug("IOB: " + DanaRKoreanPlugin.getDanaRPump().iob);
}
}
}

View file

@ -4,29 +4,30 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
public class MsgStatusBasic extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusBasic.class);
public class MsgStatusBasic_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusBasic_k.class);
public MsgStatusBasic() {
public MsgStatusBasic_k() {
SetCommand(0x020A);
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
double currentBasal = intFromBuff(bytes, 0, 2) / 100d;
int batteryRemaining = intFromBuff(bytes, 2, 1);
double reservoirRemainingUnits = intFromBuff(bytes, 3, 3) / 750d;
double dailyTotalUnits = intFromBuff(bytes, 6, 3) / 750d;
int maxDailyTotalUnits = intFromBuff(bytes, 9, 2) / 100;
DanaRKoreanPlugin.getDanaRPump().dailyTotalUnits = dailyTotalUnits;
DanaRKoreanPlugin.getDanaRPump().maxDailyTotalUnits = maxDailyTotalUnits;
DanaRKoreanPlugin.getDanaRPump().reservoirRemainingUnits = reservoirRemainingUnits;
DanaRKoreanPlugin.getDanaRPump().currentBasal = currentBasal;
DanaRKoreanPlugin.getDanaRPump().batteryRemaining = batteryRemaining;
pump.dailyTotalUnits = dailyTotalUnits;
pump.maxDailyTotalUnits = maxDailyTotalUnits;
pump.reservoirRemainingUnits = reservoirRemainingUnits;
pump.currentBasal = currentBasal;
pump.batteryRemaining = batteryRemaining;
if (Config.logDanaMessageDetail) {
log.debug("Daily total units: " + dailyTotalUnits);

View file

@ -1,116 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
public class MsgStatusBolusExtended extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended.class);
public MsgStatusBolusExtended() {
SetCommand(0x0207);
}
public void handleMessage(byte[] bytes) {
boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1;
int extendedBolusHalfHours = intFromBuff(bytes, 1, 1);
int extendedBolusMinutes = extendedBolusHalfHours * 30;
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0);
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
DanaRKoreanPlugin.getDanaRPump().isExtendedInProgress = isExtendedInProgress;
DanaRKoreanPlugin.getDanaRPump().extendedBolusMinutes = extendedBolusMinutes;
DanaRKoreanPlugin.getDanaRPump().extendedBolusAmount = extendedBolusAmount;
DanaRKoreanPlugin.getDanaRPump().extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes;
DanaRKoreanPlugin.getDanaRPump().extendedBolusAbsoluteRate = extendedBolusAbsoluteRate;
DanaRKoreanPlugin.getDanaRPump().extendedBolusStart = extendedBolusStart;
DanaRKoreanPlugin.getDanaRPump().extendedBolusRemainingMinutes = extendedBolusRemainingMinutes;
updateExtendedBolusInDB();
if (Config.logDanaMessageDetail) {
log.debug("Is extended bolus running: " + isExtendedInProgress);
log.debug("Extended bolus min: " + extendedBolusMinutes);
log.debug("Extended bolus amount: " + extendedBolusAmount);
log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes);
log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate);
log.debug("Extended bolus start: " + extendedBolusStart);
log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes);
}
}
@NonNull
private Date getDateFromSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
}
public static void updateExtendedBolusInDB() {
DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump();
Date now = new Date();
try {
if (treatmentsInterface.isExtendedBoluslInProgress()) {
TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
if (danaRKoreanPump.isExtendedInProgress) {
if (extendedBolus.absolute != danaRKoreanPump.extendedBolusAbsoluteRate) {
// Close current extended
extendedBolus.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
// Create new
TempBasal newExtended = new TempBasal();
newExtended.timeStart = now;
newExtended.absolute = danaRKoreanPump.extendedBolusAbsoluteRate;
newExtended.isAbsolute = true;
newExtended.duration = danaRKoreanPump.extendedBolusMinutes;
newExtended.isExtended = true;
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
// Close curent temp basal
extendedBolus.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
if (danaRKoreanPump.isExtendedInProgress) {
// Create new
TempBasal newExtended = new TempBasal();
newExtended.timeStart = now;
newExtended.absolute = danaRKoreanPump.extendedBolusAbsoluteRate;
newExtended.isAbsolute = true;
newExtended.duration = danaRKoreanPump.extendedBolusMinutes;
newExtended.isExtended = true;
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
MainApp.bus().post(new EventTempBasalChange());
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import android.support.annotation.NonNull;
@ -15,29 +15,30 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
public class MsgStatusBolusExtended extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended.class);
public class MsgStatusBolusExtended_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended_k.class);
public MsgStatusBolusExtended() {
public MsgStatusBolusExtended_k() {
SetCommand(0x0207);
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1;
int extendedBolusHalfHours = intFromBuff(bytes, 1, 1);
int extendedBolusMinutes = extendedBolusHalfHours * 30;
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0);
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
DanaRPump pump = DanaRPump.getInstance();
pump.isExtendedInProgress = isExtendedInProgress;
pump.extendedBolusMinutes = extendedBolusMinutes;
pump.extendedBolusAmount = extendedBolusAmount;

View file

@ -1,43 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgStatusProfile extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusProfile.class);
public MsgStatusProfile() {
SetCommand(0x0204);
}
public void handleMessage(byte[] bytes) {
if (DanaRKoreanPlugin.getDanaRPump().units == DanaRKoreanPump.UNITS_MGDL) {
DanaRKoreanPlugin.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2);
DanaRKoreanPlugin.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2);
DanaRKoreanPlugin.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2);
} else {
DanaRKoreanPlugin.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2);
DanaRKoreanPlugin.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d;
DanaRKoreanPlugin.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100d;
}
if (Config.logDanaMessageDetail) {
log.debug("Pump units (saved): " + (DanaRKoreanPlugin.getDanaRPump().units == DanaRKoreanPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Current pump CIR: " + DanaRKoreanPlugin.getDanaRPump().currentCIR);
log.debug("Current pump CF: " + DanaRKoreanPlugin.getDanaRPump().currentCF);
log.debug("Current pump AI: " + DanaRKoreanPlugin.getDanaRPump().currentAI);
log.debug("Current pump target: " + DanaRKoreanPlugin.getDanaRPump().currentTarget);
log.debug("Current pump AIDR: " + DanaRKoreanPlugin.getDanaRPump().currentAIDR);
}
}
}

View file

@ -1,105 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
public class MsgStatusTempBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusTempBasal.class);
public MsgStatusTempBasal() {
SetCommand(0x0205);
}
public void handleMessage(byte[] bytes) {
boolean isTempBasalInProgress = intFromBuff(bytes, 0, 1) == 1;
int tempBasalPercent = intFromBuff(bytes, 1, 1);
int tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0);
DanaRKoreanPlugin.getDanaRPump().isTempBasalInProgress = isTempBasalInProgress;
DanaRKoreanPlugin.getDanaRPump().tempBasalPercent = tempBasalPercent;
DanaRKoreanPlugin.getDanaRPump().tempBasalRemainingMin = tempBasalRemainingMin;
DanaRKoreanPlugin.getDanaRPump().tempBasalTotalSec = tempBasalTotalSec;
DanaRKoreanPlugin.getDanaRPump().tempBasalStart = tempBasalStart;
updateTempBasalInDB();
if (Config.logDanaMessageDetail) {
log.debug("Is temp basal running: " + isTempBasalInProgress);
log.debug("Current temp basal percent: " + tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + tempBasalTotalSec);
log.debug("Current temp basal start: " + tempBasalStart);
}
}
@NonNull
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
}
public static void updateTempBasalInDB() {
DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump();
Date now = new Date();
try {
if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRKoreanPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRKoreanPump.tempBasalPercent) {
// Close current temp basal
tempBasal.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
// Create new
TempBasal newTempBasal = new TempBasal();
newTempBasal.timeStart = now;
newTempBasal.percent = danaRKoreanPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.duration = danaRKoreanPump.tempBasalTotalSec / 60;
newTempBasal.isExtended = false;
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
// Close current temp basal
tempBasal.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
if (danaRKoreanPump.isTempBasalInProgress) {
// Create new
TempBasal newTempBasal = new TempBasal();
newTempBasal.timeStart = now;
newTempBasal.percent = danaRKoreanPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.duration = danaRKoreanPump.tempBasalTotalSec / 60;
newTempBasal.isExtended = false;
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,40 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
public class MsgStatus_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatus_k.class);
public MsgStatus_k() {
SetCommand(0x020B);
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750d;
pump.isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1;
pump.extendedBolusMinutes = intFromBuff(bytes, 4, 2);
pump.extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100d;
Double lastBolusAmount = intFromBuff(bytes, 13, 2) / 100d;
// if (lastBolusAmount != 0d) {
// pump.lastBolusTime = dateTimeFromBuff(bytes, 8);
// pump.lastBolusAmount = lastBolusAmount;
// }
pump.iob = intFromBuff(bytes, 15, 2) / 100d;
if (Config.logDanaMessageDetail) {
log.debug("Daily total: " + pump.dailyTotalUnits);
log.debug("Is extended bolus running: " + pump.isExtendedInProgress);
log.debug("Extended bolus min: " + pump.extendedBolusMinutes);
log.debug("Extended bolus amount: " + pump.extendedBolusAmount);
// log.debug("Last bolus time: " + pump.lastBolusTime);
// log.debug("Last bolus amount: " + pump.lastBolusAmount);
log.debug("IOB: " + pump.iob);
}
}
}

View file

@ -33,6 +33,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
@ -56,26 +57,25 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetSingleBasalProfil
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStart;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTempBasalStop;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetTime;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingGlucose;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMaxValues;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingGlucose;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingMaxValues;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingMeal;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingProfileRatios;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingPumpTime;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingShippingInfo;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBolusExtended;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue_k;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal_k;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic_k;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBolusExtended_k;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
@ -91,7 +91,7 @@ public class DanaRKoreanExecutionService extends Service {
private PowerManager.WakeLock mWakeLock;
private IBinder mBinder = new LocalBinder();
private DanaRKoreanPump danaRKoreanPump;
private DanaRPump danaRPump = DanaRPump.getInstance();
private Treatment bolusingTreatment = null;
private static Boolean connectionInProgress = false;
@ -119,7 +119,6 @@ public class DanaRKoreanExecutionService extends Service {
public DanaRKoreanExecutionService() {
registerBus();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump();
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRKoreanExecutionService");
@ -180,7 +179,7 @@ public class DanaRKoreanExecutionService extends Service {
}
public void connect(String from) {
if (danaRKoreanPump.password != -1 && danaRKoreanPump.password != SP.getInt(R.string.key_danar_password, -1)) {
if (danaRPump.password != -1 && danaRPump.password != SP.getInt(R.string.key_danar_password, -1)) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
return;
}
@ -274,13 +273,13 @@ public class DanaRKoreanExecutionService extends Service {
private boolean getPumpStatus() {
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
//MsgStatus statusMsg = new MsgStatus();
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
//MsgStatus_k statusMsg = new MsgStatus_k();
MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue checkValue = new MsgCheckValue();
MsgStatusBolusExtended_k exStatusMsg = new MsgStatusBolusExtended_k();
MsgCheckValue_k checkValue = new MsgCheckValue_k();
if (danaRKoreanPump.isNewPump) {
if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return false;
@ -316,28 +315,28 @@ public class DanaRKoreanExecutionService extends Service {
}
Date now = new Date();
if (danaRKoreanPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).isInitialized()) {
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).isInitialized()) {
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingMeal());
mSerialIOThread.sendMessage(new MsgSettingBasal());
mSerialIOThread.sendMessage(new MsgSettingBasal_k());
//0x3201
mSerialIOThread.sendMessage(new MsgSettingMaxValues());
mSerialIOThread.sendMessage(new MsgSettingGlucose());
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
danaRKoreanPump.lastSettingsRead = now;
danaRPump.lastSettingsRead = now;
}
danaRKoreanPump.lastConnection = now;
danaRPump.lastConnection = now;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
MainApp.getConfigBuilder().uploadDeviceStatus();
if (danaRKoreanPump.dailyTotalUnits > danaRKoreanPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
log.debug("Approaching daily limit: " + danaRKoreanPump.dailyTotalUnits + "/" + danaRKoreanPump.maxDailyTotalUnits);
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(reportFail));
MainApp.getConfigBuilder().uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRKoreanPump.dailyTotalUnits + "/" + danaRKoreanPump.maxDailyTotalUnits + "U");
MainApp.getConfigBuilder().uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
}
} catch (Exception e) {
e.printStackTrace();
@ -370,7 +369,7 @@ public class DanaRKoreanExecutionService extends Service {
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_k());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
@ -380,7 +379,7 @@ public class DanaRKoreanExecutionService extends Service {
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_k());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
@ -498,7 +497,7 @@ public class DanaRKoreanExecutionService extends Service {
double[] basal = buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet);
danaRKoreanPump.lastSettingsRead = new Date(0); // force read full settings
danaRPump.lastSettingsRead = new Date(0); // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;

View file

@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2;
import info.nightscout.utils.CRC;
/**
@ -72,7 +72,7 @@ public class SerialIOThread extends Thread {
message = processedMessage;
} else {
// get it from hash table
message = MessageHashTable.findMessage(command);
message = MessageHashTable_v2.findMessage(command);
}
if (Config.logDanaMessageDetail)

View file

@ -12,8 +12,8 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.*;
/**
* Created by mike on 28.05.2016.
*/
public class MessageHashTable {
private static Logger log = LoggerFactory.getLogger(MessageHashTable.class);
public class MessageHashTable_v2 {
private static Logger log = LoggerFactory.getLogger(MessageHashTable_v2.class);
public static HashMap<Integer, MessageBase> messages = null;
@ -68,10 +68,10 @@ public class MessageHashTable {
put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL
put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE
put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW
put(new MsgCheckValue()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(new MsgStatusAPS()); // 0xE001 CMD_PUMP_APS
put(new MsgSetAPSTempBasalStart()); // 0xE002 CMD_PUMPSET_APSTEMP
put(new MsgHistoryEvents()); // 0xE003 CMD_HISTORY_EVENTS
put(new MsgCheckValue_v2()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(new MsgStatusAPS_v2()); // 0xE001 CMD_PUMP_APS
put(new MsgSetAPSTempBasalStart_v2()); // 0xE002 CMD_PUMPSET_APSTEMP
put(new MsgHistoryEvents_v2()); // 0xE003 CMD_HISTORY_EVENTS
}
}

View file

@ -18,10 +18,10 @@ import info.nightscout.utils.ToastUtils;
/**
* Created by mike on 30.06.2016.
*/
public class MsgCheckValue extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgCheckValue.class);
public class MsgCheckValue_v2 extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgCheckValue_v2.class);
public MsgCheckValue() {
public MsgCheckValue_v2() {
SetCommand(0xF0F1);
}
@ -37,13 +37,13 @@ public class MsgCheckValue extends MessageBase {
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.EXPORT_MODEL) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
((DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class)).doDisconnect("Wrong Model");
DanaRv2Plugin.doDisconnect("Wrong Model");
log.debug("Wrong model selected");
}
if (pump.protocol != 2) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
((DanaRv2Plugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).doDisconnect("Wrong Model");
DanaRKoreanPlugin.doDisconnect("Wrong Model");
log.debug("Wrong model selected. Switching to non APS DanaR");
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginBase.PUMP, false);

View file

@ -9,11 +9,11 @@ import java.util.GregorianCalendar;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.utils.DateUtil;
public class MsgHistoryEvents extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents.class);
public class MsgHistoryEvents_v2 extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents_v2.class);
public boolean done;
public MsgHistoryEvents(Date from) {
public MsgHistoryEvents_v2(Date from) {
SetCommand(0xE003);
GregorianCalendar gfrom = new GregorianCalendar();
gfrom.setTimeInMillis(from.getTime());
@ -21,7 +21,7 @@ public class MsgHistoryEvents extends MessageBase {
done = false;
}
public MsgHistoryEvents() {
public MsgHistoryEvents_v2() {
SetCommand(0xE003);
AddParamByte((byte) 0);
AddParamByte((byte) 1);

View file

@ -6,14 +6,14 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
public class MsgSetAPSTempBasalStart extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSetAPSTempBasalStart.class);
public class MsgSetAPSTempBasalStart_v2 extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSetAPSTempBasalStart_v2.class);
public MsgSetAPSTempBasalStart() {
public MsgSetAPSTempBasalStart_v2() {
SetCommand(0xE002);
}
public MsgSetAPSTempBasalStart(int percent) {
public MsgSetAPSTempBasalStart_v2(int percent) {
this();
//HARDCODED LIMITS

View file

@ -7,10 +7,10 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
public class MsgStatusAPS extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusAPS.class);
public class MsgStatusAPS_v2 extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusAPS_v2.class);
public MsgStatusAPS() {
public MsgStatusAPS_v2() {
SetCommand(0xE001);
}

View file

@ -1,111 +0,0 @@
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
public class MsgStatusTempBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusTempBasal.class);
public MsgStatusTempBasal() {
SetCommand(0x0205);
}
public void handleMessage(byte[] bytes) {
boolean isTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x01) == 0x01;
boolean isAPSTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x02) == 0x02;
int tempBasalPercent = intFromBuff(bytes, 1, 1);
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10;
int tempBasalTotalSec;
if (intFromBuff(bytes, 2, 1) == 150) tempBasalTotalSec = 15 * 60;
else if (intFromBuff(bytes, 2, 1) == 160) tempBasalTotalSec = 30 * 60;
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0);
DanaRPump pump = DanaRPump.getInstance();
pump.isTempBasalInProgress = isTempBasalInProgress;
pump.tempBasalPercent = tempBasalPercent;
pump.tempBasalRemainingMin = tempBasalRemainingMin;
pump.tempBasalTotalSec = tempBasalTotalSec;
pump.tempBasalStart = tempBasalStart;
updateTempBasalInDB();
if (Config.logDanaMessageDetail) {
log.debug("Is temp basal running: " + isTempBasalInProgress);
log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress);
log.debug("Current temp basal percent: " + tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + tempBasalTotalSec);
log.debug("Current temp basal start: " + tempBasalStart);
}
}
@NonNull
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
}
public static void updateTempBasalInDB() {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRPump danaRPump = DanaRPump.getInstance();
Date now = new Date();
try {
if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRPump.tempBasalPercent) {
// Close current temp basal
tempBasal.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
// Create new
TempBasal newTempBasal = new TempBasal();
newTempBasal.timeStart = now;
newTempBasal.percent = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.duration = danaRPump.tempBasalTotalSec / 60;
newTempBasal.isExtended = false;
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
// Close current temp basal
tempBasal.timeEnd = now;
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
} else {
if (danaRPump.isTempBasalInProgress) {
// Create new
TempBasal newTempBasal = new TempBasal();
newTempBasal.timeStart = now;
newTempBasal.percent = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.duration = danaRPump.tempBasalTotalSec / 60;
newTempBasal.isExtended = false;
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View file

@ -42,12 +42,10 @@ import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
@ -250,7 +248,7 @@ public class DanaRv2ExecutionService extends Service {
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue checkValue = new MsgCheckValue();
MsgCheckValue_v2 checkValue = new MsgCheckValue_v2();
if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
@ -335,8 +333,8 @@ public class DanaRv2ExecutionService extends Service {
connect("highTempBasal");
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart(percent));
mSerialIOThread.sendMessage(new MsgStatusAPS());
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent));
mSerialIOThread.sendMessage(new MsgStatusAPS_v2());
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
@ -479,7 +477,7 @@ public class DanaRv2ExecutionService extends Service {
public boolean loadEvents() {
if (!isConnected()) return false;
MsgHistoryEvents msg = new MsgHistoryEvents();
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2();
mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) {
waitMsec(100);