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 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

@ -33,6 +33,7 @@ public class RileyLinkServiceData {
boolean tuneUpDone = false;
public RileyLinkError rileyLinkError;
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
private long lastServiceStateChange = 0L;
public RileyLinkFirmwareVersion firmwareVersion;
public RileyLinkTargetFrequency rileyLinkTargetFrequency; // TODO this might not be correct place
@ -52,7 +53,8 @@ public class RileyLinkServiceData {
public byte[] pumpIDBytes;
@Inject
public RileyLinkServiceData() {}
public RileyLinkServiceData() {
}
public void setPumpID(String pumpId, byte[] pumpIdBytes) {
this.pumpID = pumpId;
@ -71,17 +73,22 @@ public class RileyLinkServiceData {
workWithServiceState(newState, errorCode, true);
}
public long getLastServiceStateChange() {
return lastServiceStateChange;
}
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
if (set) {
rileyLinkServiceState = newState;
lastServiceStateChange = System.currentTimeMillis();
this.rileyLinkError = errorCode;
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
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));
else {
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.schedulers.Schedulers
import kotlinx.android.synthetic.main.omnipod_fragment.*
import org.apache.commons.lang3.StringUtils
import javax.inject.Inject
class OmnipodFragment : DaggerFragment() {
@ -87,11 +88,6 @@ class OmnipodFragment : DaggerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
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 {
if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
startActivity(Intent(context, PodManagementActivity::class.java))
@ -147,10 +143,6 @@ class OmnipodFragment : DaggerFragment() {
}
omnipod_lastconnection.setTextColor(Color.WHITE)
setVisibilityOfPodDebugButton()
updateGUI()
}
override fun onResume() {
@ -181,6 +173,7 @@ class OmnipodFragment : DaggerFragment() {
.subscribe({
setVisibilityOfPodDebugButton()
}, { fabricPrivacy.logException(it) })
updateGUI()
}
fun setVisibilityOfPodDebugButton() {
@ -212,36 +205,29 @@ class OmnipodFragment : DaggerFragment() {
@Synchronized
private fun setDeviceStatus() {
//val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus()
// omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState,
// RileyLinkUtil.getServiceState()) as RileyLinkServiceState?
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
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.Omnipod))
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,
// RileyLinkUtil.getError()) as RileyLinkError?
omnipod_errors.text =
omnipodPumpStatus.rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod))
} ?: "-"
val driverState = omnipodUtil.getDriverState();
aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState)
val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
if (rileyLinkErrorInfo != null) {
errors.add(rileyLinkErrorInfo)
}
if (!podStateManager.hasState() || !podStateManager.isPaired) {
if (podStateManager.hasState()) {
@ -258,11 +244,8 @@ 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,26 +253,30 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_expiry.text = podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = podStateManager.address.toString()
var podDeviceState = omnipodPumpStatus.podDeviceState
val stateText: String
var stateText: String?
if(podStateManager.hasFaultEvent()) {
val faultEventCode = podStateManager.faultEvent.faultEventCode
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) {
stateText += " (last delivery status: " + podStateManager.lastDeliveryStatus.name + ")"
when {
podStateManager.hasFaultEvent() -> {
val faultEventCode = podStateManager.faultEvent.faultEventCode
stateText = resourceHelper.gs(R.string.omnipod_pod_status_pod_fault)
errors.add(resourceHelper.gs(R.string.omnipod_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
}
podStateManager.isSetupCompleted -> {
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.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()
if (status.toString() == "") {
omnipod_queue.visibility = View.GONE
@ -323,8 +310,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 +343,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)
@ -397,12 +386,11 @@ class OmnipodFragment : DaggerFragment() {
omnipod_lastconnection.setTextColor(Color.WHITE)
}
omnipod_errors.text = omnipodPumpStatus.errorInfo
updateAcknowledgeAlerts()
omnipod_refresh.isEnabled = omnipodPumpStatus.podAvailable
setVisibilityOfPodDebugButton()
omnipod_refresh.isEnabled = podStateManager.isPaired
}
private fun updateAcknowledgeAlerts() {

View file

@ -90,9 +90,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;
@ -112,6 +110,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;
@ -137,6 +136,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
SP sp,
OmnipodUtil omnipodUtil,
OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager,
CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy,
RileyLinkServiceData rileyLinkServiceData,
@ -152,7 +152,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;
@ -184,6 +184,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return plugin;
}
public PodStateManager getPodStateManager() {
return podStateManager;
}
@Override
protected void onStart() {
@ -404,7 +407,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (isServiceSet()) {
if (isBusy || !omnipodPumpStatus.podAvailable)
if (isBusy || !podStateManager.isSetupCompleted())
return true;
if (busyTimestamps.size() > 0) {
@ -493,19 +496,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
@ -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) {
rxBus.send(new EventOmnipodRefreshButtonState(enabled));
}
@ -1004,15 +998,19 @@ 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) {
// We exceeded the alert threshold, and our last connection failed
long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
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())) ||
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
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
}
}

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

@ -6,8 +6,6 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import net.danlew.android.joda.JodaTimeAndroid;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -79,7 +77,7 @@ public abstract class PodStateManager {
if (!hasState()) {
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");
}
if (piVersion == null) {
@ -125,11 +123,11 @@ public abstract class PodStateManager {
}
public final void increaseMessageNumber() {
setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111));
setAndStore(() -> podState.setMessageNumber((podState.getMessageNumber() + 1) & 0b1111), false);
}
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) {
@ -144,7 +142,7 @@ public abstract class PodStateManager {
int seed = ((sum & 0xFFFF) ^ syncWord);
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() {
@ -158,7 +156,7 @@ public abstract class PodStateManager {
if (!isPaired()) {
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() {
@ -178,7 +176,7 @@ public abstract class PodStateManager {
}
public final boolean hasFaultEvent() {
return getSafe(() -> podState.getFaultEvent()) != null;
return podState != null && podState.getFaultEvent() != null;
}
public final PodInfoFaultEvent getFaultEvent() {
@ -202,6 +200,9 @@ public abstract class PodStateManager {
}
public final boolean hasActiveAlerts() {
if (podState == null) {
return false;
}
AlertSet activeAlerts = podState.getActiveAlerts();
return activeAlerts != null && activeAlerts.size() > 0;
}
@ -358,12 +359,18 @@ public abstract class PodStateManager {
}
private void setAndStore(Runnable runnable) {
setAndStore(runnable, true);
}
private void setAndStore(Runnable runnable, boolean notifyPodStateChanged) {
if (!hasState()) {
throw new IllegalStateException("Cannot mutate PodState: podState is null");
}
runnable.run();
storePodState();
notifyPodStateChanged();
if (notifyPodStateChanged) {
notifyPodStateChanged();
}
}
private void storePodState() {
@ -483,12 +490,6 @@ public abstract class PodStateManager {
}
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;
}

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

@ -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.hw.rileylink.RileyLinkUtil;
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.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
@ -26,19 +24,19 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/
@Singleton
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 SP sp;
private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
public String errorDescription = null;
public String rileyLinkErrorDescription = null;
public String rileyLinkAddress = null;
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 +49,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;
@ -62,7 +57,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public boolean beepSMBEnabled = true;
public boolean beepTBREnabled = true;
public boolean podDebuggingOptionsEnabled = false;
public String podLotNumber = "???";
public boolean timeChangeEventEnabled = true;
public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@ -81,23 +75,19 @@ public class OmnipodPumpStatus extends PumpStatus {
initSettings();
}
@Override
public void initSettings() {
this.activeProfileName = "";
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;
}
// For Omnipod, this method only returns a RileyLink error description
@Override
public String getErrorInfo() {
//verifyConfiguration();
return (this.errorDescription == null) ? "-" : this.errorDescription;
return this.rileyLinkErrorDescription;
}
@ -130,11 +120,9 @@ public class OmnipodPumpStatus extends PumpStatus {
@Override
public String toString() {
return "OmnipodPumpStatus{" +
"errorDescription='" + errorDescription + '\'' +
"rileyLinkErrorDescription='" + rileyLinkErrorDescription + '\'' +
", rileyLinkAddress='" + rileyLinkAddress + '\'' +
", inPreInit=" + inPreInit +
", rileyLinkServiceState=" + rileyLinkServiceState +
", rileyLinkError=" + rileyLinkError +
", currentBasal=" + currentBasal +
", tempBasalStart=" + tempBasalStart +
", tempBasalEnd=" + tempBasalEnd +
@ -143,7 +131,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

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

View file

@ -5,4 +5,5 @@ import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
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
*/
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodDeviceStatusChange : Event {
var rileyLinkServiceState: RileyLinkServiceState? = null

View file

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

View file

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

View file

@ -41,7 +41,7 @@ class LocalAlertUtils @Inject constructor(
}
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()
if (Config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) {
@ -57,6 +57,14 @@ class LocalAlertUtils @Inject constructor(
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.
* Call only at startup!
*/

View file

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

View file

@ -1864,10 +1864,11 @@
<string name="omnipod_pod_address">Pod Address</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_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_pod_fault">!!! Pod Fault</string>
<string name="omnipod_pod_status_pod_running">Pod running</string>
<string name="omnipod_pod_status_pod_fault">Pod Fault</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_ack_short">Ack Alerts</string>
<string name="omnipod_last_bolus" translatable="false">%1$.2f %2$s (%3$s)</string>
@ -1881,6 +1882,7 @@
<!-- 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_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>
@ -1987,5 +1989,6 @@
<string name="omnipod_pod_lot">LOT</string>
<string name="omnipod_pod_tid">TID</string>
<string name="omnipod_pod_fw_version">PM / PI version</string>
<string name="omnipod_errors">Errors</string>
</resources>