Get rid of OmnipodPumpStatus in OmnipodFragment, OmnipodCommunicationManager, RileyLinkOmnipodService + some cleanup along the way
This commit is contained in:
parent
0ef4099eaf
commit
0dab8965b4
5 changed files with 51 additions and 111 deletions
|
@ -12,8 +12,6 @@ import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
|
||||||
import info.nightscout.androidaps.logging.LTag
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
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.defs.RileyLinkServiceState
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
|
||||||
|
@ -24,12 +22,10 @@ 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.dialogs.PodManagementActivity
|
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus
|
|
||||||
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.events.EventOmnipodAcknowledgeAlertsChanged
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged
|
||||||
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.events.EventOmnipodRefreshButtonState
|
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState
|
||||||
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
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
@ -53,7 +49,6 @@ import javax.inject.Inject
|
||||||
|
|
||||||
class OmnipodFragment : DaggerFragment() {
|
class OmnipodFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
|
@ -61,7 +56,6 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||||
@Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin
|
@Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin
|
||||||
@Inject lateinit var warnColors: WarnColors
|
@Inject lateinit var warnColors: WarnColors
|
||||||
@Inject lateinit var omnipodPumpStatus: OmnipodPumpStatus
|
|
||||||
@Inject lateinit var podStateManager: PodStateManager
|
@Inject lateinit var podStateManager: PodStateManager
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
@Inject lateinit var omnipodUtil: OmnipodUtil
|
@Inject lateinit var omnipodUtil: OmnipodUtil
|
||||||
|
@ -211,8 +205,6 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun updateRileyLinkUiElements() {
|
private fun updateRileyLinkUiElements() {
|
||||||
aapsLogger.info(LTag.PUMP, "OmnipodFragment.setDeviceStatus")
|
|
||||||
|
|
||||||
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
|
val rileyLinkServiceState = rileyLinkServiceData.rileyLinkServiceState
|
||||||
|
|
||||||
val resourceId = rileyLinkServiceState.getResourceId()
|
val resourceId = rileyLinkServiceState.getResourceId()
|
||||||
|
@ -235,9 +227,9 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
setVisibilityOfPodDebugButton()
|
setVisibilityOfPodDebugButton()
|
||||||
|
|
||||||
val errors = ArrayList<String>();
|
val errors = ArrayList<String>();
|
||||||
val rileyLinkErrorInfo = omnipodPumpStatus.errorInfo
|
val rileyLinkErrorDescription = omnipodPumpPlugin.rileyLinkService.errorDescription
|
||||||
if (rileyLinkErrorInfo != null) {
|
if (StringUtils.isNotEmpty(rileyLinkErrorDescription)) {
|
||||||
errors.add(rileyLinkErrorInfo)
|
errors.add(rileyLinkErrorDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!podStateManager.hasPodState() || !podStateManager.isPodInitialized) {
|
if (!podStateManager.hasPodState() || !podStateManager.isPodInitialized) {
|
||||||
|
|
|
@ -112,9 +112,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private final DateUtil dateUtil;
|
private final DateUtil dateUtil;
|
||||||
private final PumpDescription pumpDescription;
|
private final PumpDescription pumpDescription;
|
||||||
private final ServiceConnection serviceConnection;
|
private final ServiceConnection serviceConnection;
|
||||||
private final PumpType pumpType = PumpType.Insulet_Omnipod; // FIXME
|
private final PumpType pumpType = PumpType.Insulet_Omnipod;
|
||||||
|
|
||||||
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
|
||||||
private final List<OmnipodStatusRequest> omnipodStatusRequestList = new ArrayList<>();
|
private final List<OmnipodStatusRequest> omnipodStatusRequestList = new ArrayList<>();
|
||||||
private final CompositeDisposable disposables = new CompositeDisposable();
|
private final CompositeDisposable disposables = new CompositeDisposable();
|
||||||
|
|
||||||
|
@ -127,10 +128,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private boolean isInitialized = false;
|
private boolean isInitialized = false;
|
||||||
private RileyLinkOmnipodService rileyLinkOmnipodService;
|
private RileyLinkOmnipodService rileyLinkOmnipodService;
|
||||||
private boolean busy = false;
|
private boolean busy = false;
|
||||||
private int timeChangeRetries = 0;
|
private int timeChangeRetries;
|
||||||
private Profile currentProfile;
|
private Profile currentProfile;
|
||||||
private long nextPodCheck = 0L;
|
private long nextPodCheck;
|
||||||
private boolean sentIdToFirebase;
|
private boolean sentIdToFirebase;
|
||||||
|
private long lastConnectionMillis;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OmnipodPumpPlugin(
|
public OmnipodPumpPlugin(
|
||||||
|
@ -180,7 +182,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true));
|
R.string.omnipod_custom_action_reset_rileylink, OmnipodCustomActionType.ResetRileyLinkConfiguration, true));
|
||||||
|
|
||||||
this.serviceConnection = new ServiceConnection() {
|
this.serviceConnection = new ServiceConnection() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected");
|
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected");
|
||||||
|
@ -219,10 +220,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
// We can't do this in PodStateManager itself, because JodaTimeAndroid.init() hasn't been called yet
|
// We can't do this in PodStateManager itself, because JodaTimeAndroid.init() hasn't been called yet
|
||||||
// When PodStateManager is created, which causes an IllegalArgumentException for DateTimeZones not being recognized
|
// When PodStateManager is created, which causes an IllegalArgumentException for DateTimeZones not being recognized
|
||||||
// TODO either find a more elegant solution, or at least make sure this is the right place to do this
|
|
||||||
podStateManager.loadPodState();
|
podStateManager.loadPodState();
|
||||||
|
|
||||||
initPumpStatusData();
|
lastConnectionMillis = sp.getLong(
|
||||||
|
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||||
|
|
||||||
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
||||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
@ -298,19 +299,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
disposables.clear();
|
disposables.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLogPrefix() {
|
|
||||||
return "OmnipodPlugin::";
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME remove
|
|
||||||
public void initPumpStatusData() {
|
|
||||||
omnipodPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
|
||||||
omnipodPumpStatus.lastDataTime = omnipodPumpStatus.lastConnection;
|
|
||||||
omnipodPumpStatus.previousConnection = omnipodPumpStatus.lastConnection;
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.omnipodPumpStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doPodCheck() {
|
private void doPodCheck() {
|
||||||
if (System.currentTimeMillis() > this.nextPodCheck) {
|
if (System.currentTimeMillis() > this.nextPodCheck) {
|
||||||
if (!podStateManager.isPodRunning()) {
|
if (!podStateManager.isPodRunning()) {
|
||||||
|
@ -334,8 +322,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isInitialized");
|
|
||||||
return isServiceSet() && isInitialized;
|
return isServiceSet() && isInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,9 +332,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBusy() {
|
public boolean isBusy() {
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isBusy");
|
|
||||||
|
|
||||||
if (isServiceSet()) {
|
if (isServiceSet()) {
|
||||||
return busy || !podStateManager.isPodRunning();
|
return busy || !podStateManager.isPodRunning();
|
||||||
}
|
}
|
||||||
|
@ -379,17 +362,25 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return new RileyLinkPumpInfo(pumpDescription, frequency, connectedModel, serialNumber);
|
return new RileyLinkPumpInfo(pumpDescription, frequency, connectedModel, serialNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by RileyLinkPumpDevice interface.
|
||||||
|
// Kind of redundant because we also store last successful and last failed communication in PodStateManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last successful RileyLink communication
|
* Get the last communication time with the Pod. In the current implementation, this
|
||||||
* For actual communication with the Pod, we use PodStateManager
|
* doesn't have to mean that a command was successfully executed as the Pod could also return an ErrorResponse or PodFaultEvent
|
||||||
|
* For getting the last time a command was successfully executed, use PodStateManager.getLastSuccessfulCommunication
|
||||||
*/
|
*/
|
||||||
@Override public long getLastConnectionTimeMillis() {
|
@Override public long getLastConnectionTimeMillis() {
|
||||||
return omnipodPumpStatus.lastConnection;
|
return omnipodPumpStatus.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Required by RileyLinkPumpDevice interface.
|
||||||
|
// Kind of redundant because we also store last successful and last failed communication in PodStateManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only use for setting last successful RileyLink communication to now
|
* Set the last communication time with the Pod to now. In the current implementation, this
|
||||||
* For actual communication with the Pod, we use PodStateManager
|
* doesn't have to mean that a command was successfully executed as the Pod could also return an ErrorResponse or PodFaultEvent
|
||||||
|
* For setting the last time a command was successfully executed, use PodStateManager.setLastSuccessfulCommunication
|
||||||
*/
|
*/
|
||||||
@Override public void setLastCommunicationToNow() {
|
@Override public void setLastCommunicationToNow() {
|
||||||
omnipodPumpStatus.setLastCommunicationToNow();
|
omnipodPumpStatus.setLastCommunicationToNow();
|
||||||
|
@ -397,15 +388,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isConnected");
|
|
||||||
return isServiceSet() && rileyLinkOmnipodService.isInitialized();
|
return isServiceSet() && rileyLinkOmnipodService.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
if (displayConnectionMessages)
|
|
||||||
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isConnecting");
|
|
||||||
return !isServiceSet() || !rileyLinkOmnipodService.isInitialized();
|
return !isServiceSet() || !rileyLinkOmnipodService.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,6 +424,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO seems that this abused to squeeze commands in the queue
|
||||||
|
// Look for an alternative
|
||||||
@Override
|
@Override
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
|
@ -501,8 +490,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setNewBasalProfile");
|
|
||||||
|
|
||||||
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
|
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
|
||||||
if (this.currentProfile != null && this.currentProfile.areProfileBasalPatternsSame(profile)) {
|
if (this.currentProfile != null && this.currentProfile.areProfileBasalPatternsSame(profile)) {
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
|
@ -518,7 +505,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
PumpEnactResult result = responseTask.getResult();
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Basal Profile was set: " + result.success);
|
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
this.currentProfile = profile;
|
this.currentProfile = profile;
|
||||||
|
@ -551,11 +538,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
if (omnipodPumpStatus.lastConnection != 0) {
|
return lastConnectionMillis;
|
||||||
return omnipodPumpStatus.lastConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -612,19 +595,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "stopBolusDelivering");
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelBolus);
|
getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelBolus);
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
setRefreshButtonEnabled(true);
|
||||||
|
|
||||||
//setRefreshButtonEnabled(true);
|
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "stopBolusDelivering - wasSuccess={}", result.success);
|
|
||||||
|
|
||||||
//finishAction("Bolus");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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),
|
||||||
|
@ -633,19 +608,19 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
|
||||||
|
|
||||||
// read current TBR
|
// read current TBR
|
||||||
TempBasalPair tbrCurrent = readTBR();
|
TempBasalPair tbrCurrent = readTBR();
|
||||||
|
|
||||||
if (tbrCurrent != null) {
|
if (tbrCurrent != null) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
|
||||||
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
|
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tbrCurrent != null && !enforceNew) {
|
if (tbrCurrent != null && !enforceNew) {
|
||||||
if (Round.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
|
if (Round.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
@ -657,7 +632,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
PumpEnactResult result = responseTask.getResult();
|
PumpEnactResult result = responseTask.getResult();
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success);
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
incrementStatistics(OmnipodConst.Statistics.TBRsSet);
|
incrementStatistics(OmnipodConst.Statistics.TBRsSet);
|
||||||
|
@ -679,14 +654,12 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - started");
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
TempBasalPair tbrCurrent = readTBR();
|
TempBasalPair tbrCurrent = readTBR();
|
||||||
|
|
||||||
if (tbrCurrent == null) {
|
if (tbrCurrent == null) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - TBR already canceled.");
|
aapsLogger.info(LTag.PUMP, "cancelTempBasal - TBR already canceled.");
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
@ -698,16 +671,13 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR successful.");
|
// TODO is this necessary?
|
||||||
|
TemporaryBasal tempBasal = new TemporaryBasal(getInjector()) //
|
||||||
TemporaryBasal tempBasal = new TemporaryBasal() //
|
|
||||||
.date(System.currentTimeMillis()) //
|
.date(System.currentTimeMillis()) //
|
||||||
.duration(0) //
|
.duration(0) //
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
|
|
||||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
||||||
} else {
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -849,10 +819,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
|
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
|
||||||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]");
|
aapsLogger.warn(LTag.PUMP, "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]");
|
||||||
|
|
||||||
if (aapsOmnipodManager.isTimeChangeEventEnabled() && podStateManager.isPodRunning()) {
|
if (aapsOmnipodManager.isTimeChangeEventEnabled() && podStateManager.isPodRunning()) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Time,and/or TimeZone changed event received and will be consumed by driver.");
|
aapsLogger.info(LTag.PUMP, "Time, Date and/or TimeZone changed event received and will be consumed by driver.");
|
||||||
this.hasTimeDateOrTimeZoneChanged = true;
|
this.hasTimeDateOrTimeZoneChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -906,8 +876,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializePump(boolean realInit) {
|
private void initializePump(boolean realInit) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
if (podStateManager.isPodInitialized()) {
|
if (podStateManager.isPodInitialized()) {
|
||||||
|
@ -940,8 +908,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "deliverBolus - {}", detailedBolusInfo);
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -9,10 +9,8 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
|
||||||
|
@ -41,7 +39,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
|
||||||
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.exception.OmnipodException;
|
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||||
|
|
||||||
|
@ -51,25 +48,11 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||||
// TODO rename to OmnipodRileyLinkCommunicationManager
|
// TODO rename to OmnipodRileyLinkCommunicationManager
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
||||||
|
|
||||||
@Inject OmnipodPumpStatus omnipodPumpStatus;
|
|
||||||
|
|
||||||
// This empty constructor must be kept, otherwise dagger injection might break!
|
// This empty constructor must be kept, otherwise dagger injection might break!
|
||||||
@Inject
|
@Inject
|
||||||
public OmnipodCommunicationManager() {
|
public OmnipodCommunicationManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void onInit() {
|
|
||||||
// this cannot be done in the constructor, as sp is not populated at that time
|
|
||||||
omnipodPumpStatus.previousConnection = sp.getLong(
|
|
||||||
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// protected void configurePumpSpecificSettings() {
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tryToConnectToDevice() {
|
public boolean tryToConnectToDevice() {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
@ -22,8 +22,6 @@ public class OmnipodPumpStatus extends PumpStatus {
|
||||||
|
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
|
|
||||||
public String rileyLinkErrorDescription = null;
|
|
||||||
public String rileyLinkAddress = null;
|
|
||||||
public boolean inPreInit = true;
|
public boolean inPreInit = true;
|
||||||
|
|
||||||
// statuses
|
// statuses
|
||||||
|
@ -51,10 +49,9 @@ public class OmnipodPumpStatus extends PumpStatus {
|
||||||
this.pumpType = PumpType.Insulet_Omnipod;
|
this.pumpType = PumpType.Insulet_Omnipod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Omnipod, this method only returns a RileyLink error description
|
|
||||||
@Override
|
@Override
|
||||||
public String getErrorInfo() {
|
public String getErrorInfo() {
|
||||||
return this.rileyLinkErrorDescription;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTemporaryBasal() {
|
public void clearTemporaryBasal() {
|
||||||
|
@ -78,9 +75,7 @@ public class OmnipodPumpStatus extends PumpStatus {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OmnipodPumpStatus{" +
|
return "OmnipodPumpStatus{" +
|
||||||
"rileyLinkErrorDescription='" + rileyLinkErrorDescription + '\'' +
|
"inPreInit=" + inPreInit +
|
||||||
", rileyLinkAddress='" + rileyLinkAddress + '\'' +
|
|
||||||
", inPreInit=" + inPreInit +
|
|
||||||
", tempBasalStart=" + tempBasalStart +
|
", tempBasalStart=" + tempBasalStart +
|
||||||
", tempBasalEnd=" + tempBasalEnd +
|
", tempBasalEnd=" + tempBasalEnd +
|
||||||
", tempBasalAmount=" + tempBasalAmount +
|
", tempBasalAmount=" + tempBasalAmount +
|
||||||
|
|
|
@ -22,7 +22,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.R;
|
import info.nightscout.androidaps.plugins.pump.omnipod.R;
|
||||||
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.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.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.OmnipodUIComm;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
|
||||||
|
@ -39,7 +38,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
private static final String REGEX_MAC = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
private static final String REGEX_MAC = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
||||||
|
|
||||||
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
|
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
|
||||||
@Inject OmnipodPumpStatus omnipodPumpStatus;
|
|
||||||
@Inject OmnipodUtil omnipodUtil;
|
@Inject OmnipodUtil omnipodUtil;
|
||||||
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
|
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
|
||||||
@Inject PodStateManager podStateManager;
|
@Inject PodStateManager podStateManager;
|
||||||
|
@ -50,6 +48,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
private boolean rileyLinkAddressChanged = false;
|
private boolean rileyLinkAddressChanged = false;
|
||||||
private boolean inPreInit = true;
|
private boolean inPreInit = true;
|
||||||
|
private String rileyLinkAddress;
|
||||||
|
private String errorDescription;
|
||||||
|
|
||||||
OmnipodUIComm omnipodUIComm;
|
OmnipodUIComm omnipodUIComm;
|
||||||
|
|
||||||
|
@ -115,6 +115,10 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
// We don't use PumpDeviceState in the Omnipod driver
|
// We don't use PumpDeviceState in the Omnipod driver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getErrorDescription() {
|
||||||
|
return errorDescription;
|
||||||
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
public RileyLinkOmnipodService getServiceInstance() {
|
public RileyLinkOmnipodService getServiceInstance() {
|
||||||
return RileyLinkOmnipodService.this;
|
return RileyLinkOmnipodService.this;
|
||||||
|
@ -132,21 +136,21 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
@Override
|
@Override
|
||||||
public boolean verifyConfiguration() {
|
public boolean verifyConfiguration() {
|
||||||
try {
|
try {
|
||||||
omnipodPumpStatus.rileyLinkErrorDescription = null;
|
errorDescription = 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.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
|
errorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!rileyLinkAddress.matches(REGEX_MAC)) {
|
if (!rileyLinkAddress.matches(REGEX_MAC)) {
|
||||||
omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
|
errorDescription = 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.rileyLinkAddress)) {
|
||||||
this.omnipodPumpStatus.rileyLinkAddress = rileyLinkAddress;
|
this.rileyLinkAddress = rileyLinkAddress;
|
||||||
rileyLinkAddressChanged = true;
|
rileyLinkAddressChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +163,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
this.omnipodPumpStatus.rileyLinkErrorDescription = ex.getMessage();
|
errorDescription = 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue