Restore RL history for Omnipod

This commit is contained in:
Bart Sopers 2020-08-17 22:00:56 +02:00
parent 18a515e5f7
commit 7b9cbe7497
5 changed files with 23 additions and 114 deletions

View file

@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import org.joda.time.LocalDateTime;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -18,24 +16,13 @@ public class RLHistoryItemMedtronic extends RLHistoryItem {
this.medtronicCommandType = medtronicCommandType;
}
@Override
public String getDescription(ResourceHelper resourceHelper) {
switch (this.source) {
case RileyLink:
return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return resourceHelper.gs(pumpDeviceState.getResourceId());
case MedtronicCommand:
if (RLHistoryItemSource.MedtronicCommand.equals(source)) {
return medtronicCommandType.name();
default:
return "Unknown Description";
}
}
return super.getDescription(resourceHelper);
}
}

View file

@ -16,22 +16,12 @@ public class RLHistoryItemOmnipod extends RLHistoryItem {
this.omnipodCommandType = omnipodCommandType;
}
@Override
public String getDescription(ResourceHelper resourceHelper) {
switch (this.source) {
case RileyLink:
return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return resourceHelper.gs(pumpDeviceState.getResourceId());
case OmnipodCommand:
if (RLHistoryItemSource.OmnipodCommand.equals(source)) {
return omnipodCommandType.name();
default:
return "Unknown Description";
}
return super.getDescription(resourceHelper);
}
}

View file

@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
@ -13,19 +15,22 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;
private final IOmnipodManager omnipodCommunicationManager;
private final OmnipodUIPostprocessor omnipodUIPostprocessor;
private final IOmnipodManager omnipodCommunicationManager;
private RileyLinkUtil rileyLinkUtil;
public OmnipodUIComm(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
OmnipodUIPostprocessor omnipodUIPostprocessor,
IOmnipodManager omnipodCommunicationManager
IOmnipodManager omnipodCommunicationManager,
RileyLinkUtil rileyLinkUtil
) {
this.injector = injector;
this.aapsLogger = aapsLogger;
this.omnipodUIPostprocessor = omnipodUIPostprocessor;
this.omnipodCommunicationManager = omnipodCommunicationManager;
this.rileyLinkUtil = rileyLinkUtil;
}
@ -35,34 +40,10 @@ public class OmnipodUIComm {
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
// new Thread(() -> {
// LOG.warn("@@@ Start Thread");
//
// task.execute(getCommunicationManager());
//
// LOG.warn("@@@ End Thread");
// });
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
task.execute(this.omnipodCommunicationManager);
// for (int i = 0; i < getMaxWaitTime(commandType); i++) {
// synchronized (task) {
// // try {
// //
// // //task.wait(1000);
// // } catch (InterruptedException e) {
// // LOG.error("executeCommand InterruptedException", e);
// // }
//
//
// SystemClock.sleep(1000);
// }
//
// if (task.isReceived()) {
// break;
// }
// }
if (!task.isReceived()) {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
}

View file

@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
@ -43,6 +44,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodUtil omnipodUtil;
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager;
@Inject DatabaseHelperInterface databaseHelper;
private static RileyLinkOmnipodService instance;
@ -70,22 +72,20 @@ public class RileyLinkOmnipodService extends RileyLinkService {
super.onConfigurationChanged(newConfig);
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public RileyLinkEncodingType getEncoding() {
return RileyLinkEncodingType.Manchester;
}
/**
* If you have customized RileyLinkServiceData you need to override this
*/
@Override
public void initRileyLinkServiceData() {
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod;
@ -111,7 +111,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodCommunicationManager = omnipodCommunicationService;
aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this);
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this, databaseHelper);
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager);
@ -121,7 +121,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rxBus.send(new EventOmnipodPumpValuesChanged());
}
public OmnipodUIComm getDeviceCommandExecutor() {
return this.omnipodUIComm;
}
@ -130,7 +129,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rfspy.resetRileyLinkConfiguration();
}
@Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return omnipodCommunicationManager;
@ -141,15 +139,12 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
}
public class LocalBinder extends Binder {
public RileyLinkOmnipodService getServiceInstance() {
return RileyLinkOmnipodService.this;
}
}
/* private functions */
// PumpInterface - REMOVE
@ -158,7 +153,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return rileyLinkServiceData.rileyLinkServiceState.isReady();
}
@Override
public boolean verifyConfiguration() {
try {
omnipodPumpStatus.rileyLinkErrorDescription = null;
@ -202,11 +197,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
}
private boolean reconfigureService() {
if (!inPreInit) {
if (rileyLinkAddressChanged) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false;

View file

@ -2,17 +2,11 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data;
import org.joda.time.LocalDateTime;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
//import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
//import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
//import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
/**
@ -21,7 +15,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class RLHistoryItem {
//private MedtronicCommandType medtronicCommandType;
protected LocalDateTime dateTime;
protected RLHistoryItemSource source;
protected RileyLinkServiceState serviceState;
@ -29,7 +22,6 @@ public class RLHistoryItem {
protected RileyLinkTargetDevice targetDevice;
protected PumpDeviceState pumpDeviceState;
//private OmnipodCommandType omnipodCommandType;
public RLHistoryItem(LocalDateTime dateTime, RLHistoryItemSource source, RileyLinkTargetDevice targetDevice) {
this.dateTime = dateTime;
@ -46,7 +38,6 @@ public class RLHistoryItem {
this.source = RLHistoryItemSource.RileyLink;
}
public RLHistoryItem(PumpDeviceState pumpDeviceState, RileyLinkTargetDevice targetDevice) {
this.pumpDeviceState = pumpDeviceState;
this.dateTime = new LocalDateTime();
@ -54,64 +45,34 @@ public class RLHistoryItem {
this.source = RLHistoryItemSource.MedtronicPump;
}
// public RLHistoryItem(MedtronicCommandType medtronicCommandType) {
// this.dateTime = new LocalDateTime();
// this.medtronicCommandType = medtronicCommandType;
// source = RLHistoryItemSource.MedtronicCommand;
// }
//
//
// public RLHistoryItem(OmnipodCommandType omnipodCommandType) {
// this.dateTime = new LocalDateTime();
// this.omnipodCommandType = omnipodCommandType;
// source = RLHistoryItemSource.OmnipodCommand;
// }
public LocalDateTime getDateTime() {
return dateTime;
}
public RileyLinkServiceState getServiceState() {
return serviceState;
}
public RileyLinkError getErrorCode() {
return errorCode;
}
public String getDescription(ResourceHelper resourceHelper) {
// TODO extend when we have Omnipod
switch (this.source) {
case RileyLink:
return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return resourceHelper.gs(pumpDeviceState.getResourceId());
// case MedtronicCommand:
// return medtronicCommandType.name();
//
// case OmnipodCommand:
// return omnipodCommandType.name();
default:
return "Unknown Description";
}
}
public RLHistoryItemSource getSource() {
return source;
}
public PumpDeviceState getPumpDeviceState() {
return pumpDeviceState;
}
@ -129,14 +90,12 @@ public class RLHistoryItem {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}
public static class Comparator implements java.util.Comparator<RLHistoryItem> {
@Override
public int compare(RLHistoryItem o1, RLHistoryItem o2) {
return o2.dateTime.compareTo(o1.getDateTime());