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 org.joda.time.LocalDateTime;
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.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.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -18,24 +16,13 @@ public class RLHistoryItemMedtronic extends RLHistoryItem {
this.medtronicCommandType = medtronicCommandType; this.medtronicCommandType = medtronicCommandType;
} }
@Override
public String getDescription(ResourceHelper resourceHelper) { public String getDescription(ResourceHelper resourceHelper) {
if (RLHistoryItemSource.MedtronicCommand.equals(source)) {
switch (this.source) { return medtronicCommandType.name();
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();
default:
return "Unknown Description";
} }
return super.getDescription(resourceHelper);
} }
} }

View file

@ -16,22 +16,12 @@ public class RLHistoryItemOmnipod extends RLHistoryItem {
this.omnipodCommandType = omnipodCommandType; this.omnipodCommandType = omnipodCommandType;
} }
@Override
public String getDescription(ResourceHelper resourceHelper) { public String getDescription(ResourceHelper resourceHelper) {
if (RLHistoryItemSource.OmnipodCommand.equals(source)) {
switch (this.source) { return omnipodCommandType.name();
case RileyLink:
return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return resourceHelper.gs(pumpDeviceState.getResourceId());
case OmnipodCommand:
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 dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; 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.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
@ -13,19 +15,22 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final IOmnipodManager omnipodCommunicationManager;
private final OmnipodUIPostprocessor omnipodUIPostprocessor; private final OmnipodUIPostprocessor omnipodUIPostprocessor;
private final IOmnipodManager omnipodCommunicationManager;
private RileyLinkUtil rileyLinkUtil;
public OmnipodUIComm( public OmnipodUIComm(
HasAndroidInjector injector, HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
OmnipodUIPostprocessor omnipodUIPostprocessor, OmnipodUIPostprocessor omnipodUIPostprocessor,
IOmnipodManager omnipodCommunicationManager IOmnipodManager omnipodCommunicationManager,
RileyLinkUtil rileyLinkUtil
) { ) {
this.injector = injector; this.injector = injector;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.omnipodUIPostprocessor = omnipodUIPostprocessor; this.omnipodUIPostprocessor = omnipodUIPostprocessor;
this.omnipodCommunicationManager = omnipodCommunicationManager; this.omnipodCommunicationManager = omnipodCommunicationManager;
this.rileyLinkUtil = rileyLinkUtil;
} }
@ -35,34 +40,10 @@ public class OmnipodUIComm {
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters); OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
// new Thread(() -> { rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
// LOG.warn("@@@ Start Thread");
//
// task.execute(getCommunicationManager());
//
// LOG.warn("@@@ End Thread");
// });
task.execute(this.omnipodCommunicationManager); 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()) { if (!task.isReceived()) {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType); 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 javax.inject.Inject;
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
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;
@ -43,6 +44,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodUtil omnipodUtil; @Inject OmnipodUtil omnipodUtil;
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor; @Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager; @Inject PodStateManager podStateManager;
@Inject DatabaseHelperInterface databaseHelper;
private static RileyLinkOmnipodService instance; private static RileyLinkOmnipodService instance;
@ -70,22 +72,20 @@ public class RileyLinkOmnipodService extends RileyLinkService {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
} }
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return mBinder; return mBinder;
} }
@Override @Override
public RileyLinkEncodingType getEncoding() { public RileyLinkEncodingType getEncoding() {
return RileyLinkEncodingType.Manchester; return RileyLinkEncodingType.Manchester;
} }
/** /**
* If you have customized RileyLinkServiceData you need to override this * If you have customized RileyLinkServiceData you need to override this
*/ */
@Override
public void initRileyLinkServiceData() { public void initRileyLinkServiceData() {
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod; rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod;
@ -111,7 +111,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodCommunicationManager = omnipodCommunicationService; this.omnipodCommunicationManager = omnipodCommunicationService;
aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus, 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); omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager);
@ -121,7 +121,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rxBus.send(new EventOmnipodPumpValuesChanged()); rxBus.send(new EventOmnipodPumpValuesChanged());
} }
public OmnipodUIComm getDeviceCommandExecutor() { public OmnipodUIComm getDeviceCommandExecutor() {
return this.omnipodUIComm; return this.omnipodUIComm;
} }
@ -130,7 +129,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rfspy.resetRileyLinkConfiguration(); rfspy.resetRileyLinkConfiguration();
} }
@Override @Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() { public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return omnipodCommunicationManager; return omnipodCommunicationManager;
@ -141,15 +139,12 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState); this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
} }
public class LocalBinder extends Binder { public class LocalBinder extends Binder {
public RileyLinkOmnipodService getServiceInstance() { public RileyLinkOmnipodService getServiceInstance() {
return RileyLinkOmnipodService.this; return RileyLinkOmnipodService.this;
} }
} }
/* private functions */ /* private functions */
// PumpInterface - REMOVE // PumpInterface - REMOVE
@ -158,7 +153,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return rileyLinkServiceData.rileyLinkServiceState.isReady(); return rileyLinkServiceData.rileyLinkServiceState.isReady();
} }
@Override
public boolean verifyConfiguration() { public boolean verifyConfiguration() {
try { try {
omnipodPumpStatus.rileyLinkErrorDescription = null; omnipodPumpStatus.rileyLinkErrorDescription = null;
@ -202,11 +197,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
} }
private boolean reconfigureService() { private boolean reconfigureService() {
if (!inPreInit) { if (!inPreInit) {
if (rileyLinkAddressChanged) { if (rileyLinkAddressChanged) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false; rileyLinkAddressChanged = false;

View file

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