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
|
||||
version "omnipod-0.1-SNAPSHOT"
|
||||
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", "REMOTE", '"' + generateGitRemote() + '"'
|
||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||
|
|
|
@ -160,14 +160,14 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
|||
encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length);
|
||||
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 {
|
||||
// We actually ignore previous (ack) responses if it was not last packet to send
|
||||
response = exchangePackets(podState, packet);
|
||||
} 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;
|
||||
if (ex instanceof OmnipodException) {
|
||||
newException = (OmnipodException) ex;
|
||||
|
|
|
@ -33,6 +33,7 @@ public class PodSessionState extends PodState {
|
|||
private final FirmwareVersion pmVersion;
|
||||
private final int lot;
|
||||
private final int tid;
|
||||
private Double reservoirLevel;
|
||||
private boolean suspended;
|
||||
|
||||
private DateTimeZone timeZone;
|
||||
|
@ -98,7 +99,6 @@ public class PodSessionState extends PodState {
|
|||
return expiresAt == null ? "???" : DateUtil.dateAndTimeString(expiresAt.toDate());
|
||||
}
|
||||
|
||||
|
||||
public FirmwareVersion getPiVersion() {
|
||||
return piVersion;
|
||||
}
|
||||
|
@ -115,6 +115,10 @@ public class PodSessionState extends PodState {
|
|||
return tid;
|
||||
}
|
||||
|
||||
public Double getReservoirLevel() {
|
||||
return reservoirLevel;
|
||||
}
|
||||
|
||||
public synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
|
||||
int sum = (sentNonce & 0xFFFF)
|
||||
+ OmniCRC.crc16lookup[sequenceNumber]
|
||||
|
@ -225,6 +229,7 @@ public class PodSessionState extends PodState {
|
|||
suspended = (statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED);
|
||||
activeAlerts = statusResponse.getAlerts();
|
||||
lastDeliveryStatus = statusResponse.getDeliveryStatus();
|
||||
reservoirLevel = statusResponse.getReservoirLevel();
|
||||
store();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
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.db.PodDbEntryType;
|
||||
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.CommandInitializationException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.exception.CommunicationException;
|
||||
|
@ -63,17 +66,21 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
private static AapsOmnipodManager instance;
|
||||
private OmnipodPumpStatus pumpStatus;
|
||||
|
||||
private Date lastBolusTime;
|
||||
private Double lastBolusUnits;
|
||||
|
||||
public static AapsOmnipodManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus pumpStatus) {
|
||||
public AapsOmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState, OmnipodPumpStatus _pumpStatus) {
|
||||
delegate = new OmnipodManager(communicationService, podState, podSessionState -> {
|
||||
// Handle pod state changes
|
||||
|
||||
OmnipodUtil.setPodSessionState(podSessionState);
|
||||
|
||||
if (pumpStatus != null) {
|
||||
// Update active alerts
|
||||
if (podSessionState.hasActiveAlerts()) {
|
||||
List<String> alerts = translateActiveAlerts(podSessionState);
|
||||
String alertsText = TextUtils.join("\n", alerts);
|
||||
|
@ -91,12 +98,27 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
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;
|
||||
}
|
||||
|
||||
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
|
||||
double expectedUnitsRemaining = unitsRemaining == null ? 75.0 : unitsRemaining;
|
||||
return Math.abs(expectedUnitsRemaining - pumpStatus.reservoirRemainingUnits) < 0.000001;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> translateActiveAlerts(PodSessionState podSessionState) {
|
||||
List<String> alerts = new ArrayList<>();
|
||||
|
@ -190,6 +212,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
|
||||
boolean beepsEnabled = isSmb ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
|
||||
|
||||
Date bolusStarted;
|
||||
try {
|
||||
bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, isSmb ? null :
|
||||
(estimatedUnitsDelivered, percentage) -> {
|
||||
|
@ -198,27 +221,27 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
|||
progressUpdateEvent.setPercent(percentage);
|
||||
sendEvent(progressUpdateEvent);
|
||||
});
|
||||
|
||||
bolusStarted = new Date();
|
||||
} catch (Exception ex) {
|
||||
String comment = handleAndTranslateException(ex);
|
||||
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
|
||||
// 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 {
|
||||
// Wait for the bolus to finish
|
||||
OmnipodManager.BolusDeliveryResult bolusDeliveryResult =
|
||||
bolusCommandResult.getDeliveryResultSubject().blockingGet();
|
||||
unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
|
||||
} catch (Exception ex) {
|
||||
if (loggingEnabled()) {
|
||||
LOG.debug("Ignoring failed status response for bolus completion verification", ex);
|
||||
}
|
||||
double unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
|
||||
|
||||
if (pumpStatus != null && !isSmb) {
|
||||
lastBolusTime = bolusStarted;
|
||||
lastBolusUnits = 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.events.EventOmnipodDeviceStatusChange;
|
||||
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.utils.OKDialog;
|
||||
|
||||
|
@ -171,8 +172,8 @@ public class OmnipodUtil extends RileyLinkUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void setPodDeviceState(PodDeviceState podSessionState) {
|
||||
omnipodPumpStatus.podDeviceState = podSessionState;
|
||||
public static void setPodDeviceState(PodDeviceState podDeviceState) {
|
||||
omnipodPumpStatus.podDeviceState = podDeviceState;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue