Merge branch 'DanaRv2' into history
This commit is contained in:
commit
be4aa1131e
|
@ -155,9 +155,10 @@ public class MessageOriginalNames {
|
|||
messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP");
|
||||
messageNames.put(0xE003, "CMD_HISTORY_APSTEMP");
|
||||
|
||||
messageNames.put(0xE001, "CMD_PUMP_APSTEMP_VALUE");
|
||||
messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP");
|
||||
messageNames.put(0xE003, "CMD_HISTORY_APSTEMP");
|
||||
messageNames.put(0xE001, "CMD_PUMP_APS");
|
||||
messageNames.put(0xE002, "CMD_PUMPSET_APS");
|
||||
messageNames.put(0xE003, "CMD_HISTORY_APS");
|
||||
messageNames.put(0xE004, "CMD_PUMPSET_APSTEMP");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -117,9 +117,10 @@ public class MessageHashTable {
|
|||
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 MsgStatusAPSTempBasal()); // 0xE001 CMD_PUMP_APSTEMP_VALUE
|
||||
put(new MsgStatusAPS()); // 0xE001 CMD_PUMP_APS
|
||||
put(new MsgSetAPSTempBasalStart()); // 0xE002 CMD_PUMPSET_APSTEMP
|
||||
put(new MsgHistoryEvents()); // 0xE003 CMD_HISTORY_EVENTS
|
||||
put(new MsgStatusAPSTempBasal()); // 0xE004 CMD_PUMP_APSTEMP
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
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);
|
||||
|
||||
public MsgStatusAPSTempBasal() {
|
||||
SetCommand(0xE001);
|
||||
SetCommand(0xE004);
|
||||
}
|
||||
|
||||
public void handleMessage(byte[] bytes) {
|
||||
double iob = intFromBuff(bytes, 0, 2) / 100d;
|
||||
double deliveredSoFar = intFromBuff(bytes, 2, 2) / 100d;
|
||||
boolean isTempBasalInProgress = intFromBuff(bytes, 0, 1) == 1;
|
||||
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();
|
||||
pump.iob = iob;
|
||||
pump.isTempBasalInProgress = isTempBasalInProgress;
|
||||
pump.tempBasalPercent = tempBasalPercent;
|
||||
pump.tempBasalRemainingMin = tempBasalRemainingMin;
|
||||
pump.tempBasalTotalSec = tempBasalTotalSec;
|
||||
pump.tempBasalStart = tempBasalStart;
|
||||
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Delivered so far: " + deliveredSoFar);
|
||||
log.debug("Current pump IOB: " + iob);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ 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.MsgStatusAPSTempBasal;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -284,6 +285,7 @@ public class DanaRv2ExecutionService extends Service {
|
|||
MsgStatus statusMsg = new MsgStatus();
|
||||
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
|
||||
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
|
||||
MsgStatusAPSTempBasal tempAPSStatusMsg = new MsgStatusAPSTempBasal();
|
||||
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
|
||||
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(tempAPSStatusMsg);
|
||||
mSerialIOThread.sendMessage(exStatusMsg);
|
||||
mSerialIOThread.sendMessage(statusMsg);
|
||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
||||
|
@ -309,13 +312,17 @@ public class DanaRv2ExecutionService extends Service {
|
|||
// Load of status of current basal rate failed, give one more try
|
||||
mSerialIOThread.sendMessage(tempStatusMsg);
|
||||
}
|
||||
if (!tempAPSStatusMsg.received) {
|
||||
// Load of status of current basal rate failed, give one more try
|
||||
mSerialIOThread.sendMessage(tempAPSStatusMsg);
|
||||
}
|
||||
if (!exStatusMsg.received) {
|
||||
// Load of status of current extended bolus failed, give one more try
|
||||
mSerialIOThread.sendMessage(exStatusMsg);
|
||||
}
|
||||
|
||||
// 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);
|
||||
log.debug("getPumpStatus failed");
|
||||
return false;
|
||||
|
@ -362,6 +369,7 @@ public class DanaRv2ExecutionService extends Service {
|
|||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
|
||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
|
||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||
return true;
|
||||
}
|
||||
|
@ -371,8 +379,9 @@ public class DanaRv2ExecutionService extends Service {
|
|||
if (!isConnected()) return false;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
|
||||
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart(percent));
|
||||
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal());
|
||||
mSerialIOThread.sendMessage(new MsgStatusAPS());
|
||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||
mSerialIOThread.sendMessage(new MsgStatusAPSTempBasal());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue