- Partial fix for display of RL status

- Fix IllegalStateException when AssignAddressAction is executed when an address has already been assigned
- Improve (not yet used) custom unreachable alert check
- Remove hasFixedUnreachableAlert from PumpType
- Remove omnipodPumpStatus.podAvailable in favor of PodStateManager
- Remove some unused code / comments
- Add a bunch of TODOs
This commit is contained in:
Bart Sopers 2020-08-10 17:58:54 +02:00
parent 4d04353e7b
commit a0ca8cf9cc
13 changed files with 48 additions and 73 deletions

View file

@ -55,7 +55,6 @@ public class PumpDescription {
public boolean supportsTDDs;
public boolean needsManualTDDLoad;
public boolean hasFixedUnreachableAlert;
public boolean hasCustomUnreachableAlertCheck;
public void resetSettings() {
@ -90,7 +89,6 @@ public class PumpDescription {
supportsTDDs = false;
needsManualTDDLoad = true;
hasFixedUnreachableAlert = false;
hasCustomUnreachableAlertCheck = false;
}
@ -140,7 +138,6 @@ public class PumpDescription {
is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min);
hasFixedUnreachableAlert = pumpType.getHasFixedUnreachableAlert();
hasCustomUnreachableAlertCheck = pumpType.getHasCustomUnreachableAlertCheck();
}

View file

@ -102,13 +102,13 @@ public enum PumpType {
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true, true),
0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true),
Insulet_Omnipod_Dash("Insulet Omnipod Dash", ManufacturerType.Insulet, "Omnipod Dash", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true, true), // TODO just copied OmniPod for now
0.05d, null, 0.05d, null, PumpCapability.OmnipodCapabilities, true), // TODO just copied OmniPod for now
// Medtronic
Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, //
@ -163,7 +163,6 @@ public enum PumpType {
private double baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability;
private boolean hasFixedUnreachableAlert;
private boolean hasCustomUnreachableAlertCheck;
private PumpType parent;
@ -231,7 +230,7 @@ public enum PumpType {
PumpCapability pumpCapability) {
this(description, manufacturer, model, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType,
tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep,
baseBasalSpecialSteps, pumpCapability, false, false);
baseBasalSpecialSteps, pumpCapability, false);
}
@ -249,7 +248,6 @@ public enum PumpType {
double baseBasalStep,
DoseStepSize baseBasalSpecialSteps, //
PumpCapability pumpCapability,
boolean hasFixedUnreachableAlert,
boolean hasCustomUnreachableAlertCheck) {
this.description = description;
this.manufacturer = manufacturer;
@ -265,17 +263,11 @@ public enum PumpType {
this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability;
this.hasFixedUnreachableAlert = hasFixedUnreachableAlert;
this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck;
}
public boolean getHasFixedUnreachableAlert() {
return hasFixedUnreachableAlert;
}
public boolean getHasCustomUnreachableAlertCheck() {
return hasFixedUnreachableAlert;
return hasCustomUnreachableAlertCheck;
}
public String getDescription() {

View file

@ -31,6 +31,8 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -167,10 +169,11 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
this.pumpFrequency.setText(resourceHelper.gs(R.string.omnipod_frequency));
// TODO needs improvement
if (omnipodPumpStatus != null) {
if (omnipodPumpStatus.podAvailable) {
this.serialNumber.setText(omnipodPumpStatus.podLotNumber);
PodStateManager podStateManager = ((OmnipodPumpPlugin) pumpPlugin).getPodStateManager();
if (podStateManager.isPaired()) {
this.serialNumber.setText(podStateManager.getLot());
this.connectedDevice.setText(omnipodPumpStatus.pumpType == PumpType.Insulet_Omnipod ? "Eros Pod" : "Dash Pod");
} else {
this.serialNumber.setText("??");

View file

@ -218,16 +218,18 @@ class OmnipodFragment : DaggerFragment() {
aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus)
val resourceId = rileyLinkServiceData.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod)
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
val resourceId = rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod)
val rileyLinkError = rileyLinkServiceData.rileyLinkError
omnipod_rl_status.text =
when {
omnipodPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
}
omnipod_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
@ -235,7 +237,7 @@ class OmnipodFragment : DaggerFragment() {
// RileyLinkUtil.getError()) as RileyLinkError?
omnipod_errors.text =
omnipodPumpStatus.rileyLinkError?.let {
rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod))
} ?: "-"
@ -258,11 +260,9 @@ class OmnipodFragment : DaggerFragment() {
} else {
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_pod_connected)
}
omnipodPumpStatus.podAvailable = false
omnipodPumpStatus.podNumber == null
} else {
omnipodPumpStatus.podLotNumber = "" + podStateManager.lot
omnipodPumpStatus.podAvailable = podStateManager.isSetupCompleted
omnipod_pod_address.text = podStateManager.address.toString()
omnipod_pod_lot.text = podStateManager.lot.toString()
omnipod_pod_tid.text = podStateManager.tid.toString()
@ -270,13 +270,11 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_expiry.text = podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = podStateManager.address.toString()
var podDeviceState = omnipodPumpStatus.podDeviceState
var stateText: String?
if(podStateManager.hasFaultEvent()) {
if (podStateManager.hasFaultEvent()) {
val faultEventCode = podStateManager.faultEvent.faultEventCode
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) + " ("+ faultEventCode.value +" "+ faultEventCode.name +")"
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) + " (" + faultEventCode.value + " " + faultEventCode.name + ")"
} else if (podStateManager.isSetupCompleted) {
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running)
if (podStateManager.lastDeliveryStatus != null) {
@ -323,8 +321,9 @@ class OmnipodFragment : DaggerFragment() {
setDeviceStatus()
if (omnipodPumpStatus.podAvailable) {
if (podStateManager.isPaired) {
// last connection
// TODO replace with podStateManager.getLastSuccessfulCommunication
if (omnipodPumpStatus.lastConnection != 0L) {
//val minAgo = DateUtil.minAgo(pumpStatus.lastConnection)
val min = (System.currentTimeMillis() - omnipodPumpStatus.lastConnection) / 1000 / 60
@ -355,9 +354,10 @@ class OmnipodFragment : DaggerFragment() {
}
// last bolus
// TODO replace with podStateManager.getLastBolus
val bolus = omnipodPumpStatus.lastBolusAmount
val bolusTime = omnipodPumpStatus.lastBolusTime
if (bolus != null && bolusTime != null && omnipodPumpStatus.podAvailable) {
if (bolus != null && bolusTime != null) {
val agoMsc = System.currentTimeMillis() - omnipodPumpStatus.lastBolusTime.time
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
@ -401,8 +401,7 @@ class OmnipodFragment : DaggerFragment() {
updateAcknowledgeAlerts()
omnipod_refresh.isEnabled = omnipodPumpStatus.podAvailable
omnipod_refresh.isEnabled = podStateManager.isPaired
}
private fun updateAcknowledgeAlerts() {

View file

@ -88,9 +88,7 @@ import io.reactivex.schedulers.Schedulers;
*/
@Singleton
public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice {
// TODO Dagger (maybe done)
@Inject protected PodStateManager podStateManager;
protected PodStateManager podStateManager;
private static OmnipodPumpPlugin plugin = null;
private RileyLinkServiceData rileyLinkServiceData;
private ServiceTaskExecutor serviceTaskExecutor;
@ -110,6 +108,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private boolean isInitialized = false;
protected OmnipodCommunicationManagerInterface omnipodCommunicationManager;
// TODO make non-static just inject the Singleton and use a getter)
public static boolean isBusy = false;
protected List<Long> busyTimestamps = new ArrayList<>();
protected boolean sentIdToFirebase = false;
@ -135,6 +134,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
SP sp,
OmnipodUtil omnipodUtil,
OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager,
CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy,
RileyLinkServiceData rileyLinkServiceData,
@ -150,7 +150,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
PumpType.Insulet_Omnipod,
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy
);
injector.androidInjector().inject(this);
this.podStateManager = podStateManager;
this.rileyLinkServiceData = rileyLinkServiceData;
this.serviceTaskExecutor = serviceTaskExecutor;
@ -182,6 +182,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return plugin;
}
public PodStateManager getPodStateManager() {
return podStateManager;
}
@Override
protected void onStart() {
@ -402,7 +405,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (isServiceSet()) {
if (isBusy || !omnipodPumpStatus.podAvailable)
if (isBusy || !podStateManager.isSetupCompleted())
return true;
if (busyTimestamps.size() > 0) {
@ -491,19 +494,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
public boolean isSuspended() {
return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod ||
!podStateManager.isSetupCompleted() || podStateManager.isSuspended();
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
//
// TODO ddd
// return (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
//
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
}
@Override
@ -1001,9 +993,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
if (omnipodPumpStatus.lastConnection != 0 || omnipodPumpStatus.lastErrorConnection != 0) {
if (omnipodPumpStatus.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if (omnipodPumpStatus.lastErrorConnection > omnipodPumpStatus.lastConnection) {
if (podStateManager.isSetupCompleted() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if (podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) {
// We exceeded the alert threshold, and our last connection failed
// We should show an alert
return true;

View file

@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
/**
* Created by andy on 6/29/18.
*/
// TODO make singleton
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
@Inject public AAPSLogger aapsLogger;
@ -58,6 +59,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
//@Inject RileyLinkServiceData rileyLinkServiceData;
//@Inject ServiceTaskExecutor serviceTaskExecutor;
@Inject
public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy);
omnipodPumpStatus.previousConnection = sp.getLong(

View file

@ -7,10 +7,12 @@ import java.util.Random;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.AssignAddressCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -29,8 +31,8 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
if (!podStateManager.hasState()) {
podStateManager.initState(generateRandomAddress());
}
if (podStateManager.isPaired()) {
throw new IllegalStateException("podStateManager already has a paired Pod");
if (podStateManager.isPaired() && podStateManager.getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podStateManager.getSetupProgress());
}
AssignAddressCommand assignAddress = new AssignAddressCommand(podStateManager.getAddress());
@ -53,7 +55,6 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
return assignAddressResponse;
}
private static int generateRandomAddress() {
// Create random address with 20 bits to match PDM, could easily use 24 bits instead
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);

View file

@ -46,7 +46,7 @@ public class SetTempBasalAction implements OmnipodAction<StatusResponse> {
OmnipodMessage message = new OmnipodMessage(podStateManager.getAddress(), messageBlocks, podStateManager.getMessageNumber());
StatusResponse statusResponse = communicationService.exchangeMessages(StatusResponse.class, podStateManager, message);
podStateManager.setLastTempBasal(new DateTime().minus(OmnipodConst.AVERAGE_TEMP_BASAL_COMMAND_COMMUNICATION_DURATION), rate, duration);
podStateManager.setLastTempBasal(DateTime.now().minus(OmnipodConst.AVERAGE_TEMP_BASAL_COMMAND_COMMUNICATION_DURATION), rate, duration);
return statusResponse;
}
}

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.R;
* Created by andy on 4.8.2019
*/
// FIXME remove
public enum PodDeviceState {
// FIXME

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver;
// TODO replace with method calls on PodStateManager
public enum OmnipodDriverState {
NotInitalized, // when we start

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/
@Singleton
public class OmnipodPumpStatus extends PumpStatus {
// TODO remove all fields that can also be obtained via PodStateManager
private final ResourceHelper resourceHelper;
private final SP sp;
@ -37,8 +38,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public boolean inPreInit = true;
// statuses
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
public RileyLinkError rileyLinkError;
public double currentBasal = 0;
public long tempBasalStart;
public long tempBasalEnd;
@ -51,9 +50,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public String podNumber;
public PodDeviceState podDeviceState = PodDeviceState.NeverContacted;
// FIXME replace with method calls on PodStateManager
public boolean podAvailable = false;
public boolean podAvailibityChecked = false;
public boolean ackAlertsAvailable = false;
public String ackAlertsText = null;
@ -88,9 +84,7 @@ public class OmnipodPumpStatus extends PumpStatus {
this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75;
this.lastConnection = sp.getLong(OmnipodConst.Statistics.LastGoodPumpCommunicationTime, 0L);
this.lastDataTime = this.lastConnection;
this.pumpType = PumpType.Insulet_Omnipod;
this.podAvailable = false;
}
@ -133,8 +127,6 @@ public class OmnipodPumpStatus extends PumpStatus {
"errorDescription='" + errorDescription + '\'' +
", rileyLinkAddress='" + rileyLinkAddress + '\'' +
", inPreInit=" + inPreInit +
", rileyLinkServiceState=" + rileyLinkServiceState +
", rileyLinkError=" + rileyLinkError +
", currentBasal=" + currentBasal +
", tempBasalStart=" + tempBasalStart +
", tempBasalEnd=" + tempBasalEnd +
@ -143,7 +135,6 @@ public class OmnipodPumpStatus extends PumpStatus {
", regexMac='" + regexMac + '\'' +
", podNumber='" + podNumber + '\'' +
", podDeviceState=" + podDeviceState +
", podAvailable=" + podAvailable +
", ackAlertsAvailable=" + ackAlertsAvailable +
", ackAlertsText='" + ackAlertsText + '\'' +
", lastDataTime=" + lastDataTime +

View file

@ -72,6 +72,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.Disposable;
// TODO make singleton
public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface {
private final PodStateManager podStateManager;

View file

@ -131,11 +131,6 @@ public class OmnipodUtil {
return gsonBuilder.create();
}
public void notifyDeviceStatusChanged() {
}
public void setPodDeviceState(PodDeviceState podDeviceState) {
omnipodPumpStatus.podDeviceState = podDeviceState;
}