Remove OmnipodUiComm and OmnipodUiTask
This commit is contained in:
parent
887a1672dc
commit
4a10a04f79
7 changed files with 117 additions and 336 deletions
|
@ -15,7 +15,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodI
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.RemoveActionFragment
|
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.RemoveActionFragment
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask
|
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@ -37,7 +36,6 @@ abstract class OmnipodModule {
|
||||||
@ContributesAndroidInjector abstract fun aapsOmnipodManagerProvider(): AapsOmnipodManager
|
@ContributesAndroidInjector abstract fun aapsOmnipodManagerProvider(): AapsOmnipodManager
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
@ContributesAndroidInjector abstract fun omnipodUITaskProvider(): OmnipodUITask
|
|
||||||
@ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction
|
@ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction
|
||||||
@ContributesAndroidInjector abstract fun podStateManager(): PodStateManager
|
@ContributesAndroidInjector abstract fun podStateManager(): PodStateManager
|
||||||
@ContributesAndroidInjector abstract fun initPodTask(): InitPodTask
|
@ContributesAndroidInjector abstract fun initPodTask(): InitPodTask
|
||||||
|
@ -45,6 +43,6 @@ abstract class OmnipodModule {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Provides
|
@Provides
|
||||||
fun podStateManagerProvider(aapsPodStateManager: AapsPodStateManager) : PodStateManager = aapsPodStateManager
|
fun podStateManagerProvider(aapsPodStateManager: AapsPodStateManager): PodStateManager = aapsPodStateManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -54,6 +55,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNo
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
|
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.events.EventRileyLinkDeviceStatusChange;
|
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
|
@ -65,15 +67,13 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
|
||||||
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.comm.AapsOmnipodManager;
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
||||||
|
@ -99,6 +99,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private final ServiceTaskExecutor serviceTaskExecutor;
|
private final ServiceTaskExecutor serviceTaskExecutor;
|
||||||
private final AapsOmnipodManager aapsOmnipodManager;
|
private final AapsOmnipodManager aapsOmnipodManager;
|
||||||
private final OmnipodUtil omnipodUtil;
|
private final OmnipodUtil omnipodUtil;
|
||||||
|
private final RileyLinkUtil rileyLinkUtil;
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final RxBusWrapper rxBus;
|
private final RxBusWrapper rxBus;
|
||||||
private final ActivePluginProvider activePlugin;
|
private final ActivePluginProvider activePlugin;
|
||||||
|
@ -110,7 +111,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private final PumpDescription pumpDescription;
|
private final PumpDescription pumpDescription;
|
||||||
private final ServiceConnection serviceConnection;
|
private final ServiceConnection serviceConnection;
|
||||||
private final PumpType pumpType = PumpType.Insulet_Omnipod;
|
private final PumpType pumpType = PumpType.Insulet_Omnipod;
|
||||||
private final OmnipodUIComm commandExecutor;
|
|
||||||
|
|
||||||
private final List<CustomAction> customActions = new ArrayList<>();
|
private final List<CustomAction> customActions = new ArrayList<>();
|
||||||
// TODO: BS: Not really sure what this is all about, have a closer look at it some time
|
// TODO: BS: Not really sure what this is all about, have a closer look at it some time
|
||||||
|
@ -169,14 +169,13 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
this.serviceTaskExecutor = serviceTaskExecutor;
|
this.serviceTaskExecutor = serviceTaskExecutor;
|
||||||
this.aapsOmnipodManager = aapsOmnipodManager;
|
this.aapsOmnipodManager = aapsOmnipodManager;
|
||||||
this.omnipodUtil = omnipodUtil;
|
this.omnipodUtil = omnipodUtil;
|
||||||
|
this.rileyLinkUtil = rileyLinkUtil;
|
||||||
|
|
||||||
pumpDescription = new PumpDescription(pumpType);
|
pumpDescription = new PumpDescription(pumpType);
|
||||||
|
|
||||||
customActions.add(new CustomAction(
|
customActions.add(new CustomAction(
|
||||||
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true));
|
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true));
|
||||||
|
|
||||||
commandExecutor = new OmnipodUIComm(injector, aapsLogger, aapsOmnipodManager, rileyLinkUtil, rxBus);
|
|
||||||
|
|
||||||
this.serviceConnection = new ServiceConnection() {
|
this.serviceConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
|
@ -346,30 +345,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return !podStateManager.isPodRunning() || podStateManager.isSuspended();
|
return !podStateManager.isPodRunning() || podStateManager.isSuspended();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finishHandshaking() {
|
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void connect(String reason) {
|
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void disconnect(String reason) {
|
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void stopConnecting() {
|
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void triggerPumpConfigurationChangedEvent() {
|
public void triggerPumpConfigurationChangedEvent() {
|
||||||
rxBus.send(new EventOmnipodPumpValuesChanged());
|
|
||||||
rxBus.send(new EventRileyLinkDeviceStatusChange());
|
rxBus.send(new EventRileyLinkDeviceStatusChange());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,36 +397,43 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
Iterator<OmnipodStatusRequest> iterator = omnipodStatusRequestList.iterator();
|
Iterator<OmnipodStatusRequest> iterator = omnipodStatusRequestList.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
OmnipodStatusRequest omnipodStatusRequest = iterator.next();
|
OmnipodStatusRequest statusRequest = iterator.next();
|
||||||
OmnipodUITask omnipodUITask;
|
switch (statusRequest) {
|
||||||
if (omnipodStatusRequest == OmnipodStatusRequest.GetPodPulseLog) {
|
case GetPodPulseLog:
|
||||||
omnipodUITask = commandExecutor.executeCommand(omnipodStatusRequest.getCommandType());
|
try {
|
||||||
|
PodInfoRecentPulseLog result = executeCommand(OmnipodCommandType.GetPodPulseLog, aapsOmnipodManager::readPulseLog);
|
||||||
PodInfoRecentPulseLog result = (PodInfoRecentPulseLog) omnipodUITask.returnDataObject;
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
|
i.putExtra("soundid", 0);
|
||||||
if (result == null) {
|
i.putExtra("status", "Pulse Log (copied to clipboard):\n" + result.toString());
|
||||||
aapsLogger.warn(LTag.PUMP, "Result was null.");
|
i.putExtra("title", resourceHelper.gs(R.string.omnipod_warning));
|
||||||
} else {
|
i.putExtra("clipboardContent", result.toString());
|
||||||
aapsLogger.warn(LTag.PUMP, "Result was NOT null.");
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(i);
|
||||||
Intent i = new Intent(context, ErrorHelperActivity.class);
|
} catch (Exception ex) {
|
||||||
i.putExtra("soundid", 0);
|
aapsLogger.warn(LTag.PUMP, "Failed to retrieve pulse log", ex);
|
||||||
i.putExtra("status", "Pulse Log (copied to clipboard):\n" + result.toString());
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
i.putExtra("title", resourceHelper.gs(R.string.omnipod_warning));
|
i.putExtra("soundid", 0);
|
||||||
i.putExtra("clipboardContent", result.toString());
|
i.putExtra("status", "Failed to retrieve pulse log");
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.putExtra("title", resourceHelper.gs(R.string.omnipod_warning));
|
||||||
context.startActivity(i);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
context.startActivity(i);
|
||||||
|
}
|
||||||
} else {
|
break;
|
||||||
commandExecutor.executeCommand(omnipodStatusRequest.getCommandType());
|
case AcknowledgeAlerts:
|
||||||
|
executeCommand(OmnipodCommandType.GetPodPulseLog, aapsOmnipodManager::acknowledgeAlerts);
|
||||||
|
break;
|
||||||
|
case GetPodState:
|
||||||
|
executeCommand(OmnipodCommandType.GetPodPulseLog, aapsOmnipodManager::getPodStatus);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
||||||
}
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
||||||
OmnipodUITask omnipodUITask = commandExecutor.executeCommand(OmnipodCommandType.SetTime);
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
||||||
|
|
||||||
if (omnipodUITask.wasCommandSuccessful()) {
|
if (result.success) {
|
||||||
this.hasTimeDateOrTimeZoneChanged = false;
|
this.hasTimeDateOrTimeZoneChanged = false;
|
||||||
timeChangeRetries = 0;
|
timeChangeRetries = 0;
|
||||||
|
|
||||||
|
@ -473,10 +457,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetBasalProfile,
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBasalProfile, () -> aapsOmnipodManager.setBasalProfile(profile));
|
||||||
profile);
|
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
|
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
|
||||||
|
|
||||||
|
@ -498,14 +479,14 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
if (!podStateManager.isPodActivationCompleted()) {
|
if (!podStateManager.isPodActivationCompleted()) {
|
||||||
return true; // Return true, because otherwise AAPS will try setting a Basal schedule while no Pod is active
|
return false;
|
||||||
}
|
}
|
||||||
return podStateManager.getBasalSchedule().equals(AapsOmnipodManager.mapProfileToBasalSchedule(profile));
|
return podStateManager.getBasalSchedule().equals(AapsOmnipodManager.mapProfileToBasalSchedule(profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
return lastConnectionTimeMillis;
|
return podStateManager.isPodActivationCompleted() ? podStateManager.getLastSuccessfulCommunication().getMillis() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -565,7 +546,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
commandExecutor.executeCommand(OmnipodCommandType.CancelBolus);
|
executeCommand(OmnipodCommandType.CancelBolus, aapsOmnipodManager::cancelBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
|
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
|
||||||
|
@ -591,11 +572,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now start new TBR
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTemporaryBasal, () -> aapsOmnipodManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes)));
|
||||||
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetTemporaryBasal,
|
|
||||||
absoluteRate, durationInMinutes);
|
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success);
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success);
|
||||||
|
|
||||||
|
@ -606,18 +583,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer
|
|
||||||
durationInMinutes, Profile profile, boolean enforceNew) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [OmnipodPumpPlugin] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer
|
|
||||||
durationInMinutes) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
TemporaryBasal tbrCurrent = readTBR();
|
TemporaryBasal tbrCurrent = readTBR();
|
||||||
|
@ -628,9 +593,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.CancelTemporaryBasal);
|
PumpEnactResult result = executeCommand(OmnipodCommandType.CancelTemporaryBasal, aapsOmnipodManager::cancelTemporaryBasal);
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// TODO is this necessary?
|
// TODO is this necessary?
|
||||||
|
@ -645,11 +608,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull @Override public PumpEnactResult cancelExtendedBolus() {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO improve (i8n and more)
|
// TODO improve (i8n and more)
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public JSONObject getJSONStatus(Profile profile, String profileName, String version) {
|
public JSONObject getJSONStatus(Profile profile, String profileName, String version) {
|
||||||
|
@ -751,20 +709,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull @Override public PumpEnactResult loadTDDs() {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "loadTDDs [OmnipodPumpPlugin] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean canHandleDST() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CustomAction> getCustomActions() {
|
public List<CustomAction> getCustomActions() {
|
||||||
return customActions;
|
return customActions;
|
||||||
|
@ -820,10 +764,62 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
omnipodStatusRequestList.add(pumpStatusRequest);
|
omnipodStatusRequestList.add(pumpStatusRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFakingTempsByExtendedBoluses() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean canHandleDST() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finishHandshaking() {
|
||||||
|
if (displayConnectionMessages)
|
||||||
|
aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void connect(String reason) {
|
||||||
|
if (displayConnectionMessages)
|
||||||
|
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void disconnect(String reason) {
|
||||||
|
if (displayConnectionMessages)
|
||||||
|
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void stopConnecting() {
|
||||||
|
if (displayConnectionMessages)
|
||||||
|
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer
|
||||||
|
durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [OmnipodPumpPlugin] - Not implemented.");
|
||||||
|
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer
|
||||||
|
durationInMinutes) {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
|
||||||
|
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull @Override public PumpEnactResult cancelExtendedBolus() {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
|
||||||
|
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull @Override public PumpEnactResult loadTDDs() {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "loadTDDs [OmnipodPumpPlugin] - Not implemented.");
|
||||||
|
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializePump() {
|
private void initializePump() {
|
||||||
if (podStateManager.isPodInitialized() && podStateManager.getPodProgressStatus().isAtLeast(PodProgressStatus.PAIRING_COMPLETED)) {
|
if (podStateManager.isPodInitialized() && podStateManager.getPodProgressStatus().isAtLeast(PodProgressStatus.PAIRING_COMPLETED)) {
|
||||||
OmnipodUITask omnipodUITask = commandExecutor.executeCommand(OmnipodCommandType.GetPodStatus);
|
PumpEnactResult result = executeCommand(OmnipodCommandType.GetPodStatus, aapsOmnipodManager::getPodStatus);
|
||||||
if (omnipodUITask.wasCommandSuccessful()) {
|
if (result.success) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Successfully retrieved Pod status on startup");
|
aapsLogger.debug(LTag.PUMP, "Successfully retrieved Pod status on startup");
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.warn(LTag.PUMP, "Failed to retrieve Pod status on startup");
|
aapsLogger.warn(LTag.PUMP, "Failed to retrieve Pod status on startup");
|
||||||
|
@ -846,10 +842,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
OmnipodUITask responseTask = commandExecutor.executeCommand(OmnipodCommandType.SetBolus,
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
||||||
detailedBolusInfo);
|
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses
|
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses
|
||||||
|
@ -861,6 +854,19 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T> T executeCommand(OmnipodCommandType commandType, Supplier<T> supplier) {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "Executing command: {}", commandType);
|
||||||
|
|
||||||
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
|
||||||
|
|
||||||
|
T pumpEnactResult = supplier.get();
|
||||||
|
|
||||||
|
// TODO maybe only do this for specific commands
|
||||||
|
rxBus.send(new EventRefreshOverview("Omnipod command: " + commandType.name(), false));
|
||||||
|
|
||||||
|
return pumpEnactResult;
|
||||||
|
}
|
||||||
|
|
||||||
private void incrementStatistics(String statsKey) {
|
private void incrementStatistics(String statsKey) {
|
||||||
long currentCount = sp.getLong(statsKey, 0L);
|
long currentCount = sp.getLong(statsKey, 0L);
|
||||||
currentCount++;
|
currentCount++;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public interface IOmnipodManager {
|
||||||
*
|
*
|
||||||
* @param detailedBolusInfo DetailedBolusInfo instance with amount and all other required data
|
* @param detailedBolusInfo DetailedBolusInfo instance with amount and all other required data
|
||||||
*/
|
*/
|
||||||
PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo);
|
PumpEnactResult bolus(DetailedBolusInfo detailedBolusInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel Bolus (if bolus is already stopped, return acknowledgment)
|
* Cancel Bolus (if bolus is already stopped, return acknowledgment)
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
|
package info.nightscout.androidaps.plugins.pump.omnipod.defs;
|
||||||
|
|
||||||
public enum OmnipodStatusRequest {
|
public enum OmnipodStatusRequest {
|
||||||
AcknowledgeAlerts(OmnipodCommandType.AcknowledgeAlerts), //
|
AcknowledgeAlerts,
|
||||||
GetPodState(OmnipodCommandType.GetPodStatus), //
|
GetPodState,
|
||||||
GetPodPulseLog(OmnipodCommandType.GetPodPulseLog);
|
GetPodPulseLog
|
||||||
|
|
||||||
private OmnipodCommandType commandType;
|
|
||||||
|
|
||||||
OmnipodStatusRequest(OmnipodCommandType commandType) {
|
|
||||||
this.commandType = commandType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OmnipodCommandType getCommandType() {
|
|
||||||
return commandType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult bolus(DetailedBolusInfo detailedBolusInfo) {
|
||||||
OmnipodManager.BolusCommandResult bolusCommandResult;
|
OmnipodManager.BolusCommandResult bolusCommandResult;
|
||||||
|
|
||||||
boolean beepsEnabled = detailedBolusInfo.isSMB ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
|
boolean beepsEnabled = detailedBolusInfo.isSMB ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by andy on 4.8.2019
|
|
||||||
*/
|
|
||||||
public class OmnipodUIComm {
|
|
||||||
|
|
||||||
private final HasAndroidInjector injector;
|
|
||||||
private final AAPSLogger aapsLogger;
|
|
||||||
private final IOmnipodManager omnipodManager;
|
|
||||||
private final RileyLinkUtil rileyLinkUtil;
|
|
||||||
private final RxBusWrapper rxBus;
|
|
||||||
|
|
||||||
public OmnipodUIComm(
|
|
||||||
HasAndroidInjector injector,
|
|
||||||
AAPSLogger aapsLogger,
|
|
||||||
IOmnipodManager omnipodManager,
|
|
||||||
RileyLinkUtil rileyLinkUtil,
|
|
||||||
RxBusWrapper rxBus
|
|
||||||
) {
|
|
||||||
this.injector = injector;
|
|
||||||
this.aapsLogger = aapsLogger;
|
|
||||||
this.omnipodManager = omnipodManager;
|
|
||||||
this.rileyLinkUtil = rileyLinkUtil;
|
|
||||||
this.rxBus = rxBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) {
|
|
||||||
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
|
|
||||||
|
|
||||||
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
|
|
||||||
|
|
||||||
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
|
|
||||||
|
|
||||||
task.execute(this.omnipodManager);
|
|
||||||
|
|
||||||
if (!task.isReceived()) {
|
|
||||||
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
|
|
||||||
}
|
|
||||||
|
|
||||||
rxBus.send(new EventRefreshOverview("Omnipod command: " + commandType.name(), false));
|
|
||||||
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,157 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by andy on 4.8.2019
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class OmnipodUITask {
|
|
||||||
@Inject AAPSLogger aapsLogger;
|
|
||||||
|
|
||||||
public OmnipodCommandType commandType;
|
|
||||||
public PumpEnactResult returnData;
|
|
||||||
private Object[] parameters;
|
|
||||||
public PodResponseType responseType;
|
|
||||||
public Object returnDataObject;
|
|
||||||
|
|
||||||
public OmnipodUITask(HasAndroidInjector injector, OmnipodCommandType commandType, Object... parameters) {
|
|
||||||
injector.androidInjector().inject(this);
|
|
||||||
this.commandType = commandType;
|
|
||||||
this.parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(IOmnipodManager communicationManager) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ In execute. {}", commandType);
|
|
||||||
|
|
||||||
switch (commandType) {
|
|
||||||
case PairAndPrimePod:
|
|
||||||
returnData = communicationManager.initPod((PodInitActionType) parameters[0], (PodInitReceiver) parameters[1], null);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FillCanulaAndSetBasalProfile:
|
|
||||||
returnData = communicationManager.initPod((PodInitActionType) parameters[0], (PodInitReceiver) parameters[1], (Profile) parameters[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DeactivatePod:
|
|
||||||
returnData = communicationManager.deactivatePod((PodInitReceiver) parameters[0]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ResetPodStatus:
|
|
||||||
returnData = communicationManager.resetPodStatus();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SetBasalProfile:
|
|
||||||
returnData = communicationManager.setBasalProfile((Profile) parameters[0]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SetBolus: {
|
|
||||||
DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo) parameters[0];
|
|
||||||
|
|
||||||
if (detailedBolusInfo != null)
|
|
||||||
returnData = communicationManager.setBolus(detailedBolusInfo);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GetPodPulseLog:
|
|
||||||
// This command is very error prone, so retry a few times if it fails
|
|
||||||
// Can take some time, but that's ok since this is a very specific feature for experts
|
|
||||||
// And will not be used by normal users
|
|
||||||
for (int i = 0; 3 > i; i++) {
|
|
||||||
try {
|
|
||||||
returnDataObject = communicationManager.readPulseLog();
|
|
||||||
responseType = PodResponseType.Acknowledgment;
|
|
||||||
break;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
{
|
|
||||||
aapsLogger.warn(LTag.PUMP, "Failed to retrieve pulse log", ex);
|
|
||||||
}
|
|
||||||
returnDataObject = null;
|
|
||||||
responseType = PodResponseType.Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GetPodStatus:
|
|
||||||
returnData = communicationManager.getPodStatus();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CancelBolus:
|
|
||||||
returnData = communicationManager.cancelBolus();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SetTemporaryBasal: {
|
|
||||||
TempBasalPair tbr = getTBRSettings();
|
|
||||||
if (tbr != null) {
|
|
||||||
returnData = communicationManager.setTemporaryBasal(tbr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CancelTemporaryBasal:
|
|
||||||
returnData = communicationManager.cancelTemporaryBasal();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AcknowledgeAlerts:
|
|
||||||
returnData = communicationManager.acknowledgeAlerts();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SetTime:
|
|
||||||
returnData = communicationManager.setTime();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: {
|
|
||||||
aapsLogger.warn(LTag.PUMP, "This commandType is not supported (yet) - {}.", commandType);
|
|
||||||
responseType = PodResponseType.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (returnData != null) {
|
|
||||||
responseType = returnData.success ? PodResponseType.Acknowledgment : PodResponseType.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private TempBasalPair getTBRSettings() {
|
|
||||||
return new TempBasalPair(getDoubleFromParameters(0), //
|
|
||||||
false, //
|
|
||||||
getIntegerFromParameters(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getDoubleFromParameters(int index) {
|
|
||||||
return (Double) parameters[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIntegerFromParameters(int index) {
|
|
||||||
return (Integer) parameters[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T getResult() {
|
|
||||||
return (T) returnData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReceived() {
|
|
||||||
return returnData != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean wasCommandSuccessful() {
|
|
||||||
if (returnData == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return returnData.success;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue