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

This commit is contained in:
Andy Rozman 2020-08-10 23:07:14 +01:00
commit 5e20444bf4
23 changed files with 137 additions and 158 deletions

View file

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

View file

@ -102,13 +102,13 @@ public enum PumpType {
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // 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, // Insulet_Omnipod_Dash("Insulet Omnipod Dash", ManufacturerType.Insulet, "Omnipod Dash", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // 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
Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, // Medtronic_512_712("Medtronic 512/712", ManufacturerType.Medtronic, "512/712", 0.1d, null, //
@ -163,7 +163,6 @@ public enum PumpType {
private double baseBasalStep; // private double baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; // private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability; private PumpCapability pumpCapability;
private boolean hasFixedUnreachableAlert;
private boolean hasCustomUnreachableAlertCheck; private boolean hasCustomUnreachableAlertCheck;
private PumpType parent; private PumpType parent;
@ -231,7 +230,7 @@ public enum PumpType {
PumpCapability pumpCapability) { PumpCapability pumpCapability) {
this(description, manufacturer, model, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, this(description, manufacturer, model, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType,
tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep,
baseBasalSpecialSteps, pumpCapability, false, false); baseBasalSpecialSteps, pumpCapability, false);
} }
@ -249,7 +248,6 @@ public enum PumpType {
double baseBasalStep, double baseBasalStep,
DoseStepSize baseBasalSpecialSteps, // DoseStepSize baseBasalSpecialSteps, //
PumpCapability pumpCapability, PumpCapability pumpCapability,
boolean hasFixedUnreachableAlert,
boolean hasCustomUnreachableAlertCheck) { boolean hasCustomUnreachableAlertCheck) {
this.description = description; this.description = description;
this.manufacturer = manufacturer; this.manufacturer = manufacturer;
@ -265,17 +263,11 @@ public enum PumpType {
this.baseBasalStep = baseBasalStep; this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps; this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability; this.pumpCapability = pumpCapability;
this.hasFixedUnreachableAlert = hasFixedUnreachableAlert;
this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck; this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck;
} }
public boolean getHasFixedUnreachableAlert() {
return hasFixedUnreachableAlert;
}
public boolean getHasCustomUnreachableAlertCheck() { public boolean getHasCustomUnreachableAlertCheck() {
return hasFixedUnreachableAlert; return hasCustomUnreachableAlertCheck;
} }
public String getDescription() { 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.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; 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.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.utils.resources.ResourceHelper; 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)); this.pumpFrequency.setText(resourceHelper.gs(R.string.omnipod_frequency));
// TODO needs improvement
if (omnipodPumpStatus != null) { if (omnipodPumpStatus != null) {
PodStateManager podStateManager = ((OmnipodPumpPlugin) pumpPlugin).getPodStateManager();
if (omnipodPumpStatus.podAvailable) { if (podStateManager.isPaired()) {
this.serialNumber.setText(omnipodPumpStatus.podLotNumber); this.serialNumber.setText(podStateManager.getLot());
this.connectedDevice.setText(omnipodPumpStatus.pumpType == PumpType.Insulet_Omnipod ? "Eros Pod" : "Dash Pod"); this.connectedDevice.setText(omnipodPumpStatus.pumpType == PumpType.Insulet_Omnipod ? "Eros Pod" : "Dash Pod");
} else { } else {
this.serialNumber.setText("??"); this.serialNumber.setText("??");

View file

@ -33,6 +33,7 @@ public class RileyLinkServiceData {
boolean tuneUpDone = false; boolean tuneUpDone = false;
public RileyLinkError rileyLinkError; public RileyLinkError rileyLinkError;
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted; public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
private long lastServiceStateChange = 0L;
public RileyLinkFirmwareVersion firmwareVersion; public RileyLinkFirmwareVersion firmwareVersion;
public RileyLinkTargetFrequency rileyLinkTargetFrequency; // TODO this might not be correct place public RileyLinkTargetFrequency rileyLinkTargetFrequency; // TODO this might not be correct place
@ -52,7 +53,8 @@ public class RileyLinkServiceData {
public byte[] pumpIDBytes; public byte[] pumpIDBytes;
@Inject @Inject
public RileyLinkServiceData() {} public RileyLinkServiceData() {
}
public void setPumpID(String pumpId, byte[] pumpIdBytes) { public void setPumpID(String pumpId, byte[] pumpIdBytes) {
this.pumpID = pumpId; this.pumpID = pumpId;
@ -71,17 +73,22 @@ public class RileyLinkServiceData {
workWithServiceState(newState, errorCode, true); workWithServiceState(newState, errorCode, true);
} }
public long getLastServiceStateChange() {
return lastServiceStateChange;
}
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) { private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
if (set) { if (set) {
rileyLinkServiceState = newState; rileyLinkServiceState = newState;
lastServiceStateChange = System.currentTimeMillis();
this.rileyLinkError = errorCode; this.rileyLinkError = errorCode;
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name()); aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice)); rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice));
if (activePlugin.getActivePump().manufacturer()== ManufacturerType.Medtronic) if (activePlugin.getActivePump().manufacturer() == ManufacturerType.Medtronic)
rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode)); rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode));
else { else {
rxBus.send(new EventOmnipodDeviceStatusChange(newState, errorCode)); rxBus.send(new EventOmnipodDeviceStatusChange(newState, errorCode));

View file

@ -45,6 +45,7 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.omnipod_fragment.* import kotlinx.android.synthetic.main.omnipod_fragment.*
import org.apache.commons.lang3.StringUtils
import javax.inject.Inject import javax.inject.Inject
class OmnipodFragment : DaggerFragment() { class OmnipodFragment : DaggerFragment() {
@ -87,11 +88,6 @@ class OmnipodFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
omnipod_rl_status.text = resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(RileyLinkTargetDevice.Omnipod))
omnipod_pod_status.setTextColor(Color.WHITE)
omnipod_pod_status.text = "{fa-bed}"
omnipod_pod_mgmt.setOnClickListener { omnipod_pod_mgmt.setOnClickListener {
if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) { if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, PodManagementActivity::class.java)) startActivity(Intent(context, PodManagementActivity::class.java))
@ -147,10 +143,6 @@ class OmnipodFragment : DaggerFragment() {
} }
omnipod_lastconnection.setTextColor(Color.WHITE) omnipod_lastconnection.setTextColor(Color.WHITE)
setVisibilityOfPodDebugButton()
updateGUI()
} }
override fun onResume() { override fun onResume() {
@ -181,6 +173,7 @@ class OmnipodFragment : DaggerFragment() {
.subscribe({ .subscribe({
setVisibilityOfPodDebugButton() setVisibilityOfPodDebugButton()
}, { fabricPrivacy.logException(it) }) }, { fabricPrivacy.logException(it) })
updateGUI()
} }
fun setVisibilityOfPodDebugButton() { fun setVisibilityOfPodDebugButton() {
@ -212,36 +205,29 @@ class OmnipodFragment : DaggerFragment() {
@Synchronized @Synchronized
private fun setDeviceStatus() { private fun setDeviceStatus() {
//val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus()
// omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState,
// RileyLinkUtil.getServiceState()) as RileyLinkServiceState?
aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus) aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus)
val resourceId = rileyLinkServiceData.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod) val errors = ArrayList<String>();
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
val resourceId = rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod)
val rileyLinkError = rileyLinkServiceData.rileyLinkError val rileyLinkError = rileyLinkServiceData.rileyLinkError
omnipod_rl_status.text = omnipod_rl_status.text =
when { when {
omnipodPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId) rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId) rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId) rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
omnipodPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump)) rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.Omnipod))
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId) else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
} }
omnipod_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE) omnipod_rl_status.setTextColor(if (rileyLinkServiceState.isError || rileyLinkError != null) Color.RED else Color.WHITE)
// omnipodPumpStatus.rileyLinkError = checkStatusSet(omnipodPumpStatus.rileyLinkError, val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
// RileyLinkUtil.getError()) as RileyLinkError? if (rileyLinkErrorInfo != null) {
errors.add(rileyLinkErrorInfo)
omnipod_errors.text = }
omnipodPumpStatus.rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod))
} ?: "-"
val driverState = omnipodUtil.getDriverState();
aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState)
if (!podStateManager.hasState() || !podStateManager.isPaired) { if (!podStateManager.hasState() || !podStateManager.isPaired) {
if (podStateManager.hasState()) { if (podStateManager.hasState()) {
@ -258,11 +244,8 @@ class OmnipodFragment : DaggerFragment() {
} else { } else {
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_pod_connected) omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_no_pod_connected)
} }
omnipodPumpStatus.podAvailable = false
omnipodPumpStatus.podNumber == null omnipodPumpStatus.podNumber == null
} else { } else {
omnipodPumpStatus.podLotNumber = "" + podStateManager.lot
omnipodPumpStatus.podAvailable = podStateManager.isSetupCompleted
omnipod_pod_address.text = podStateManager.address.toString() omnipod_pod_address.text = podStateManager.address.toString()
omnipod_pod_lot.text = podStateManager.lot.toString() omnipod_pod_lot.text = podStateManager.lot.toString()
omnipod_pod_tid.text = podStateManager.tid.toString() omnipod_pod_tid.text = podStateManager.tid.toString()
@ -270,26 +253,30 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_expiry.text = podStateManager.expiryDateAsString omnipod_pod_expiry.text = podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = podStateManager.address.toString() omnipodPumpStatus.podNumber = podStateManager.address.toString()
var podDeviceState = omnipodPumpStatus.podDeviceState val stateText: String
var stateText: String? when {
podStateManager.hasFaultEvent() -> {
if(podStateManager.hasFaultEvent()) { val faultEventCode = podStateManager.faultEvent.faultEventCode
val faultEventCode = podStateManager.faultEvent.faultEventCode stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault)
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault) + " ("+ faultEventCode.value +" "+ faultEventCode.name +")" errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
} else if (podStateManager.isSetupCompleted) { }
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running)
if (podStateManager.lastDeliveryStatus != null) { podStateManager.isSetupCompleted -> {
stateText += " (last delivery status: " + podStateManager.lastDeliveryStatus.name + ")" stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_running, if (podStateManager.lastDeliveryStatus == null) null else podStateManager.lastDeliveryStatus.name)
}
else -> {
stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress, podStateManager.setupProgress.name)
} }
} else {
stateText = resourceHelper.gs(R.string.omnipod_pod_setup_in_progress)
stateText += " (setup progress: " + podStateManager.setupProgress.name + ")"
} }
omnipod_pod_status.text = stateText omnipod_pod_status.text = stateText
} }
omnipod_pod_status.setTextColor(if (podStateManager.hasFaultEvent()) Color.RED else Color.WHITE)
omnipod_errors.text = if (errors.size == 0) "-" else StringUtils.join(errors, System.lineSeparator())
val status = commandQueue.spannedStatus() val status = commandQueue.spannedStatus()
if (status.toString() == "") { if (status.toString() == "") {
omnipod_queue.visibility = View.GONE omnipod_queue.visibility = View.GONE
@ -323,8 +310,9 @@ class OmnipodFragment : DaggerFragment() {
setDeviceStatus() setDeviceStatus()
if (omnipodPumpStatus.podAvailable) { if (podStateManager.isPaired) {
// last connection // last connection
// TODO replace with podStateManager.getLastSuccessfulCommunication
if (omnipodPumpStatus.lastConnection != 0L) { if (omnipodPumpStatus.lastConnection != 0L) {
//val minAgo = DateUtil.minAgo(pumpStatus.lastConnection) //val minAgo = DateUtil.minAgo(pumpStatus.lastConnection)
val min = (System.currentTimeMillis() - omnipodPumpStatus.lastConnection) / 1000 / 60 val min = (System.currentTimeMillis() - omnipodPumpStatus.lastConnection) / 1000 / 60
@ -355,9 +343,10 @@ class OmnipodFragment : DaggerFragment() {
} }
// last bolus // last bolus
// TODO replace with podStateManager.getLastBolus
val bolus = omnipodPumpStatus.lastBolusAmount val bolus = omnipodPumpStatus.lastBolusAmount
val bolusTime = omnipodPumpStatus.lastBolusTime val bolusTime = omnipodPumpStatus.lastBolusTime
if (bolus != null && bolusTime != null && omnipodPumpStatus.podAvailable) { if (bolus != null && bolusTime != null) {
val agoMsc = System.currentTimeMillis() - omnipodPumpStatus.lastBolusTime.time val agoMsc = System.currentTimeMillis() - omnipodPumpStatus.lastBolusTime.time
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0 val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
val unit = resourceHelper.gs(R.string.insulin_unit_shortname) val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
@ -397,12 +386,11 @@ class OmnipodFragment : DaggerFragment() {
omnipod_lastconnection.setTextColor(Color.WHITE) omnipod_lastconnection.setTextColor(Color.WHITE)
} }
omnipod_errors.text = omnipodPumpStatus.errorInfo
updateAcknowledgeAlerts() updateAcknowledgeAlerts()
omnipod_refresh.isEnabled = omnipodPumpStatus.podAvailable setVisibilityOfPodDebugButton()
omnipod_refresh.isEnabled = podStateManager.isPaired
} }
private fun updateAcknowledgeAlerts() { private fun updateAcknowledgeAlerts() {

View file

@ -90,9 +90,7 @@ import io.reactivex.schedulers.Schedulers;
*/ */
@Singleton @Singleton
public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice { public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice {
protected PodStateManager podStateManager;
// TODO Dagger (maybe done)
@Inject protected PodStateManager podStateManager;
private static OmnipodPumpPlugin plugin = null; private static OmnipodPumpPlugin plugin = null;
private RileyLinkServiceData rileyLinkServiceData; private RileyLinkServiceData rileyLinkServiceData;
private ServiceTaskExecutor serviceTaskExecutor; private ServiceTaskExecutor serviceTaskExecutor;
@ -112,6 +110,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private boolean isInitialized = false; private boolean isInitialized = false;
protected OmnipodCommunicationManagerInterface omnipodCommunicationManager; protected OmnipodCommunicationManagerInterface omnipodCommunicationManager;
// TODO make non-static just inject the Singleton and use a getter)
public static boolean isBusy = false; public static boolean isBusy = false;
protected List<Long> busyTimestamps = new ArrayList<>(); protected List<Long> busyTimestamps = new ArrayList<>();
protected boolean sentIdToFirebase = false; protected boolean sentIdToFirebase = false;
@ -137,6 +136,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
SP sp, SP sp,
OmnipodUtil omnipodUtil, OmnipodUtil omnipodUtil,
OmnipodPumpStatus omnipodPumpStatus, OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager,
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy, FabricPrivacy fabricPrivacy,
RileyLinkServiceData rileyLinkServiceData, RileyLinkServiceData rileyLinkServiceData,
@ -152,7 +152,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
PumpType.Insulet_Omnipod, PumpType.Insulet_Omnipod,
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy
); );
injector.androidInjector().inject(this); this.podStateManager = podStateManager;
this.rileyLinkServiceData = rileyLinkServiceData; this.rileyLinkServiceData = rileyLinkServiceData;
this.serviceTaskExecutor = serviceTaskExecutor; this.serviceTaskExecutor = serviceTaskExecutor;
@ -184,6 +184,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return plugin; return plugin;
} }
public PodStateManager getPodStateManager() {
return podStateManager;
}
@Override @Override
protected void onStart() { protected void onStart() {
@ -404,7 +407,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (isServiceSet()) { if (isServiceSet()) {
if (isBusy || !omnipodPumpStatus.podAvailable) if (isBusy || !podStateManager.isSetupCompleted())
return true; return true;
if (busyTimestamps.size() > 0) { if (busyTimestamps.size() > 0) {
@ -493,19 +496,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod || return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod ||
!podStateManager.isSetupCompleted() || podStateManager.isSuspended(); !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 @Override
@ -615,6 +607,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
// FIXME do we actually need this? If a user presses refresh during an action,
// I suppose the GetStatusCommand would just be queued?
private void setRefreshButtonEnabled(boolean enabled) { private void setRefreshButtonEnabled(boolean enabled) {
rxBus.send(new EventOmnipodRefreshButtonState(enabled)); rxBus.send(new EventOmnipodRefreshButtonState(enabled));
} }
@ -1004,15 +998,19 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) { public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
if (omnipodPumpStatus.lastConnection != 0 || omnipodPumpStatus.lastErrorConnection != 0) { long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
if (omnipodPumpStatus.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) { if (podStateManager.isSetupCompleted() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
if (omnipodPumpStatus.lastErrorConnection > omnipodPumpStatus.lastConnection) { if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
// We exceeded the alert threshold, and our last connection failed if ((podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
rileyLinkServiceData.rileyLinkServiceState.isError() ||
// The below clause is a hack for working around the RL service state forever staying in connecting state on startup if the RL is switched off / unreachable
(rileyLinkServiceData.getRileyLinkServiceState().isConnecting() && rileyLinkServiceData.getLastServiceStateChange() + rileyLinkInitializationTimeout < System.currentTimeMillis())) {
// We exceeded the alert threshold, and either our last command failed or we cannot reach the RL
// We should show an alert // We should show an alert
return true; return true;
} }
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful // Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
// This happens when we simply didn't need to send any commands to the pump // This happens when we simply didn't need to send any commands to the pump
} }
} }

View file

@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
/** /**
* Created by andy on 6/29/18. * Created by andy on 6/29/18.
*/ */
// TODO make singleton
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager { public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
@Inject public AAPSLogger aapsLogger; @Inject public AAPSLogger aapsLogger;
@ -58,6 +59,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
//@Inject RileyLinkServiceData rileyLinkServiceData; //@Inject RileyLinkServiceData rileyLinkServiceData;
//@Inject ServiceTaskExecutor serviceTaskExecutor; //@Inject ServiceTaskExecutor serviceTaskExecutor;
@Inject
public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) { public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy); super(injector, rfspy);
omnipodPumpStatus.previousConnection = sp.getLong( 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.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException; 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.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; 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.command.AssignAddressCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse; 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.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
@ -29,8 +31,8 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
if (!podStateManager.hasState()) { if (!podStateManager.hasState()) {
podStateManager.initState(generateRandomAddress()); podStateManager.initState(generateRandomAddress());
} }
if (podStateManager.isPaired()) { if (podStateManager.isPaired() && podStateManager.getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalStateException("podStateManager already has a paired Pod"); throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podStateManager.getSetupProgress());
} }
AssignAddressCommand assignAddress = new AssignAddressCommand(podStateManager.getAddress()); AssignAddressCommand assignAddress = new AssignAddressCommand(podStateManager.getAddress());
@ -53,7 +55,6 @@ public class AssignAddressAction implements OmnipodAction<VersionResponse> {
return assignAddressResponse; return assignAddressResponse;
} }
private static int generateRandomAddress() { private static int generateRandomAddress() {
// Create random address with 20 bits to match PDM, could easily use 24 bits instead // Create random address with 20 bits to match PDM, could easily use 24 bits instead
return 0x1f000000 | (new Random().nextInt() & 0x000fffff); 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()); OmnipodMessage message = new OmnipodMessage(podStateManager.getAddress(), messageBlocks, podStateManager.getMessageNumber());
StatusResponse statusResponse = communicationService.exchangeMessages(StatusResponse.class, podStateManager, message); 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; return statusResponse;
} }
} }

View file

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

View file

@ -6,8 +6,6 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import net.danlew.android.joda.JodaTimeAndroid;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
@ -79,7 +77,7 @@ public abstract class PodStateManager {
if (!hasState()) { if (!hasState()) {
throw new IllegalStateException("Cannot set pairing parameters: podState is null"); throw new IllegalStateException("Cannot set pairing parameters: podState is null");
} }
if (isPaired()) { if (isPaired() && getSetupProgress().isAfter(SetupProgress.ADDRESS_ASSIGNED)) {
throw new IllegalStateException("Cannot set pairing parameters: pairing parameters have already been set"); throw new IllegalStateException("Cannot set pairing parameters: pairing parameters have already been set");
} }
if (piVersion == null) { if (piVersion == null) {
@ -125,11 +123,11 @@ public abstract class PodStateManager {
} }
public final void increaseMessageNumber() { public final void increaseMessageNumber() {
setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111)); setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111), false);
} }
public final void increasePacketNumber() { public final void increasePacketNumber() {
setAndStore(() -> podState.setPacketNumber((podState.getPacketNumber() + 1) & 0b11111)); setAndStore(() -> podState.setPacketNumber((podState.getPacketNumber() + 1) & 0b11111), false);
} }
public final synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) { public final synchronized void resyncNonce(int syncWord, int sentNonce, int sequenceNumber) {
@ -144,7 +142,7 @@ public abstract class PodStateManager {
int seed = ((sum & 0xFFFF) ^ syncWord); int seed = ((sum & 0xFFFF) ^ syncWord);
NonceState nonceState = new NonceState(podState.getLot(), podState.getTid(), (byte) (seed & 0xFF)); NonceState nonceState = new NonceState(podState.getLot(), podState.getTid(), (byte) (seed & 0xFF));
setAndStore(() -> podState.setNonceState(nonceState)); setAndStore(() -> podState.setNonceState(nonceState), false);
} }
public final synchronized int getCurrentNonce() { public final synchronized int getCurrentNonce() {
@ -158,7 +156,7 @@ public abstract class PodStateManager {
if (!isPaired()) { if (!isPaired()) {
throw new IllegalStateException("Cannot advance to next nonce: Pod is not paired yet"); throw new IllegalStateException("Cannot advance to next nonce: Pod is not paired yet");
} }
setAndStore(() -> podState.getNonceState().advanceToNextNonce()); setAndStore(() -> podState.getNonceState().advanceToNextNonce(), false);
} }
public final DateTime getLastSuccessfulCommunication() { public final DateTime getLastSuccessfulCommunication() {
@ -178,7 +176,7 @@ public abstract class PodStateManager {
} }
public final boolean hasFaultEvent() { public final boolean hasFaultEvent() {
return getSafe(() -> podState.getFaultEvent()) != null; return podState != null && podState.getFaultEvent() != null;
} }
public final PodInfoFaultEvent getFaultEvent() { public final PodInfoFaultEvent getFaultEvent() {
@ -202,6 +200,9 @@ public abstract class PodStateManager {
} }
public final boolean hasActiveAlerts() { public final boolean hasActiveAlerts() {
if (podState == null) {
return false;
}
AlertSet activeAlerts = podState.getActiveAlerts(); AlertSet activeAlerts = podState.getActiveAlerts();
return activeAlerts != null && activeAlerts.size() > 0; return activeAlerts != null && activeAlerts.size() > 0;
} }
@ -358,12 +359,18 @@ public abstract class PodStateManager {
} }
private void setAndStore(Runnable runnable) { private void setAndStore(Runnable runnable) {
setAndStore(runnable, true);
}
private void setAndStore(Runnable runnable, boolean notifyPodStateChanged) {
if (!hasState()) { if (!hasState()) {
throw new IllegalStateException("Cannot mutate PodState: podState is null"); throw new IllegalStateException("Cannot mutate PodState: podState is null");
} }
runnable.run(); runnable.run();
storePodState(); storePodState();
notifyPodStateChanged(); if (notifyPodStateChanged) {
notifyPodStateChanged();
}
} }
private void storePodState() { private void storePodState() {
@ -483,12 +490,6 @@ public abstract class PodStateManager {
} }
void setPiVersion(FirmwareVersion piVersion) { void setPiVersion(FirmwareVersion piVersion) {
if (this.piVersion != null) {
throw new IllegalStateException("piVersion has already been set");
}
if (piVersion == null) {
throw new IllegalArgumentException("piVersion can not be null");
}
this.piVersion = piVersion; this.piVersion = piVersion;
} }

View file

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

View file

@ -11,8 +11,6 @@ import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
@ -26,19 +24,19 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/ */
@Singleton @Singleton
public class OmnipodPumpStatus extends PumpStatus { public class OmnipodPumpStatus extends PumpStatus {
// TODO remove all fields that can also be obtained via PodStateManager
// We can probably get rid of this class altogether
private final ResourceHelper resourceHelper; private final ResourceHelper resourceHelper;
private final SP sp; private final SP sp;
private final RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus; private final RxBusWrapper rxBus;
public String errorDescription = null; public String rileyLinkErrorDescription = null;
public String rileyLinkAddress = null; public String rileyLinkAddress = null;
public boolean inPreInit = true; public boolean inPreInit = true;
// statuses // statuses
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
public RileyLinkError rileyLinkError;
public double currentBasal = 0; public double currentBasal = 0;
public long tempBasalStart; public long tempBasalStart;
public long tempBasalEnd; public long tempBasalEnd;
@ -51,9 +49,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public String podNumber; public String podNumber;
public PodDeviceState podDeviceState = PodDeviceState.NeverContacted; 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 boolean ackAlertsAvailable = false;
public String ackAlertsText = null; public String ackAlertsText = null;
@ -62,7 +57,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public boolean beepSMBEnabled = true; public boolean beepSMBEnabled = true;
public boolean beepTBREnabled = true; public boolean beepTBREnabled = true;
public boolean podDebuggingOptionsEnabled = false; public boolean podDebuggingOptionsEnabled = false;
public String podLotNumber = "???";
public boolean timeChangeEventEnabled = true; public boolean timeChangeEventEnabled = true;
public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@ -81,23 +75,19 @@ public class OmnipodPumpStatus extends PumpStatus {
initSettings(); initSettings();
} }
@Override @Override
public void initSettings() { public void initSettings() {
this.activeProfileName = ""; this.activeProfileName = "";
this.reservoirRemainingUnits = 75d; this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75; this.batteryRemaining = 75;
this.lastConnection = sp.getLong(OmnipodConst.Statistics.LastGoodPumpCommunicationTime, 0L); this.lastConnection = sp.getLong(OmnipodConst.Statistics.LastGoodPumpCommunicationTime, 0L);
this.lastDataTime = this.lastConnection;
this.pumpType = PumpType.Insulet_Omnipod; this.pumpType = PumpType.Insulet_Omnipod;
this.podAvailable = false;
} }
// For Omnipod, this method only returns a RileyLink error description
@Override
public String getErrorInfo() { public String getErrorInfo() {
//verifyConfiguration(); return this.rileyLinkErrorDescription;
return (this.errorDescription == null) ? "-" : this.errorDescription;
} }
@ -130,11 +120,9 @@ public class OmnipodPumpStatus extends PumpStatus {
@Override @Override
public String toString() { public String toString() {
return "OmnipodPumpStatus{" + return "OmnipodPumpStatus{" +
"errorDescription='" + errorDescription + '\'' + "rileyLinkErrorDescription='" + rileyLinkErrorDescription + '\'' +
", rileyLinkAddress='" + rileyLinkAddress + '\'' + ", rileyLinkAddress='" + rileyLinkAddress + '\'' +
", inPreInit=" + inPreInit + ", inPreInit=" + inPreInit +
", rileyLinkServiceState=" + rileyLinkServiceState +
", rileyLinkError=" + rileyLinkError +
", currentBasal=" + currentBasal + ", currentBasal=" + currentBasal +
", tempBasalStart=" + tempBasalStart + ", tempBasalStart=" + tempBasalStart +
", tempBasalEnd=" + tempBasalEnd + ", tempBasalEnd=" + tempBasalEnd +
@ -143,7 +131,6 @@ public class OmnipodPumpStatus extends PumpStatus {
", regexMac='" + regexMac + '\'' + ", regexMac='" + regexMac + '\'' +
", podNumber='" + podNumber + '\'' + ", podNumber='" + podNumber + '\'' +
", podDeviceState=" + podDeviceState + ", podDeviceState=" + podDeviceState +
", podAvailable=" + podAvailable +
", ackAlertsAvailable=" + ackAlertsAvailable + ", ackAlertsAvailable=" + ackAlertsAvailable +
", ackAlertsText='" + ackAlertsText + '\'' + ", ackAlertsText='" + ackAlertsText + '\'' +
", lastDataTime=" + lastDataTime + ", lastDataTime=" + lastDataTime +

View file

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

View file

@ -23,8 +23,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
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.EventOmnipodAcknowledgeAlertsChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -85,8 +83,6 @@ public class AapsPodStateManager extends PodStateManager {
omnipodPumpStatus.lastBolusAmount = null; omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0; omnipodPumpStatus.reservoirRemainingUnits = 0.0;
omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended; omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
sendEvent(new EventOmnipodPumpValuesChanged());
sendEvent(new EventRefreshOverview("Omnipod Pump", false)); sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} else { } else {
// Update active alerts // Update active alerts
@ -97,14 +93,11 @@ public class AapsPodStateManager extends PodStateManager {
if (!omnipodPumpStatus.ackAlertsAvailable || !alertsText.equals(omnipodPumpStatus.ackAlertsText)) { if (!omnipodPumpStatus.ackAlertsAvailable || !alertsText.equals(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsAvailable = true; omnipodPumpStatus.ackAlertsAvailable = true;
omnipodPumpStatus.ackAlertsText = TextUtils.join("\n", alerts); omnipodPumpStatus.ackAlertsText = TextUtils.join("\n", alerts);
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
} }
} else { } else {
if (omnipodPumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(omnipodPumpStatus.ackAlertsText)) { if (omnipodPumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsText = null; omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false; omnipodPumpStatus.ackAlertsAvailable = false;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
} }
} }
@ -119,15 +112,15 @@ public class AapsPodStateManager extends PodStateManager {
omnipodPumpStatus.lastBolusTime = lastBolusStartTime; omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
omnipodPumpStatus.lastBolusAmount = lastBolusAmount; omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel(); omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
boolean sendRefreshOverviewEvent = isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType);
omnipodPumpStatus.pumpStatusType = isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running; omnipodPumpStatus.pumpStatusType = isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running;
sendEvent(new EventOmnipodPumpValuesChanged());
if (isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) { if (sendRefreshOverviewEvent) {
sendEvent(new EventRefreshOverview("Omnipod Pump", false)); sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} }
} }
} }
rxBus.send(new EventOmnipodDeviceStatusChange(this)); sendEvent(new EventOmnipodPumpValuesChanged());
} }
private List<String> getTranslatedActiveAlerts() { private List<String> getTranslatedActiveAlerts() {

View file

@ -191,6 +191,7 @@ public class OmnipodUITask {
} }
// FIXME a lot of this is not needed anymore since introducing PodStateManager
public void postProcess(OmnipodUIPostprocessor postprocessor) { public void postProcess(OmnipodUIPostprocessor postprocessor) {
EventOmnipodDeviceStatusChange statusChange; EventOmnipodDeviceStatusChange statusChange;

View file

@ -5,4 +5,5 @@ import info.nightscout.androidaps.events.Event
/** /**
* Created by andy on 04.06.2018. * Created by andy on 04.06.2018.
*/ */
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodAcknowledgeAlertsChanged : Event() class EventOmnipodAcknowledgeAlertsChanged : Event()

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManage
/** /**
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
*/ */
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodDeviceStatusChange : Event { class EventOmnipodDeviceStatusChange : Event {
var rileyLinkServiceState: RileyLinkServiceState? = null var rileyLinkServiceState: RileyLinkServiceState? = null

View file

@ -7,8 +7,6 @@ import android.os.IBinder;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import javax.inject.Inject; import javax.inject.Inject;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -164,17 +162,17 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public boolean verifyConfiguration() { public boolean verifyConfiguration() {
try { try {
omnipodPumpStatus.errorDescription = "-"; omnipodPumpStatus.rileyLinkErrorDescription = null;
String rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); String rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (StringUtils.isEmpty(rileyLinkAddress)) { if (StringUtils.isEmpty(rileyLinkAddress)) {
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: no address"); aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: no address");
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid); omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
return false; return false;
} else { } else {
if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) { if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) {
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid); omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress); aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress);
} else { } else {
if (!rileyLinkAddress.equals(this.omnipodPumpStatus.rileyLinkAddress)) { if (!rileyLinkAddress.equals(this.omnipodPumpStatus.rileyLinkAddress)) {
@ -199,7 +197,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return true; return true;
} catch (Exception ex) { } catch (Exception ex) {
this.omnipodPumpStatus.errorDescription = ex.getMessage(); this.omnipodPumpStatus.rileyLinkErrorDescription = ex.getMessage();
aapsLogger.error(LTag.PUMPCOMM, "Error on Verification: " + ex.getMessage(), ex); aapsLogger.error(LTag.PUMPCOMM, "Error on Verification: " + ex.getMessage(), ex);
return false; return false;
} }

View file

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

View file

@ -41,7 +41,7 @@ class LocalAlertUtils @Inject constructor(
} }
fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) { fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) {
val alarmTimeoutExpired = lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis() val alarmTimeoutExpired = isAlarmTimeoutExpired(lastConnection, pumpUnreachableThreshold())
val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis() val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis()
if (Config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true) if (Config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) {
@ -57,6 +57,14 @@ class LocalAlertUtils @Inject constructor(
if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE))
} }
private fun isAlarmTimeoutExpired(lastConnection: Long, unreachableThreshold: Long): Boolean {
if (activePlugin.activePump.pumpDescription.hasCustomUnreachableAlertCheck) {
return activePlugin.activePump.isUnreachableAlertTimeoutExceeded(unreachableThreshold)
} else {
return lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis()
}
}
/*Presnoozes the alarms with 5 minutes if no snooze exists. /*Presnoozes the alarms with 5 minutes if no snooze exists.
* Call only at startup! * Call only at startup!
*/ */

View file

@ -575,7 +575,7 @@
android:layout_weight="1.5" android:layout_weight="1.5"
android:gravity="end" android:gravity="end"
android:paddingRight="5dp" android:paddingRight="5dp"
android:text="@string/medtronic_errors" android:text="@string/omnipod_errors"
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView

View file

@ -1864,10 +1864,11 @@
<string name="omnipod_pod_address">Pod Address</string> <string name="omnipod_pod_address">Pod Address</string>
<string name="omnipod_pod_expiry">Pod Expires</string> <string name="omnipod_pod_expiry">Pod Expires</string>
<string name="omnipod_pod_status_no_pod_connected">No Pod connected</string> <string name="omnipod_pod_status_no_pod_connected">No Pod connected</string>
<string name="omnipod_pod_setup_in_progress">Pod setup in progress</string> <string name="omnipod_pod_setup_in_progress">Pod setup in progress (setup progress: %1$s)</string>
<string name="omnipod_pod_status_not_initalized">Pod not initialized</string> <string name="omnipod_pod_status_not_initalized">Pod not initialized</string>
<string name="omnipod_pod_status_pod_fault">!!! Pod Fault</string> <string name="omnipod_pod_status_pod_fault">Pod Fault</string>
<string name="omnipod_pod_status_pod_running">Pod running</string> <string name="omnipod_pod_status_pod_fault_description">Pod Fault: %1$s %2$s</string>
<string name="omnipod_pod_status_pod_running">Pod running (last delivery status: %1$s)</string>
<string name="omnipod_pod_active_alerts">Active Pod Alerts</string> <string name="omnipod_pod_active_alerts">Active Pod Alerts</string>
<string name="omnipod_ack_short">Ack Alerts</string> <string name="omnipod_ack_short">Ack Alerts</string>
<string name="omnipod_last_bolus" translatable="false">%1$.2f %2$s (%3$s)</string> <string name="omnipod_last_bolus" translatable="false">%1$.2f %2$s (%3$s)</string>
@ -1881,6 +1882,7 @@
<!-- Omnipod - Error --> <!-- Omnipod - Error -->
<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_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_operation_not_possible_no_profile">Operation is not possible.\n\n You need to wait few minutes, until AAPS tries to set profile for first time.</string> <string name="omnipod_error_operation_not_possible_no_profile">Operation is not possible.\n\n You need to wait few minutes, until AAPS tries to set profile for first time.</string>
<string name="omnipod_error_illegal_init_action_type">Illegal PodInitActionType: %1$s</string> <string name="omnipod_error_illegal_init_action_type">Illegal PodInitActionType: %1$s</string>
@ -1987,5 +1989,6 @@
<string name="omnipod_pod_lot">LOT</string> <string name="omnipod_pod_lot">LOT</string>
<string name="omnipod_pod_tid">TID</string> <string name="omnipod_pod_tid">TID</string>
<string name="omnipod_pod_fw_version">PM / PI version</string> <string name="omnipod_pod_fw_version">PM / PI version</string>
<string name="omnipod_errors">Errors</string>
</resources> </resources>