Update last bolus and units remaning for Omnipod in PumpStatus
This commit is contained in:
parent
52e0b0cf82
commit
3cc1113501
5 changed files with 50 additions and 21 deletions
|
@ -111,7 +111,7 @@ android {
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
version "omnipod-0.1-SNAPSHOT"
|
version "omnipod-0.1-SNAPSHOT"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "DEV_VERSION", "2.6-dev"
|
buildConfigField "String", "DEV_VERSION", '"2.6-dev"'
|
||||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||||
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
||||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||||
|
|
|
@ -160,14 +160,14 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
||||||
encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length);
|
encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length);
|
||||||
firstPacket = false;
|
firstPacket = false;
|
||||||
|
|
||||||
// If this is not the last packet, the message wasn't fully sent,
|
|
||||||
// so it's impossible for the pod to have received the message
|
|
||||||
boolean isCertainFailure = encodedMessage.length > 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// We actually ignore previous (ack) responses if it was not last packet to send
|
// We actually ignore previous (ack) responses if it was not last packet to send
|
||||||
response = exchangePackets(podState, packet);
|
response = exchangePackets(podState, packet);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
// If this is not the last packet, the message wasn't fully sent,
|
||||||
|
// so it's impossible for the pod to have received the message
|
||||||
|
boolean isCertainFailure = encodedMessage.length > 0;
|
||||||
|
|
||||||
OmnipodException newException;
|
OmnipodException newException;
|
||||||
if (ex instanceof OmnipodException) {
|
if (ex instanceof OmnipodException) {
|
||||||
newException = (OmnipodException) ex;
|
newException = (OmnipodException) ex;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class PodSessionState extends PodState {
|
||||||
private final FirmwareVersion pmVersion;
|
private final FirmwareVersion pmVersion;
|
||||||
private final int lot;
|
private final int lot;
|
||||||
private final int tid;
|
private final int tid;
|
||||||
|
private Double reservoirLevel;
|
||||||
private boolean suspended;
|
private boolean suspended;
|
||||||
|
|
||||||
private DateTimeZone timeZone;
|
private DateTimeZone timeZone;
|
||||||
|
@ -98,7 +99,6 @@ public class PodSessionState extends PodState {
|
||||||
return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate());
|
return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FirmwareVersion getPiVersion() {
|
public FirmwareVersion getPiVersion() {
|
||||||
return piVersion;
|
return piVersion;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,10 @@ public class PodSessionState extends PodState {
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Double getReservoirLevel() {
|
||||||
|
return reservoirLevel;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
|
public synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
|
||||||
int sum = (sentNonce & 0xFFFF)
|
int sum = (sentNonce & 0xFFFF)
|
||||||
+ OmniCRC.crc16lookup[sequenceNumber]
|
+ OmniCRC.crc16lookup[sequenceNumber]
|
||||||
|
@ -225,6 +229,7 @@ public class PodSessionState extends PodState {
|
||||||
suspended = (statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
|
suspended = (statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
|
||||||
activeAlerts = statusResponse.getAlerts();
|
activeAlerts = statusResponse.getAlerts();
|
||||||
lastDeliveryStatus = statusResponse.getDeliveryStatus();
|
lastDeliveryStatus = statusResponse.getDeliveryStatus();
|
||||||
|
reservoirLevel = statusResponse.getReservoirLevel();
|
||||||
store();
|
store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -37,6 +39,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionStat
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntryType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodDbEntryType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
|
import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializationException;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
|
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommandInitializationException;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommunicationException;
|
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommunicationException;
|
||||||
|
@ -63,17 +66,21 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
private static AapsOmnipodManager instance;
|
private static AapsOmnipodManager instance;
|
||||||
private OmnipodPumpStatus pumpStatus;
|
private OmnipodPumpStatus pumpStatus;
|
||||||
|
|
||||||
|
private Date lastBolusTime;
|
||||||
|
private Double lastBolusUnits;
|
||||||
|
|
||||||
public static AapsOmnipodManager getInstance() {
|
public static AapsOmnipodManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus pumpStatus) {
|
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus _pumpStatus) {
|
||||||
delegate = new OmnipodManager(communicationService, podState, podSessionState -> {
|
delegate = new OmnipodManager(communicationService, podState, podSessionState -> {
|
||||||
// Handle pod state changes
|
// Handle pod state changes
|
||||||
|
|
||||||
OmnipodUtil.setPodSessionState(podSessionState);
|
OmnipodUtil.setPodSessionState(podSessionState);
|
||||||
|
|
||||||
if (pumpStatus != null) {
|
if (pumpStatus != null) {
|
||||||
|
// Update active alerts
|
||||||
if (podSessionState.hasActiveAlerts()) {
|
if (podSessionState.hasActiveAlerts()) {
|
||||||
List<String> alerts = translateActiveAlerts(podSessionState);
|
List<String> alerts = translateActiveAlerts(podSessionState);
|
||||||
String alertsText = TextUtils.join("\n", alerts);
|
String alertsText = TextUtils.join("\n", alerts);
|
||||||
|
@ -91,12 +98,27 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
|
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update other info: last bolus, units remaining
|
||||||
|
if (!Objects.equals(lastBolusTime, pumpStatus.lastBolusTime) //
|
||||||
|
|| !Objects.equals(lastBolusUnits, pumpStatus.lastBolusAmount) //
|
||||||
|
|| !isReservoirStatusUpToDate(pumpStatus, podSessionState.getReservoirLevel())) {
|
||||||
|
pumpStatus.lastBolusTime = lastBolusTime;
|
||||||
|
pumpStatus.lastBolusAmount = lastBolusUnits;
|
||||||
|
pumpStatus.reservoirRemainingUnits = podSessionState.getReservoirLevel() == null ? 75.0 : podSessionState.getReservoirLevel();
|
||||||
|
sendEvent(new EventOmnipodPumpValuesChanged());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.pumpStatus = pumpStatus;
|
this.pumpStatus = _pumpStatus;
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
|
||||||
|
double expectedUnitsRemaining = unitsRemaining == null ? 75.0 : unitsRemaining;
|
||||||
|
return Math.abs(expectedUnitsRemaining - pumpStatus.reservoirRemainingUnits) < 0.000001;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<String> translateActiveAlerts(PodSessionState podSessionState) {
|
private List<String> translateActiveAlerts(PodSessionState podSessionState) {
|
||||||
List<String> alerts = new ArrayList<>();
|
List<String> alerts = new ArrayList<>();
|
||||||
|
@ -190,6 +212,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
|
|
||||||
boolean beepsEnabled = isSmb ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
|
boolean beepsEnabled = isSmb ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
|
||||||
|
|
||||||
|
Date bolusStarted;
|
||||||
try {
|
try {
|
||||||
bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, isSmb ? null :
|
bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, isSmb ? null :
|
||||||
(estimatedUnitsDelivered, percentage) -> {
|
(estimatedUnitsDelivered, percentage) -> {
|
||||||
|
@ -198,27 +221,27 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
progressUpdateEvent.setPercent(percentage);
|
progressUpdateEvent.setPercent(percentage);
|
||||||
sendEvent(progressUpdateEvent);
|
sendEvent(progressUpdateEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bolusStarted = new Date();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String comment = handleAndTranslateException(ex);
|
String comment = handleAndTranslateException(ex);
|
||||||
return new PumpEnactResult().success(false).enacted(false).comment(comment);
|
return new PumpEnactResult().success(false).enacted(false).comment(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OmnipodManager.CommandDeliveryStatus.UNCERTAIN_FAILURE.equals(bolusCommandResult.getCommandDeliveryStatus()) /* && !isSmb */) {
|
if (OmnipodManager.CommandDeliveryStatus.UNCERTAIN_FAILURE.equals(bolusCommandResult.getCommandDeliveryStatus()) && !isSmb /* TODO or should we also warn for SMB? */) {
|
||||||
// TODO notify user about uncertain failure ---> we're unsure whether or not the bolus has been delivered
|
// TODO notify user about uncertain failure ---> we're unsure whether or not the bolus has been delivered
|
||||||
// For safety reasons, we should treat this as a bolus that has been delivered, in order to prevent insulin overdose
|
// For safety reasons, we should treat this as a bolus that has been delivered, in order to prevent insulin overdose
|
||||||
}
|
}
|
||||||
|
|
||||||
double unitsDelivered = units;
|
// Wait for the bolus to finish
|
||||||
|
OmnipodManager.BolusDeliveryResult bolusDeliveryResult =
|
||||||
|
bolusCommandResult.getDeliveryResultSubject().blockingGet();
|
||||||
|
|
||||||
try {
|
double unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
|
||||||
// Wait for the bolus to finish
|
|
||||||
OmnipodManager.BolusDeliveryResult bolusDeliveryResult =
|
if (pumpStatus != null && !isSmb) {
|
||||||
bolusCommandResult.getDeliveryResultSubject().blockingGet();
|
lastBolusTime = bolusStarted;
|
||||||
unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
|
lastBolusUnits = unitsDelivered;
|
||||||
} catch (Exception ex) {
|
|
||||||
if (loggingEnabled()) {
|
|
||||||
LOG.debug("Ignoring failed status response for bolus completion verification", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered);
|
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
||||||
import info.nightscout.androidaps.utils.OKDialog;
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
|
|
||||||
|
@ -171,8 +172,8 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setPodDeviceState(PodDeviceState podSessionState) {
|
public static void setPodDeviceState(PodDeviceState podDeviceState) {
|
||||||
omnipodPumpStatus.podDeviceState = podSessionState;
|
omnipodPumpStatus.podDeviceState = podDeviceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue