Merge pull request #192 from AAPS-Omnipod/omnipod_eros_dev_upstream_merge

Omnipod fixes
This commit is contained in:
Milos Kozak 2021-01-07 10:25:44 +01:00 committed by GitHub
commit 706783edab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 103 additions and 70 deletions

View file

@ -49,14 +49,14 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
Intent.ACTION_TIMEZONE_CHANGED == action -> {
aapsLogger.info(LTag.PUMP, "TimeDateOrTZChangeReceiver::Timezone changed. Notifying pump driver.")
activePump.timezoneOrDSTChanged(TimeChangeType.TimezoneChange)
activePump.timezoneOrDSTChanged(TimeChangeType.TimezoneChanged)
}
Intent.ACTION_TIME_CHANGED == action -> {
val currentDst = calculateDST()
if (currentDst == isDST) {
aapsLogger.info(LTag.PUMP, "TimeDateOrTZChangeReceiver::Time changed (manual). Notifying pump driver.")
activePump.timezoneOrDSTChanged(TimeChangeType.ManualTimeChange)
activePump.timezoneOrDSTChanged(TimeChangeType.TimeChanged)
} else {
if (currentDst) {
aapsLogger.info(LTag.PUMP, "TimeDateOrTZChangeReceiver::DST started. Notifying pump driver.")

View file

@ -78,6 +78,7 @@ public class Notification {
public static final int OMNIPOD_UNCERTAIN_SMB = 67;
public static final int OMNIPOD_UNKNOWN_TBR = 68;
public static final int OMNIPOD_STARTUP_STATUS_REFRESH_FAILED = 69;
public static final int OMNIPOD_TIME_OUT_OF_SYNC = 70;
public static final int IMPORTANCE_HIGH = 2;

View file

@ -1,8 +1,8 @@
package info.nightscout.androidaps.utils;
public enum TimeChangeType {
TimezoneChange,
TimezoneChanged,
DST_Started,
DST_Ended,
ManualTimeChange
TimeChanged
}

View file

@ -116,8 +116,8 @@ import static info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.
*/
@Singleton
public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, RileyLinkPumpDevice {
private static final long RILEY_LINK_CONNECT_TIMEOUT_MILLIS = 3 * 60 * 1000L; // 3 minutes
private static final long STATUS_CHECK_INTERVAL_MILLIS = 60 * 1000L; // 1 minute
private static final long RILEY_LINK_CONNECT_TIMEOUT_MILLIS = 3 * 60 * 1_000L; // 3 minutes
private static final long STATUS_CHECK_INTERVAL_MILLIS = 60 * 1_000L; // 1 minute
public static final int STARTUP_STATUS_REQUEST_TRIES = 2;
public static final double RESERVOIR_OVER_50_UNITS_DEFAULT = 75.0;
@ -150,12 +150,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private RileyLinkOmnipodService rileyLinkOmnipodService;
private boolean busy = false;
private int timeChangeRetries;
private long nextPodCheck;
private long nextPodWarningCheck;
private long lastConnectionTimeMillis;
private final Handler loopHandler = new Handler(Looper.getMainLooper());
private final Runnable statusChecker;
private boolean isCancelTempBasalRunning;
@Inject
public OmnipodPumpPlugin(
@ -238,6 +237,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
statusChecker = new Runnable() {
@Override public void run() {
if (commandQueue.size() == 0) {
if (podStateManager.isPodRunning() && !podStateManager.isSuspended()) {
aapsOmnipodManager.cancelSuspendedFakeTbrIfExists();
} else {
@ -255,8 +255,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
podStateManager.getActiveAlerts().size() > 0 && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
queueAcknowledgeAlertsCommand();
}
} else {
aapsLogger.debug(LTag.PUMP, "Skipping Pod status check because command queue is not empty");
}
doPodCheck();
updatePodWarningNotifications();
loopHandler.postDelayed(this, STATUS_CHECK_INTERVAL_MILLIS);
}
@ -360,10 +363,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
private void handleCancelledTbr() {
// Only report TBR cancellations if they haven't been explicitly requested
if (isCancelTempBasalRunning) {
return;
}
if (!podStateManager.isTempBasalRunning() && activePlugin.getActiveTreatments().isTempBasalInProgress() && !aapsOmnipodManager.hasSuspendedFakeTbr()) {
aapsOmnipodManager.reportCancelledTbr();
}
@ -445,19 +444,30 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
});
}
private void doPodCheck() {
if (System.currentTimeMillis() > this.nextPodCheck) {
private void updatePodWarningNotifications() {
if (System.currentTimeMillis() > this.nextPodWarningCheck) {
if (!podStateManager.isPodRunning()) {
Notification notification = new Notification(Notification.OMNIPOD_POD_NOT_ATTACHED, resourceHelper.gs(R.string.omnipod_error_pod_not_attached), Notification.NORMAL);
rxBus.send(new EventNewNotification(notification));
} else {
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
if (podStateManager.isSuspended()) {
Notification notification = new Notification(Notification.OMNIPOD_POD_SUSPENDED, resourceHelper.gs(R.string.omnipod_error_pod_suspended), Notification.NORMAL);
rxBus.send(new EventNewNotification(notification));
} else {
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED));
if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
Notification notification = new Notification(Notification.OMNIPOD_TIME_OUT_OF_SYNC, resourceHelper.gs(R.string.omnipod_error_time_out_of_sync), Notification.NORMAL);
rxBus.send(new EventNewNotification(notification));
} else {
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC));
}
}
}
this.nextPodCheck = DateTimeUtil.getTimeInFutureFromMinutes(15);
this.nextPodWarningCheck = DateTimeUtil.getTimeInFutureFromMinutes(15);
}
}
@ -695,12 +705,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return new PumpEnactResult(getInjector()).success(true).enacted(false);
}
isCancelTempBasalRunning = true;
try {
return executeCommand(OmnipodCommandType.CANCEL_TEMPORARY_BASAL, aapsOmnipodManager::cancelTemporaryBasal);
} finally {
isCancelTempBasalRunning = false;
}
}
// TODO improve (i8n and more)
@ -957,12 +962,18 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@Override
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
aapsLogger.warn(LTag.PUMP, "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]");
aapsLogger.info(LTag.PUMP, "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]");
if (podStateManager.isPodRunning()) {
aapsLogger.info(LTag.PUMP, "Time, Date and/or TimeZone changed event received and will be consumed by driver.");
hasTimeDateOrTimeZoneChanged = true;
if (timeChangeType == TimeChangeType.TimeChanged) {
aapsLogger.info(LTag.PUMP, "Ignoring time change because it is not a DST or TZ change");
return;
} else if (!podStateManager.isPodRunning()) {
aapsLogger.info(LTag.PUMP, "Ignoring time change because no Pod is active");
return;
}
aapsLogger.info(LTag.PUMP, "DST and/or TimeZone changed event will be consumed by driver");
hasTimeDateOrTimeZoneChanged = true;
}
@Override

View file

@ -1,13 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.action;
import org.joda.time.Duration;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.MessageBlock;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.BeepConfigCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.CancelDeliveryCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepConfigType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.BeepType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
@ -35,23 +39,14 @@ public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
public StatusResponse execute(OmnipodRileyLinkCommunicationManager communicationService) {
List<MessageBlock> messageBlocks = new ArrayList<>();
if (acknowledgementBeep && deliveryTypes.size() > 1) {
// Workaround for strange beep behaviour when cancelling multiple delivery types
List<DeliveryType> deliveryTypeList = new ArrayList<>(deliveryTypes);
messageBlocks.add(new CancelDeliveryCommand(podStateManager.getCurrentNonce(), BeepType.NO_BEEP, deliveryTypes));
EnumSet<DeliveryType> deliveryTypeWithBeep = EnumSet.of(deliveryTypeList.remove(deliveryTypeList.size() - 1));
EnumSet<DeliveryType> deliveryTypesWithoutBeep = EnumSet.copyOf(deliveryTypeList);
messageBlocks.add(new CancelDeliveryCommand(podStateManager.getCurrentNonce(), BeepType.NO_BEEP, deliveryTypesWithoutBeep));
messageBlocks.add(new CancelDeliveryCommand(podStateManager.getCurrentNonce(), BeepType.BEEP, deliveryTypeWithBeep));
} else {
messageBlocks.add(new CancelDeliveryCommand(podStateManager.getCurrentNonce(),
acknowledgementBeep && deliveryTypes.size() == 1 ? BeepType.BEEP : BeepType.NO_BEEP, deliveryTypes));
// Workaround for strange behavior where the Pod beeps for each specified delivery type
if (acknowledgementBeep) {
messageBlocks.add(new BeepConfigCommand(BeepConfigType.BEEP, false, Duration.ZERO, false, Duration.ZERO, false, Duration.ZERO));
}
StatusResponse statusResponse = communicationService.exchangeMessages(StatusResponse.class, podStateManager,
return communicationService.exchangeMessages(StatusResponse.class, podStateManager,
new OmnipodMessage(podStateManager.getAddress(), messageBlocks, podStateManager.getMessageNumber()));
return statusResponse;
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import info.nightscout.androidaps.logging.AAPSLogger;
@ -31,7 +32,7 @@ public class OmnipodMessage {
public OmnipodMessage(int address, List<MessageBlock> messageBlocks, int sequenceNumber) {
this.address = address;
this.messageBlocks = messageBlocks;
this.messageBlocks = new ArrayList<>(messageBlocks);
this.sequenceNumber = sequenceNumber;
}
@ -54,7 +55,7 @@ public class OmnipodMessage {
throw new CrcMismatchException(calculatedCrc, crc);
}
List<MessageBlock> blocks = decodeBlocks(ByteUtil.substring(data, 6, data.length - 6 - 2));
if (blocks == null || blocks.size() == 0) {
if (blocks.size() == 0) {
throw new MessageDecodingException("No blocks decoded");
}
@ -110,7 +111,7 @@ public class OmnipodMessage {
}
public List<MessageBlock> getMessageBlocks() {
return messageBlocks;
return new ArrayList<>(messageBlocks);
}
public int getSequenceNumber() {
@ -147,12 +148,16 @@ public class OmnipodMessage {
return false;
}
public boolean isSetTempBasalMessage() {
return messageBlocks.size() >= 2 && messageBlocks.get(0).getType() == MessageBlockType.SET_INSULIN_SCHEDULE && messageBlocks.get(1).getType() == MessageBlockType.TEMP_BASAL_EXTRA;
public boolean isGetStatusMessage() {
return messageBlocks.size() == 1 && messageBlocks.get(0).getType() == MessageBlockType.GET_STATUS;
}
public boolean isCancelTempBasalMessage() {
return messageBlocks.size() >= 1 && messageBlocks.get(0).getType() == MessageBlockType.CANCEL_DELIVERY && ((CancelDeliveryCommand) messageBlocks.get(0)).getDeliveryTypes().contains(DeliveryType.TEMP_BASAL);
public boolean isSuspendDeliveryMessage() {
return isCancelDeliveryMessage() && EnumSet.allOf(DeliveryType.class).equals(((CancelDeliveryCommand) messageBlocks.get(0)).getDeliveryTypes());
}
private boolean isCancelDeliveryMessage() {
return messageBlocks.size() >= 1 && messageBlocks.get(0).getType() == MessageBlockType.CANCEL_DELIVERY;
}
@Override

View file

@ -30,4 +30,7 @@ public class OmnipodConstants {
public static final double POD_SETUP_UNITS = POD_PRIME_BOLUS_UNITS + POD_CANNULA_INSERTION_BOLUS_UNITS;
public static final int DEFAULT_MAX_RESERVOIR_ALERT_THRESHOLD = 20;
// when the time deviates more than the threshold, the user will get warned and will get the option to change the time
public static final Duration TIME_DEVIATION_THRESHOLD = Duration.standardMinutes(5);
}

View file

@ -277,6 +277,15 @@ public class OmnipodManager {
private synchronized StatusResponse cancelDelivery(EnumSet<DeliveryType> deliveryTypes, boolean acknowledgementBeep) {
assertReadyForDelivery();
if (!podStateManager.isTempBasalCertain() || !podStateManager.isBasalCertain()) {
try {
getPodStatus();
} catch (OmnipodException ex) {
ex.setCertainFailure(true);
throw ex;
}
}
if (deliveryTypes.contains(DeliveryType.BASAL)) {
podStateManager.setBasalCertain(false);
}

View file

@ -568,10 +568,10 @@ public abstract class PodStateManager {
podState.setPodProgressStatus(status.getPodProgressStatus());
podState.setTimeActive(status.getTimeActive());
boolean isBasalCertain = podState.isBasalCertain() == null || podState.isBasalCertain();
boolean isTempBasalCertain = podState.isTempBasalCertain() == null || podState.isTempBasalCertain();
boolean wasBasalCertain = podState.isBasalCertain() == null || podState.isBasalCertain();
boolean wasTempBasalCertain = podState.isTempBasalCertain() == null || podState.isTempBasalCertain();
if (!status.getDeliveryStatus().isTbrRunning() && hasTempBasal()) {
if (isTempBasalCertain) {
if (wasTempBasalCertain || requestMessage.isSuspendDeliveryMessage()) {
clearTempBasal(); // Triggers onTbrChanged when appropriate
} else {
// Don't trigger onTbrChanged as we will trigger onUncertainTbrRecovered below
@ -580,14 +580,17 @@ public abstract class PodStateManager {
podState.setTempBasalDuration(null);
}
}
if (!isTempBasalCertain) {
if (!wasTempBasalCertain) {
podState.setTempBasalCertain(true);
if (!requestMessage.isSetTempBasalMessage() // We always set TBR to uncertain before sending the set temp basal command, so this is not an actual recovery
&& !requestMessage.isCancelTempBasalMessage()) { // Delivery status changed, so we can't recover here
// We exclusively use get status messages to recover from uncertain TBRs
// DO NOT change this as the recovery mechanism will otherwise interfere with normal delivery commands
if (requestMessage.isGetStatusMessage()) {
onUncertainTbrRecovered();
}
}
if (!isBasalCertain) {
if (!wasBasalCertain) {
podState.setBasalCertain(true);
}

View file

@ -347,6 +347,7 @@ public class AapsOmnipodManager {
dismissNotification(Notification.FAILED_UDPATE_PROFILE);
dismissNotification(Notification.OMNIPOD_POD_SUSPENDED);
dismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC);
return new PumpEnactResult(injector).success(true).enacted(true);
}
@ -584,6 +585,9 @@ public class AapsOmnipodManager {
addSuccessToHistory(PodHistoryEntryType.SUSPEND_DELIVERY, null);
createSuspendedFakeTbrIfNotExists();
dismissNotification(Notification.FAILED_UDPATE_PROFILE);
dismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC);
return new PumpEnactResult(injector).success(true).enacted(true);
}
@ -619,6 +623,7 @@ public class AapsOmnipodManager {
dismissNotification(Notification.FAILED_UDPATE_PROFILE);
dismissNotification(Notification.OMNIPOD_POD_SUSPENDED);
dismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC);
return new PumpEnactResult(injector).success(true).enacted(true);
}

View file

@ -251,7 +251,7 @@ class OmnipodOverviewFragment : DaggerFragment() {
omnipod_overview_firmware_version.text = resourceHelper.gs(R.string.omnipod_firmware_version_value, podStateManager.pmVersion.toString(), podStateManager.piVersion.toString())
omnipod_overview_time_on_pod.text = readableZonedTime(podStateManager.time)
omnipod_overview_time_on_pod.setTextColor(if (podStateManager.timeDeviatesMoreThan(Duration.standardMinutes(5))) {
omnipod_overview_time_on_pod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
Color.RED
} else {
Color.WHITE

View file

@ -106,6 +106,7 @@
<string name="omnipod_error_rileylink_address_invalid">RileyLink address invalid.</string>
<string name="omnipod_error_operation_not_possible_no_configuration">Operation is not possible.\n\nYou need to configure Omnipod first, before you can use this operation.</string>
<string name="omnipod_error_pod_not_attached">No active Pod</string>
<string name="omnipod_error_time_out_of_sync">The time on the Pod is out of sync. Please update the time in the Omnipod tab.</string>
<string name="omnipod_error_unexpected_exception">An unexpected error occurred. Please report! (%1$s: %2$s).</string>
<string name="omnipod_error_crc_mismatch">Communication failed: message integrity verification failed</string>
<string name="omnipod_error_invalid_packet_type">Communication failed: received an invalid packet from the Pod</string>