Merge branch 'omnipod_eros' of https://github.com/AAPS-Omnipod/AndroidAPS into omnipod_eros

This commit is contained in:
Andy Rozman 2019-12-08 18:22:12 +00:00
commit 5711a98a77
4 changed files with 54 additions and 23 deletions

View file

@ -43,13 +43,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalDelivery
import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalSetupProgressException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.NonceOutOfSyncException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import io.reactivex.Completable; import io.reactivex.Completable;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.SingleSubject; import io.reactivex.subjects.SingleSubject;
public class OmnipodManager { public class OmnipodManager {
@ -97,7 +98,7 @@ public class OmnipodManager {
return Single.timer(delayInSeconds, TimeUnit.SECONDS) // return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse -> .map(o -> verifySetupAction(statusResponse ->
PrimeAction.updatePrimingStatus(podState, statusResponse), SetupProgress.PRIMING_FINISHED)) // PrimeAction.updatePrimingStatus(podState, statusResponse), SetupProgress.PRIMING_FINISHED)) //
.observeOn(AndroidSchedulers.mainThread()); .observeOn(Schedulers.io());
} }
public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) { public synchronized Single<SetupActionResult> insertCannula(BasalSchedule basalSchedule) {
@ -113,7 +114,7 @@ public class OmnipodManager {
return Single.timer(delayInSeconds, TimeUnit.SECONDS) // return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse -> .map(o -> verifySetupAction(statusResponse ->
InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), SetupProgress.COMPLETED)) // InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), SetupProgress.COMPLETED)) //
.observeOn(AndroidSchedulers.mainThread()); .observeOn(Schedulers.io());
} }
public synchronized StatusResponse getPodStatus() { public synchronized StatusResponse getPodStatus() {
@ -190,7 +191,7 @@ public class OmnipodManager {
long progressReportInterval = estimatedRemainingBolusDuration.getMillis() / numberOfProgressReports; long progressReportInterval = estimatedRemainingBolusDuration.getMillis() / numberOfProgressReports;
disposables.add(Flowable.intervalRange(0, numberOfProgressReports + 1, 0, progressReportInterval, TimeUnit.MILLISECONDS) // disposables.add(Flowable.intervalRange(0, numberOfProgressReports + 1, 0, progressReportInterval, TimeUnit.MILLISECONDS) //
.observeOn(AndroidSchedulers.mainThread()) // .observeOn(Schedulers.io()) //
.subscribe(count -> { .subscribe(count -> {
int percentage = (int) ((double) count / numberOfProgressReports * 100); int percentage = (int) ((double) count / numberOfProgressReports * 100);
double estimatedUnitsDelivered = activeBolusData == null ? 0 : activeBolusData.estimateUnitsDelivered(); double estimatedUnitsDelivered = activeBolusData == null ? 0 : activeBolusData.estimateUnitsDelivered();
@ -200,9 +201,13 @@ public class OmnipodManager {
SingleSubject<BolusDeliveryResult> bolusCompletionSubject = SingleSubject.create(); SingleSubject<BolusDeliveryResult> bolusCompletionSubject = SingleSubject.create();
synchronized (bolusDataLock) {
activeBolusData = new ActiveBolusData(units, startDate, bolusCompletionSubject, disposables);
}
disposables.add(Completable.complete() // disposables.add(Completable.complete() //
.delay(estimatedRemainingBolusDuration.getMillis() + 250, TimeUnit.MILLISECONDS) // .delay(estimatedRemainingBolusDuration.getMillis() + 250, TimeUnit.MILLISECONDS) //
.observeOn(AndroidSchedulers.mainThread()) // .observeOn(Schedulers.io()) //
.doOnComplete(() -> { .doOnComplete(() -> {
synchronized (bolusDataLock) { synchronized (bolusDataLock) {
for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) { for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) {
@ -216,7 +221,7 @@ public class OmnipodManager {
} }
} catch (Exception ex) { } catch (Exception ex) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
LOG.debug("Ignoring exception in bolus completion verfication", ex); LOG.debug("Ignoring exception in bolus completion verification", ex);
} }
} }
} }
@ -229,10 +234,6 @@ public class OmnipodManager {
}) })
.subscribe()); .subscribe());
synchronized (bolusDataLock) {
activeBolusData = new ActiveBolusData(units, startDate, bolusCompletionSubject, disposables);
}
return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject); return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject);
} }
@ -244,7 +245,13 @@ public class OmnipodManager {
throw new IllegalDeliveryStatusException(DeliveryStatus.BOLUS_IN_PROGRESS, podState.getLastDeliveryStatus()); throw new IllegalDeliveryStatusException(DeliveryStatus.BOLUS_IN_PROGRESS, podState.getLastDeliveryStatus());
} }
executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, acknowledgementBeep))); try {
executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, acknowledgementBeep)));
} catch (PodFaultException ex) {
if (isLoggingEnabled()) {
LOG.info("Ignoring PodFaultException in cancelBolus", ex);
}
}
activeBolusData.getDisposables().dispose(); activeBolusData.getDisposables().dispose();
activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered())); activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered()));
@ -281,12 +288,19 @@ public class OmnipodManager {
resumeDelivery(acknowledgementBeeps); resumeDelivery(acknowledgementBeeps);
} }
public synchronized void deactivatePod(boolean acknowledgementBeep) { public synchronized void deactivatePod() {
if (podState == null) { if (podState == null) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null); throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null);
} }
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, acknowledgementBeep))); try {
// Never send acknowledgement beeps here. Matches the PDM's behavior
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, false)));
} catch (PodFaultException ex) {
if (isLoggingEnabled()) {
LOG.info("Ignoring PodFaultException in deactivatePod", ex);
}
}
resetPodState(); resetPodState();
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs; package info.nightscout.androidaps.plugins.pump.omnipod.defs;
import java.util.Locale;
public enum FaultEventCode { public enum FaultEventCode {
NO_FAULTS((byte) 0x00), NO_FAULTS((byte) 0x00),
FAILED_FLASH_ERASE((byte) 0x01), FAILED_FLASH_ERASE((byte) 0x01),
@ -138,4 +140,9 @@ public enum FaultEventCode {
public byte getValue() { public byte getValue() {
return value; return value;
} }
@Override
public String toString() {
return String.format(Locale.getDefault(), "Pod fault (%d): %s", value, name());
}
} }

View file

@ -77,10 +77,24 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
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);
updatePumpStatus(podSessionState);
});
this.pumpStatus = _pumpStatus;
instance = this;
}
if (pumpStatus != null) { private void updatePumpStatus(PodSessionState podSessionState) {
if (pumpStatus != null) {
if (podSessionState == null) {
pumpStatus.ackAlertsText = null;
pumpStatus.ackAlertsAvailable = false;
pumpStatus.lastBolusTime = null;
pumpStatus.lastBolusAmount = null;
pumpStatus.reservoirRemainingUnits = 0.0;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
sendEvent(new EventOmnipodPumpValuesChanged());
} else {
// Update active alerts // Update active alerts
if (podSessionState.hasActiveAlerts()) { if (podSessionState.hasActiveAlerts()) {
List<String> alerts = translateActiveAlerts(podSessionState); List<String> alerts = translateActiveAlerts(podSessionState);
@ -110,9 +124,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
sendEvent(new EventOmnipodPumpValuesChanged()); sendEvent(new EventOmnipodPumpValuesChanged());
} }
} }
}); }
this.pumpStatus = _pumpStatus;
instance = this;
} }
private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) { private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
@ -170,7 +182,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
try { try {
delegate.deactivatePod(true); delegate.deactivatePod();
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment); podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment);
@ -300,6 +312,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
public void setPumpStatus(OmnipodPumpStatus pumpStatus) { public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
this.pumpStatus = pumpStatus; this.pumpStatus = pumpStatus;
this.getCommunicationService().setPumpStatus(pumpStatus); this.getCommunicationService().setPumpStatus(pumpStatus);
updatePumpStatus(delegate.getPodState());
} }
// TODO should we add this to the OmnipodCommunicationManager interface? // TODO should we add this to the OmnipodCommunicationManager interface?

View file

@ -1,15 +1,12 @@
package info.nightscout.androidaps.plugins.pump.omnipod.exception; package info.nightscout.androidaps.plugins.pump.omnipod.exception;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent;
public class PodFaultException extends OmnipodException { public class PodFaultException extends OmnipodException {
private final PodInfoFaultEvent faultEvent; private final PodInfoFaultEvent faultEvent;
public PodFaultException(PodInfoFaultEvent faultEvent) { public PodFaultException(PodInfoFaultEvent faultEvent) {
super(String.format(Locale.getDefault(), "Pod fault (%d): %s", faultEvent.getFaultEventCode().getValue(), super(faultEvent.getFaultEventCode().toString(), true);
faultEvent.getFaultEventCode().toString()), true);
this.faultEvent = faultEvent; this.faultEvent = faultEvent;
} }