DanaRv2 Modify 6

This commit is contained in:
Milos Kozak 2017-05-12 00:38:26 +02:00
parent 5b25d28f42
commit 2610edae55
5 changed files with 73 additions and 12 deletions

View file

@ -155,9 +155,10 @@ public class MessageOriginalNames {
messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP"); messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP");
messageNames.put(0xE003, "CMD_HISTORY_APSTEMP"); messageNames.put(0xE003, "CMD_HISTORY_APSTEMP");
messageNames.put(0xE001, "CMD_PUMP_APSTEMP_VALUE"); messageNames.put(0xE001, "CMD_PUMP_APS");
messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP"); messageNames.put(0xE002, "CMD_PUMPSET_APS");
messageNames.put(0xE003, "CMD_HISTORY_APSTEMP"); messageNames.put(0xE003, "CMD_HISTORY_APS");
messageNames.put(0xE004, "CMD_PUMPSET_APSTEMP");
} }

View file

@ -117,9 +117,10 @@ public class MessageHashTable {
put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE
put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW
put(new MsgCheckValue()); // 0xF0F1 CMD_PUMP_CHECK_VALUE put(new MsgCheckValue()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(new MsgStatusAPSTempBasal()); // 0xE001 CMD_PUMP_APSTEMP_VALUE put(new MsgStatusAPS()); // 0xE001 CMD_PUMP_APS
put(new MsgSetAPSTempBasalStart()); // 0xE002 CMD_PUMPSET_APSTEMP put(new MsgSetAPSTempBasalStart()); // 0xE002 CMD_PUMPSET_APSTEMP
put(new MsgHistoryEvents()); // 0xE003 CMD_HISTORY_EVENTS put(new MsgHistoryEvents()); // 0xE003 CMD_HISTORY_EVENTS
put(new MsgStatusAPSTempBasal()); // 0xE004 CMD_PUMP_APSTEMP
} }
} }

View file

@ -0,0 +1,30 @@
package info.nightscout.androidaps.plugins.PumpDanaRv2.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 MsgStatusAPS extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusAPS.class);
public MsgStatusAPS() {
SetCommand(0xE001);
}
public void handleMessage(byte[] bytes) {
double iob = intFromBuff(bytes, 0, 2) / 100d;
double deliveredSoFar = intFromBuff(bytes, 2, 2) / 100d;
DanaRPump pump = DanaRPump.getInstance();
pump.iob = iob;
if (Config.logDanaMessageDetail) {
log.debug("Delivered so far: " + deliveredSoFar);
log.debug("Current pump IOB: " + iob);
}
}
}

View file

@ -1,8 +1,12 @@
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
import android.support.annotation.NonNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@ -11,20 +15,36 @@ public class MsgStatusAPSTempBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgStatusAPSTempBasal.class); private static Logger log = LoggerFactory.getLogger(MsgStatusAPSTempBasal.class);
public MsgStatusAPSTempBasal() { public MsgStatusAPSTempBasal() {
SetCommand(0xE001); SetCommand(0xE004);
} }
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
double iob = intFromBuff(bytes, 0, 2) / 100d; boolean isTempBasalInProgress = intFromBuff(bytes, 0, 1) == 1;
double deliveredSoFar = intFromBuff(bytes, 2, 2) / 100d; int tempBasalPercent = intFromBuff(bytes, 1, 2);
int tempBasalTotalSec = intFromBuff(bytes, 3, 1) * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 4, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0);
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
pump.iob = iob; pump.isTempBasalInProgress = isTempBasalInProgress;
pump.tempBasalPercent = tempBasalPercent;
pump.tempBasalRemainingMin = tempBasalRemainingMin;
pump.tempBasalTotalSec = tempBasalTotalSec;
pump.tempBasalStart = tempBasalStart;
if (Config.logDanaMessageDetail) { if (Config.logDanaMessageDetail) {
log.debug("Delivered so far: " + deliveredSoFar); log.debug("Is temp basal running: " + isTempBasalInProgress);
log.debug("Current pump IOB: " + iob); 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);
}
} }

View file

@ -82,6 +82,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread; import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPSTempBasal; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPSTempBasal;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
@ -284,6 +285,7 @@ public class DanaRv2ExecutionService extends Service {
MsgStatus statusMsg = new MsgStatus(); MsgStatus statusMsg = new MsgStatus();
MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
MsgStatusAPSTempBasal tempAPSStatusMsg = new MsgStatusAPSTempBasal();
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(); MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue checkValue = new MsgCheckValue(); MsgCheckValue checkValue = new MsgCheckValue();
@ -295,6 +297,7 @@ public class DanaRv2ExecutionService extends Service {
} }
mSerialIOThread.sendMessage(tempStatusMsg); // do this before statusBasic because here is temp duration mSerialIOThread.sendMessage(tempStatusMsg); // do this before statusBasic because here is temp duration
mSerialIOThread.sendMessage(tempAPSStatusMsg);
mSerialIOThread.sendMessage(exStatusMsg); mSerialIOThread.sendMessage(exStatusMsg);
mSerialIOThread.sendMessage(statusMsg); mSerialIOThread.sendMessage(statusMsg);
mSerialIOThread.sendMessage(statusBasicMsg); mSerialIOThread.sendMessage(statusBasicMsg);
@ -309,13 +312,17 @@ public class DanaRv2ExecutionService extends Service {
// Load of status of current basal rate failed, give one more try // Load of status of current basal rate failed, give one more try
mSerialIOThread.sendMessage(tempStatusMsg); mSerialIOThread.sendMessage(tempStatusMsg);
} }
if (!tempAPSStatusMsg.received) {
// Load of status of current basal rate failed, give one more try
mSerialIOThread.sendMessage(tempAPSStatusMsg);
}
if (!exStatusMsg.received) { if (!exStatusMsg.received) {
// Load of status of current extended bolus failed, give one more try // Load of status of current extended bolus failed, give one more try
mSerialIOThread.sendMessage(exStatusMsg); mSerialIOThread.sendMessage(exStatusMsg);
} }
// Check we have really current status of pump // Check we have really current status of pump
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) { if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !tempAPSStatusMsg.received || !exStatusMsg.received) {
waitMsec(10 * 1000); waitMsec(10 * 1000);
log.debug("getPumpStatus failed"); log.debug("getPumpStatus failed");
return false; return false;
@ -362,6 +369,7 @@ public class DanaRv2ExecutionService extends Service {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal()); mSerialIOThread.sendMessage(new MsgStatusTempBasal());
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true; return true;
} }
@ -371,8 +379,9 @@ public class DanaRv2ExecutionService extends Service {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart(percent)); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart(percent));
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal()); mSerialIOThread.sendMessage(new MsgStatusAPS());
mSerialIOThread.sendMessage(new MsgStatusTempBasal()); mSerialIOThread.sendMessage(new MsgStatusTempBasal());
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true; return true;
} }