Remove OmnipodCommunicationManager, make OmnipodManager implement OmnipodCommunicationManagerInterface

This commit is contained in:
Bart Sopers 2019-08-29 01:07:28 +02:00
parent 75ae6844f3
commit 78f402a367
13 changed files with 221 additions and 316 deletions

View file

@ -11,6 +11,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.BolusAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.BolusAction;
@ -27,21 +28,28 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.Inser
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PairService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PairService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTempBasalService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.SetTempBasalService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfo; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfo;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
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.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleMapper; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleMapper;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
public class OmnipodManager { public class OmnipodManager implements OmnipodCommunicationManagerInterface {
private final OmnipodCommunicationService communicationService; private final OmnipodCommunicationService communicationService;
private PodSessionState podState; private PodSessionState podState;
private static OmnipodManager instance;
// FIXME this is dirty
public static OmnipodManager getInstance() {
return instance;
}
public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) { public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) {
if (communicationService == null) { if (communicationService == null) {
@ -49,55 +57,15 @@ public class OmnipodManager {
} }
this.communicationService = communicationService; this.communicationService = communicationService;
this.podState = podState; this.podState = podState;
instance = this;
} }
public OmnipodManager(OmnipodCommunicationService communicationService) { public OmnipodManager(OmnipodCommunicationService communicationService) {
this(communicationService, null); this(communicationService, null);
} }
public OmnipodCommunicationService getCommunicationService() { @Override
return communicationService; public PodCommResponse insertCannula(Profile profile) {
}
public <T extends PodInfo> T getPodInfo(PodInfoType podInfoType) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, podInfoType));
return podInfoResponse.getPodInfo();
}
public StatusResponse getStatus() {
if (podState == null) {
throw new IllegalStateException("Pod should be paired first");
}
return communicationService.executeAction(new GetStatusAction(podState));
}
public void acknowledgeAlerts() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()));
}
public void pairAndPrime() {
if (podState == null) {
podState = communicationService.executeAction(new PairAction(new PairService()));
}
if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
communicationService.executeAction(new PrimeAction(new PrimeService(), podState));
executeDelayed(() -> {
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
PrimeAction.updatePrimingStatus(podState, delayedStatusResponse);
}, OmnipodConst.POD_PRIME_DURATION);
} else {
throw new IllegalStateException("Illegal setup state: " + podState.getSetupProgress().name());
}
}
public void insertCannula(Profile profile) {
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) { if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
throw new IllegalArgumentException("Pod should be paired and primed first"); throw new IllegalArgumentException("Pod should be paired and primed first");
} else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) { } else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
@ -111,45 +79,131 @@ public class OmnipodManager {
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState)); StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
InsertCannulaAction.updateCannulaInsertionStatus(podState, delayedStatusResponse); InsertCannulaAction.updateCannulaInsertionStatus(podState, delayedStatusResponse);
}, OmnipodConst.POD_CANNULA_INSERTION_DURATION); }, OmnipodConst.POD_CANNULA_INSERTION_DURATION);
return null; // TODO
} }
public void setBasalSchedule(BasalSchedule basalSchedule, boolean confidenceReminder) { @Override
if (!isInitialized()) { public PodCommResponse pairAndPrime() {
throw new IllegalStateException("Pod should be initialized first"); if (podState == null) {
podState = communicationService.executeAction(new PairAction(new PairService()));
} }
communicationService.executeAction(new SetBasalScheduleAction(podState, basalSchedule, if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
confidenceReminder, podState.getScheduleOffset(), true)); communicationService.executeAction(new PrimeAction(new PrimeService(), podState));
executeDelayed(() -> {
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
PrimeAction.updatePrimingStatus(podState, delayedStatusResponse);
}, OmnipodConst.POD_PRIME_DURATION);
} else {
throw new IllegalStateException("Illegal setup state: " + podState.getSetupProgress().name());
} }
public void setTempBasal(double rate, Duration duration) { return null; // TODO
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
podState, rate, duration, true, true));
} }
public void cancelTempBasal() { @Override
if (!isInitialized()) { public PodCommResponse cancelBolus() {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true));
}
public void bolus(double units) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new BolusAction(podState, units, true, true));
}
public void cancelBolus() {
if (!isInitialized()) { if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first"); throw new IllegalStateException("Pod should be initialized first");
} }
communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true)); communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true));
return null; // TODO
} }
@Override
public PodCommResponse getPodStatus() {
if (podState == null) {
throw new IllegalStateException("Pod should be paired first");
}
// return communicationService.executeAction(new GetStatusAction(podState));
return null; // TODO
}
@Override
public PodCommResponse deactivatePod() {
if (podState == null) {
throw new IllegalStateException("Pod should be paired first");
}
communicationService.executeAction(new DeactivatePodAction(podState, true));
resetPodState();
return null; // TODO
}
@Override
public PodCommResponse setBasalProfile(Profile basalProfile) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new SetBasalScheduleAction(podState,
BasalScheduleMapper.mapProfileToBasalSchedule(basalProfile),
false, podState.getScheduleOffset(), true));
return null; // TODO
}
@Override
public PodCommResponse resetPodState() {
podState = null;
SP.remove(OmnipodConst.Prefs.PodState);
return null; // TODO
}
@Override
public PodCommResponse bolus(Double units) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new BolusAction(podState, units, true, true));
return null; // TODO
}
@Override
public PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()),
true, true));
return null; // TODO
}
@Override
public PodCommResponse cancelTemporaryBasal() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true));
return null; // TODO
}
@Override
public PodCommResponse acknowledgeAlerts() {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()));
return null; // TODO
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public <T extends PodInfo> T getPodInfo(PodInfoType podInfoType) {
if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first");
}
PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, podInfoType));
return podInfoResponse.getPodInfo();
}
// TODO should we add this to the OmnipodCommunicationManager interface?
public void suspendDelivery() { public void suspendDelivery() {
if (!isInitialized()) { if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first"); throw new IllegalStateException("Pod should be initialized first");
@ -157,6 +211,7 @@ public class OmnipodManager {
communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true)); communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true));
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public void resumeDelivery() { public void resumeDelivery() {
if (!isInitialized()) { if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first"); throw new IllegalStateException("Pod should be initialized first");
@ -165,6 +220,7 @@ public class OmnipodManager {
true, podState.getScheduleOffset(), true)); true, podState.getScheduleOffset(), true));
} }
// TODO should we add this to the OmnipodCommunicationManager interface?
public void setTime() { public void setTime() {
if (!isInitialized()) { if (!isInitialized()) {
throw new IllegalStateException("Pod should be initialized first"); throw new IllegalStateException("Pod should be initialized first");
@ -181,16 +237,12 @@ public class OmnipodManager {
true, podState.getScheduleOffset(), true)); true, podState.getScheduleOffset(), true));
} }
public DateTime getTime() { public OmnipodCommunicationService getCommunicationService() {
return podState.getTime(); return communicationService;
} }
public void deactivatePod() { public DateTime getTime() {
if (podState == null) { return podState.getTime();
throw new IllegalStateException("Pod should be paired first");
}
communicationService.executeAction(new DeactivatePodAction(podState, true));
resetPodState();
} }
public boolean isInitialized() { public boolean isInitialized() {
@ -201,11 +253,6 @@ public class OmnipodManager {
return podState == null ? "null" : podState.toString(); return podState == null ? "null" : podState.toString();
} }
public void resetPodState() {
podState = null;
SP.remove(OmnipodConst.Prefs.PodState);
}
private void executeDelayed(Runnable r, Duration timeout) { private void executeDelayed(Runnable r, Duration timeout) {
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS); scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);

View file

@ -43,7 +43,6 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
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.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm; import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUITask; import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUITask;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
@ -105,7 +104,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
displayConnectionMessages = false; displayConnectionMessages = false;
if (omnipodCommunicationManager == null) { if (omnipodCommunicationManager == null) {
omnipodCommunicationManager = OmnipodCommunicationManager.getInstance(); omnipodCommunicationManager = OmnipodManager.getInstance();
} }
omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager); omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager);

View file

@ -1,144 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm;
import android.content.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
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.RFSpy;
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.omnipod.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.data.PodCommResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.SP;
/**
* Created by andy on 4.8.2019
*/
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager implements OmnipodCommunicationManagerInterface {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
private static OmnipodCommunicationManager omnipodCommunicationManager;
String errorMessage;
OmnipodCommunicationService communicationService;
OmnipodManager omnipodManager;
public OmnipodCommunicationManager(Context context, RFSpy rfspy) {
super(rfspy);
omnipodCommunicationManager = this;
OmnipodUtil.getPumpStatus().previousConnection = SP.getLong(
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
communicationService = new OmnipodCommunicationService(this);
omnipodManager = new OmnipodManager(communicationService, getPodSessionState());
}
private PodSessionState getPodSessionState() {
return null;
}
public static OmnipodCommunicationManager getInstance() {
return omnipodCommunicationManager;
}
@Override
protected void configurePumpSpecificSettings() {
pumpStatus = OmnipodUtil.getPumpStatus();
}
@Override
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
// TODO
//PumpMessage pumpMessage = new PumpMessage(payload);
//eturn (E) pumpMessage;
return null;
}
@Override
public boolean tryToConnectToDevice() {
return false; //isDeviceReachable(true);
}
public String getErrorResponse() {
return this.errorMessage;
}
@Override
public byte[] createPumpMessageContent(RLMessageType type) {
return new byte[0];
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPCOMM);
}
// This are just skeleton methods, we need to see what we can get returned and act accordingly
public PodCommResponse initPod() {
omnipodManager.pairAndPrime();
return null;
}
public PodCommResponse getPodStatus() {
return null;
}
public PodCommResponse deactivatePod() {
return null;
}
public PodCommResponse setBasalProfile(Profile profile) {
return null;
}
public PodCommResponse resetPodStatus() {
return null;
}
public PodCommResponse setBolus(Double parameter) {
return null;
}
public PodCommResponse cancelBolus() {
return null;
}
public PodCommResponse setTemporaryBasal(TempBasalPair tbr) {
return null;
}
public PodCommResponse cancelTemporaryBasal() {
return null;
}
@Override
public PodCommResponse acknowledgeAlerts() {
return null;
}
}

View file

@ -35,33 +35,30 @@ import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodReturnedErro
* Created by andy on 6/29/18. * Created by andy on 6/29/18.
*/ */
public class OmnipodCommunicationService /*extends RileyLinkCommunicationManager*/ { public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
private static final Logger LOG = LoggerFactory.getLogger(OmnipodCommunicationService.class); private static final Logger LOG = LoggerFactory.getLogger(OmnipodCommunicationService.class);
//RFSpy rfspy = null;
OmnipodCommunicationManager communicationManager;
public OmnipodCommunicationService(OmnipodCommunicationManager communicationManager) { public OmnipodCommunicationService(RFSpy rfspy) {
//this.rfspy = rfspy; super(rfspy);
this.communicationManager = communicationManager;
} }
// @Override @Override
// protected void configurePumpSpecificSettings() { protected void configurePumpSpecificSettings() {
// } }
//
// @Override
// public boolean tryToConnectToDevice() {
// // TODO
// return false;
// }
//
// @Override
// public byte[] createPumpMessageContent(RLMessageType type) {
// return new byte[0];
// }
//@Override @Override
public boolean tryToConnectToDevice() {
// TODO
return false;
}
@Override
public byte[] createPumpMessageContent(RLMessageType type) {
return new byte[0];
}
@Override
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) { public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
return (E) new OmnipodPacket(payload); return (E) new OmnipodPacket(payload);
} }
@ -199,7 +196,7 @@ public class OmnipodCommunicationService /*extends RileyLinkCommunicationManager
OmnipodPacket ack = createAckPacket(podState, packetAddress, messageAddress); OmnipodPacket ack = createAckPacket(podState, packetAddress, messageAddress);
boolean quiet = false; boolean quiet = false;
while (!quiet) try { while (!quiet) try {
this.communicationManager.sendAndListen(ack, 300, 1, 0, 40, OmnipodPacket.class); sendAndListen(ack, 300, 1, 0, 40, OmnipodPacket.class);
} catch (RileyLinkCommunicationException ex) { } catch (RileyLinkCommunicationException ex) {
if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) { if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
quiet = true; quiet = true;
@ -227,7 +224,7 @@ public class OmnipodCommunicationService /*extends RileyLinkCommunicationManager
while (System.currentTimeMillis() < timeoutTime) { while (System.currentTimeMillis() < timeoutTime) {
OmnipodPacket response = null; OmnipodPacket response = null;
try { try {
response = this.communicationManager.sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class); response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
} catch (Exception ex) { } catch (Exception ex) {
LOG.debug("Ignoring exception in exchangePackets: " + ex.getClass().getSimpleName() + ": " + ex.getMessage()); LOG.debug("Ignoring exception in exchangePackets: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
} }

View file

@ -4,7 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
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.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;

View file

@ -55,7 +55,7 @@ public class OmnipodUITask {
// break; // break;
case InitPod: case InitPod:
returnData = communicationManager.initPod(); returnData = communicationManager.pairAndPrime();
break; break;
case DeactivatePod: case DeactivatePod:
@ -63,7 +63,7 @@ public class OmnipodUITask {
break; break;
case ResetPodStatus: case ResetPodStatus:
returnData = communicationManager.resetPodStatus(); returnData = communicationManager.resetPodState();
break; break;
case SetBasalProfile: case SetBasalProfile:
@ -74,7 +74,7 @@ public class OmnipodUITask {
Double amount = getDoubleFromParameters(0); Double amount = getDoubleFromParameters(0);
if (amount != null) if (amount != null)
returnData = communicationManager.setBolus(amount); returnData = communicationManager.bolus(amount);
} }
break; break;

View file

@ -9,9 +9,14 @@ public interface OmnipodCommunicationManagerInterface {
// TODO add methods that can be used by OmniPod Eros and Omnipod Dash // TODO add methods that can be used by OmniPod Eros and Omnipod Dash
/** /**
* Initialize Pod * Pair and prime
*/ */
PodCommResponse initPod(); PodCommResponse pairAndPrime();
/**
* Insert cannula
*/
PodCommResponse insertCannula(Profile basalProfile);
/** /**
* Get Pod Status (is pod running, battery left ?, reservoir, etc) * Get Pod Status (is pod running, battery left ?, reservoir, etc)
@ -26,19 +31,19 @@ public interface OmnipodCommunicationManagerInterface {
/** /**
* Set Basal Profile * Set Basal Profile
*/ */
PodCommResponse setBasalProfile(Profile profile); PodCommResponse setBasalProfile(Profile basalProfile);
/** /**
* Reset Pod status (if we forget to disconnect Pod and want to init new pod, and want to forget current pod) * Reset Pod state (if we forget to disconnect Pod and want to init new pod, and want to forget current pod)
*/ */
PodCommResponse resetPodStatus(); PodCommResponse resetPodState();
/** /**
* Set Bolus * Set Bolus
* *
* @param amount amount of bolus in U * @param amount amount of bolus in U
*/ */
PodCommResponse setBolus(Double amount); PodCommResponse bolus(Double amount);
/** /**
* Cancel Bolus (if bolus is already stopped, return acknowledgment) * Cancel Bolus (if bolus is already stopped, return acknowledgment)
@ -48,9 +53,9 @@ public interface OmnipodCommunicationManagerInterface {
/** /**
* Set Temporary Basal * Set Temporary Basal
* *
* @param tbr TempBasalPair object containg amount and duration in minutes * @param tempBasalPair TempBasalPair object containg amount and duration in minutes
*/ */
PodCommResponse setTemporaryBasal(TempBasalPair tbr); PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair);
/** /**
* Cancel Temporary Basal (if TB is already stopped, return acknowledgment) * Cancel Temporary Basal (if TB is already stopped, return acknowledgment)

View file

@ -8,6 +8,7 @@ import java.util.List;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
public class BasalScheduleMapper { public class BasalScheduleMapper {
// TODO add tests
public static BasalSchedule mapProfileToBasalSchedule(Profile profile) { public static BasalSchedule mapProfileToBasalSchedule(Profile profile) {
Profile.ProfileValue[] basalValues = profile.getBasalValues(); Profile.ProfileValue[] basalValues = profile.getBasalValues();
List<BasalScheduleEntry> entries = new ArrayList<>(); List<BasalScheduleEntry> entries = new ArrayList<>();

View file

@ -6,6 +6,8 @@ import android.content.res.Configuration;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import com.google.gson.Gson;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,8 +23,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
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.utils.SP; import info.nightscout.androidaps.utils.SP;
@ -36,7 +42,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private static RileyLinkOmnipodService instance; private static RileyLinkOmnipodService instance;
OmnipodCommunicationManager omnipodCommunicationManager; OmnipodCommunicationManagerInterface omnipodCommunicationManager;
OmnipodPumpStatus pumpStatus = null; OmnipodPumpStatus pumpStatus = null;
private IBinder mBinder = new LocalBinder(); private IBinder mBinder = new LocalBinder();
@ -101,7 +107,22 @@ public class RileyLinkOmnipodService extends RileyLinkService {
RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE); RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager // init rileyLinkCommunicationManager
omnipodCommunicationManager = new OmnipodCommunicationManager(context, rfspy); initializeErosOmnipodManager();
// TODO Dash
}
private void initializeErosOmnipodManager() {
PodSessionState podState = null;
if (SP.contains(OmnipodConst.Prefs.PodState)) {
try {
Gson gson = OmnipodUtil.getGsonInstance();
String storedPodState = SP.getString(OmnipodConst.Prefs.PodState, null);
podState = gson.fromJson(storedPodState, PodSessionState.class);
} catch (Exception ex) {
LOG.error("Could not deserialize Pod state: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
omnipodCommunicationManager = new OmnipodManager(new OmnipodCommunicationService(rfspy), podState);
} }
@ -112,7 +133,11 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Override @Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() { public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return this.omnipodCommunicationManager; if(omnipodCommunicationManager instanceof OmnipodManager) { // Eros
return ((OmnipodManager) omnipodCommunicationManager).getCommunicationService();
}
// FIXME is this correct for Dash?
return (RileyLinkCommunicationManager)omnipodCommunicationManager;
} }

View file

@ -25,8 +25,8 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
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.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
@ -46,7 +46,7 @@ public class OmnipodUtil extends RileyLinkUtil {
private static RileyLinkOmnipodService omnipodService; private static RileyLinkOmnipodService omnipodService;
private static OmnipodPumpStatus omnipodPumpStatus; private static OmnipodPumpStatus omnipodPumpStatus;
private static OmnipodCommandType currentCommand; private static OmnipodCommandType currentCommand;
private static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); private static Gson gsonInstance = createGson();
private static PodSessionState podSessionState; private static PodSessionState podSessionState;
private static PodDeviceState podDeviceState; private static PodDeviceState podDeviceState;
private static OmnipodPumpPlugin omnipodPumpPlugin; private static OmnipodPumpPlugin omnipodPumpPlugin;
@ -99,12 +99,10 @@ public class OmnipodUtil extends RileyLinkUtil {
OmnipodUtil.lowLevelDebug = lowLevelDebug; OmnipodUtil.lowLevelDebug = lowLevelDebug;
} }
public static OmnipodCommunicationManagerInterface getOmnipodCommunicationManager() {
public static OmnipodCommunicationManager getOmnipodCommunicationManager() { return (OmnipodCommunicationManagerInterface) RileyLinkUtil.rileyLinkCommunicationManager;
return (OmnipodCommunicationManager) RileyLinkUtil.rileyLinkCommunicationManager;
} }
public static RileyLinkOmnipodService getOmnipodService() { public static RileyLinkOmnipodService getOmnipodService() {
return OmnipodUtil.omnipodService; return OmnipodUtil.omnipodService;
} }

View file

@ -1,65 +1,35 @@
package info.nightscout.androidaps.plugins.pump.omnipod_dash; package info.nightscout.androidaps.plugins.pump.omnipod_dash;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm; import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.ui.OmnipodUITask;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType;
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.service.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.service.OmnipodPumpStatus;
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.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
/** /**
* Created by andy on 23.04.18. * Created by andy on 23.04.18.

View file

@ -35,8 +35,6 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
private PodSessionState getPodSessionState() { private PodSessionState getPodSessionState() {
return null; return null;
} }
@ -63,44 +61,55 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
// This are just skeleton methods, we need to see what we can get returned and act accordingly // This are just skeleton methods, we need to see what we can get returned and act accordingly
@Override
public PodCommResponse initPod() { public PodCommResponse pairAndPrime() {
//omnipodManager.pairAndPrime(); //omnipodManager.pairAndPrime();
return null; return null;
} }
@Override
public PodCommResponse insertCannula(Profile basalProfile) {
return null;
}
@Override
public PodCommResponse getPodStatus() { public PodCommResponse getPodStatus() {
return null; return null;
} }
@Override
public PodCommResponse deactivatePod() { public PodCommResponse deactivatePod() {
return null; return null;
} }
public PodCommResponse setBasalProfile(Profile profile) { @Override
public PodCommResponse setBasalProfile(Profile basalProfile) {
return null; return null;
} }
public PodCommResponse resetPodStatus() { @Override
public PodCommResponse resetPodState() {
return null; return null;
} }
public PodCommResponse setBolus(Double parameter) { @Override
public PodCommResponse bolus(Double parameter) {
return null; return null;
} }
@Override
public PodCommResponse cancelBolus() { public PodCommResponse cancelBolus() {
return null; return null;
} }
public PodCommResponse setTemporaryBasal(TempBasalPair tbr) { @Override
public PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair) {
return null; return null;
} }
@Override
public PodCommResponse cancelTemporaryBasal() { public PodCommResponse cancelTemporaryBasal() {
return null; return null;
} }
@ -109,5 +118,4 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
public PodCommResponse acknowledgeAlerts() { public PodCommResponse acknowledgeAlerts() {
return null; return null;
} }
} }

View file

@ -7,7 +7,7 @@
android:enabled="true" android:enabled="true"
android:summary="" android:summary=""
android:title="RileyLink Configuration" android:title="RileyLink Configuration"
android:key="@string/pref_key_rileylink_mac_address"> android:key="@string/key_rileylink_mac_address">
<intent android:action="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" /> <intent android:action="info.nightscout.androidaps.plugins.PumpCommon.dialog.RileyLinkBLEScanActivity" />
</info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference> </info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference>