Remove OmnipodCommunicationManager, make OmnipodManager implement OmnipodCommunicationManagerInterface
This commit is contained in:
parent
75ae6844f3
commit
78f402a367
|
@ -11,6 +11,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.action.AcknowledgeAlertsAction;
|
||||
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.PrimeService;
|
||||
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.podinfo.PodInfo;
|
||||
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.OmnipodCommunicationManagerInterface;
|
||||
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.schedule.BasalSchedule;
|
||||
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.util.OmnipodConst;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
public class OmnipodManager {
|
||||
public class OmnipodManager implements OmnipodCommunicationManagerInterface {
|
||||
private final OmnipodCommunicationService communicationService;
|
||||
private PodSessionState podState;
|
||||
private static OmnipodManager instance;
|
||||
|
||||
// FIXME this is dirty
|
||||
public static OmnipodManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public OmnipodManager(OmnipodCommunicationService communicationService, PodSessionState podState) {
|
||||
if (communicationService == null) {
|
||||
|
@ -49,55 +57,15 @@ public class OmnipodManager {
|
|||
}
|
||||
this.communicationService = communicationService;
|
||||
this.podState = podState;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public OmnipodManager(OmnipodCommunicationService communicationService) {
|
||||
this(communicationService, null);
|
||||
}
|
||||
|
||||
public OmnipodCommunicationService getCommunicationService() {
|
||||
return communicationService;
|
||||
}
|
||||
|
||||
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) {
|
||||
@Override
|
||||
public PodCommResponse insertCannula(Profile profile) {
|
||||
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
|
||||
throw new IllegalArgumentException("Pod should be paired and primed first");
|
||||
} else if (podState.getSetupProgress().isAfter(SetupProgress.CANNULA_INSERTING)) {
|
||||
|
@ -111,45 +79,131 @@ public class OmnipodManager {
|
|||
StatusResponse delayedStatusResponse = communicationService.executeAction(new GetStatusAction(podState));
|
||||
InsertCannulaAction.updateCannulaInsertionStatus(podState, delayedStatusResponse);
|
||||
}, OmnipodConst.POD_CANNULA_INSERTION_DURATION);
|
||||
|
||||
return null; // TODO
|
||||
}
|
||||
|
||||
public void setBasalSchedule(BasalSchedule basalSchedule, boolean confidenceReminder) {
|
||||
if (!isInitialized()) {
|
||||
throw new IllegalStateException("Pod should be initialized first");
|
||||
@Override
|
||||
public PodCommResponse pairAndPrime() {
|
||||
if (podState == null) {
|
||||
podState = communicationService.executeAction(new PairAction(new PairService()));
|
||||
}
|
||||
communicationService.executeAction(new SetBasalScheduleAction(podState, basalSchedule,
|
||||
confidenceReminder, podState.getScheduleOffset(), true));
|
||||
}
|
||||
if (podState.getSetupProgress().isBefore(SetupProgress.PRIMING_FINISHED)) {
|
||||
communicationService.executeAction(new PrimeAction(new PrimeService(), podState));
|
||||
|
||||
public void setTempBasal(double rate, Duration duration) {
|
||||
if (!isInitialized()) {
|
||||
throw new IllegalStateException("Pod should be initialized first");
|
||||
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());
|
||||
}
|
||||
communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
|
||||
podState, rate, duration, true, true));
|
||||
|
||||
return null; // TODO
|
||||
}
|
||||
|
||||
public void cancelTempBasal() {
|
||||
if (!isInitialized()) {
|
||||
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() {
|
||||
@Override
|
||||
public PodCommResponse cancelBolus() {
|
||||
if (!isInitialized()) {
|
||||
throw new IllegalStateException("Pod should be initialized first");
|
||||
}
|
||||
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() {
|
||||
if (!isInitialized()) {
|
||||
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));
|
||||
}
|
||||
|
||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||
public void resumeDelivery() {
|
||||
if (!isInitialized()) {
|
||||
throw new IllegalStateException("Pod should be initialized first");
|
||||
|
@ -165,6 +220,7 @@ public class OmnipodManager {
|
|||
true, podState.getScheduleOffset(), true));
|
||||
}
|
||||
|
||||
// TODO should we add this to the OmnipodCommunicationManager interface?
|
||||
public void setTime() {
|
||||
if (!isInitialized()) {
|
||||
throw new IllegalStateException("Pod should be initialized first");
|
||||
|
@ -181,16 +237,12 @@ public class OmnipodManager {
|
|||
true, podState.getScheduleOffset(), true));
|
||||
}
|
||||
|
||||
public DateTime getTime() {
|
||||
return podState.getTime();
|
||||
public OmnipodCommunicationService getCommunicationService() {
|
||||
return communicationService;
|
||||
}
|
||||
|
||||
public void deactivatePod() {
|
||||
if (podState == null) {
|
||||
throw new IllegalStateException("Pod should be paired first");
|
||||
}
|
||||
communicationService.executeAction(new DeactivatePodAction(podState, true));
|
||||
resetPodState();
|
||||
public DateTime getTime() {
|
||||
return podState.getTime();
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
|
@ -201,11 +253,6 @@ public class OmnipodManager {
|
|||
return podState == null ? "null" : podState.toString();
|
||||
}
|
||||
|
||||
public void resetPodState() {
|
||||
podState = null;
|
||||
SP.remove(OmnipodConst.Prefs.PodState);
|
||||
}
|
||||
|
||||
private void executeDelayed(Runnable r, Duration timeout) {
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||
scheduledExecutorService.schedule(r, timeout.getMillis(), TimeUnit.MILLISECONDS);
|
||||
|
|
|
@ -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.service.tasks.ResetRileyLinkConfigurationTask;
|
||||
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.OmnipodUITask;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
||||
|
@ -105,7 +104,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements PumpInterfa
|
|||
displayConnectionMessages = false;
|
||||
|
||||
if (omnipodCommunicationManager == null) {
|
||||
omnipodCommunicationManager = OmnipodCommunicationManager.getInstance();
|
||||
omnipodCommunicationManager = OmnipodManager.getInstance();
|
||||
}
|
||||
|
||||
omnipodUIComm = new OmnipodUIComm(omnipodCommunicationManager);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,33 +35,30 @@ import info.nightscout.androidaps.plugins.pump.omnipod.exception.PodReturnedErro
|
|||
* 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);
|
||||
//RFSpy rfspy = null;
|
||||
OmnipodCommunicationManager communicationManager;
|
||||
|
||||
public OmnipodCommunicationService(OmnipodCommunicationManager communicationManager) {
|
||||
//this.rfspy = rfspy;
|
||||
this.communicationManager = communicationManager;
|
||||
public OmnipodCommunicationService(RFSpy rfspy) {
|
||||
super(rfspy);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void configurePumpSpecificSettings() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean tryToConnectToDevice() {
|
||||
// // TODO
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public byte[] createPumpMessageContent(RLMessageType type) {
|
||||
// return new byte[0];
|
||||
// }
|
||||
@Override
|
||||
protected void configurePumpSpecificSettings() {
|
||||
}
|
||||
|
||||
//@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) {
|
||||
return (E) new OmnipodPacket(payload);
|
||||
}
|
||||
|
@ -199,7 +196,7 @@ public class OmnipodCommunicationService /*extends RileyLinkCommunicationManager
|
|||
OmnipodPacket ack = createAckPacket(podState, packetAddress, messageAddress);
|
||||
boolean quiet = false;
|
||||
while (!quiet) try {
|
||||
this.communicationManager.sendAndListen(ack, 300, 1, 0, 40, OmnipodPacket.class);
|
||||
sendAndListen(ack, 300, 1, 0, 40, OmnipodPacket.class);
|
||||
} catch (RileyLinkCommunicationException ex) {
|
||||
if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
|
||||
quiet = true;
|
||||
|
@ -227,7 +224,7 @@ public class OmnipodCommunicationService /*extends RileyLinkCommunicationManager
|
|||
while (System.currentTimeMillis() < timeoutTime) {
|
||||
OmnipodPacket response = null;
|
||||
try {
|
||||
response = this.communicationManager.sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
|
||||
response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
|
||||
} catch (Exception ex) {
|
||||
LOG.debug("Ignoring exception in exchangePackets: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.OmnipodCommandType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
||||
|
|
|
@ -55,7 +55,7 @@ public class OmnipodUITask {
|
|||
// break;
|
||||
|
||||
case InitPod:
|
||||
returnData = communicationManager.initPod();
|
||||
returnData = communicationManager.pairAndPrime();
|
||||
break;
|
||||
|
||||
case DeactivatePod:
|
||||
|
@ -63,7 +63,7 @@ public class OmnipodUITask {
|
|||
break;
|
||||
|
||||
case ResetPodStatus:
|
||||
returnData = communicationManager.resetPodStatus();
|
||||
returnData = communicationManager.resetPodState();
|
||||
break;
|
||||
|
||||
case SetBasalProfile:
|
||||
|
@ -74,7 +74,7 @@ public class OmnipodUITask {
|
|||
Double amount = getDoubleFromParameters(0);
|
||||
|
||||
if (amount != null)
|
||||
returnData = communicationManager.setBolus(amount);
|
||||
returnData = communicationManager.bolus(amount);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -9,9 +9,14 @@ public interface OmnipodCommunicationManagerInterface {
|
|||
// 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)
|
||||
|
@ -26,19 +31,19 @@ public interface OmnipodCommunicationManagerInterface {
|
|||
/**
|
||||
* 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
|
||||
*
|
||||
* @param amount amount of bolus in U
|
||||
*/
|
||||
PodCommResponse setBolus(Double amount);
|
||||
PodCommResponse bolus(Double amount);
|
||||
|
||||
/**
|
||||
* Cancel Bolus (if bolus is already stopped, return acknowledgment)
|
||||
|
@ -48,9 +53,9 @@ public interface OmnipodCommunicationManagerInterface {
|
|||
/**
|
||||
* 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)
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
|
||||
public class BasalScheduleMapper {
|
||||
// TODO add tests
|
||||
public static BasalSchedule mapProfileToBasalSchedule(Profile profile) {
|
||||
Profile.ProfileValue[] basalValues = profile.getBasalValues();
|
||||
List<BasalScheduleEntry> entries = new ArrayList<>();
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.content.res.Configuration;
|
|||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
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.service.RileyLinkService;
|
||||
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.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.utils.SP;
|
||||
|
||||
|
@ -36,7 +42,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
|
||||
private static RileyLinkOmnipodService instance;
|
||||
|
||||
OmnipodCommunicationManager omnipodCommunicationManager;
|
||||
OmnipodCommunicationManagerInterface omnipodCommunicationManager;
|
||||
OmnipodPumpStatus pumpStatus = null;
|
||||
private IBinder mBinder = new LocalBinder();
|
||||
|
||||
|
@ -101,7 +107,22 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
|
||||
|
||||
// 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
|
||||
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
|
||||
return this.omnipodCommunicationManager;
|
||||
if(omnipodCommunicationManager instanceof OmnipodManager) { // Eros
|
||||
return ((OmnipodManager) omnipodCommunicationManager).getCommunicationService();
|
||||
}
|
||||
// FIXME is this correct for Dash?
|
||||
return (RileyLinkCommunicationManager)omnipodCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.data.RLHistoryItem;
|
||||
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.OmnipodCommunicationManagerInterface;
|
||||
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.events.EventOmnipodDeviceStatusChange;
|
||||
|
@ -46,7 +46,7 @@ public class OmnipodUtil extends RileyLinkUtil {
|
|||
private static RileyLinkOmnipodService omnipodService;
|
||||
private static OmnipodPumpStatus omnipodPumpStatus;
|
||||
private static OmnipodCommandType currentCommand;
|
||||
private static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
private static Gson gsonInstance = createGson();
|
||||
private static PodSessionState podSessionState;
|
||||
private static PodDeviceState podDeviceState;
|
||||
private static OmnipodPumpPlugin omnipodPumpPlugin;
|
||||
|
@ -99,12 +99,10 @@ public class OmnipodUtil extends RileyLinkUtil {
|
|||
OmnipodUtil.lowLevelDebug = lowLevelDebug;
|
||||
}
|
||||
|
||||
|
||||
public static OmnipodCommunicationManager getOmnipodCommunicationManager() {
|
||||
return (OmnipodCommunicationManager) RileyLinkUtil.rileyLinkCommunicationManager;
|
||||
public static OmnipodCommunicationManagerInterface getOmnipodCommunicationManager() {
|
||||
return (OmnipodCommunicationManagerInterface) RileyLinkUtil.rileyLinkCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkOmnipodService getOmnipodService() {
|
||||
return OmnipodUtil.omnipodService;
|
||||
}
|
||||
|
|
|
@ -1,65 +1,35 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod_dash;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ServiceConnection;
|
||||
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.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
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.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.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.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.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.EventOmnipodRefreshButtonState;
|
||||
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.util.OmnipodConst;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
||||
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.
|
||||
|
|
|
@ -35,8 +35,6 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
|
|||
|
||||
|
||||
private PodSessionState getPodSessionState() {
|
||||
|
||||
|
||||
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
|
||||
|
||||
public PodCommResponse initPod() {
|
||||
@Override
|
||||
public PodCommResponse pairAndPrime() {
|
||||
//omnipodManager.pairAndPrime();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodCommResponse insertCannula(Profile basalProfile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodCommResponse getPodStatus() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PodCommResponse deactivatePod() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PodCommResponse setBasalProfile(Profile profile) {
|
||||
@Override
|
||||
public PodCommResponse setBasalProfile(Profile basalProfile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PodCommResponse resetPodStatus() {
|
||||
@Override
|
||||
public PodCommResponse resetPodState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PodCommResponse setBolus(Double parameter) {
|
||||
@Override
|
||||
public PodCommResponse bolus(Double parameter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodCommResponse cancelBolus() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PodCommResponse setTemporaryBasal(TempBasalPair tbr) {
|
||||
@Override
|
||||
public PodCommResponse setTemporaryBasal(TempBasalPair tempBasalPair) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodCommResponse cancelTemporaryBasal() {
|
||||
return null;
|
||||
}
|
||||
|
@ -109,5 +118,4 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
|
|||
public PodCommResponse acknowledgeAlerts() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
android:enabled="true"
|
||||
android:summary=""
|
||||
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" />
|
||||
</info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference>
|
||||
|
||||
|
|
Loading…
Reference in a new issue